combindma / laravel-linkedin-insight-tag
Laravel 的 LinkedIn Insight Tag 集成
1.0.0
2022-03-08 19:05 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
LinkedIn 转化跟踪的完整 Laravel 包
安装
您可以通过 composer 安装此包
composer require combindma/laravel-linkedin-insight-tag
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="linkedin-insight-tag-config"
这是发布配置文件的内容
return [ /* * LinkedIn Partner Id id provided by LinkedIn */ 'linkedin_partner_id' => env('LINKEDIN_PARTNER_ID', ''), /* * The key under which data is saved to the session with flash. */ 'sessionKey' => env('LINKEDIN_SESSION_KEY', config('app.name').'_linkedinInsightTag'), /* * Enable or disable script rendering. Useful for local development. */ 'enabled' => env('LINKEDIN_INSIGHT_TAG_ENABLED', false), ];
如果您计划使用 flash-functionality,必须在 StartSession 中间件之后安装 LinkedinInsightTagMiddleware
// app/Http/Kernel.php protected $middleware = [ ... \Illuminate\Session\Middleware\StartSession::class, \Combindma\LinkedinInsightTag\LinkedinInsightTagMiddleware::class, ... ];
用法
在 Blade 中包含脚本
在打开 head 标签后插入 head 视图,在打开 body 标签后插入 body 视图
<!DOCTYPE html> <html> <head> @include('linkedinInsightTag::head') </head> <body> @include('linkedinInsightTag::body') </body>
您的转化事件也将在此处渲染。要添加事件,请使用 conversion()
函数。
// HomeController.php use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag; public function index() { LinkedinInsightTag::conversion('7652529'); //your conversion_id provided by Linkedin return view('home'); }
这会渲染
<html> <head> <script>/* Linkedin Insight Tag's base script */</script> <!-- ... --> </head> <body> <script>window.lintrk('track', { conversion_id: 7652529 });</script> <!-- ... --> </html>
为下一次请求闪存数据
此包还可以设置事件以在下次请求中渲染。这对于在内部重定向后设置数据很有用。
// ContactController.php use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag; public function postContact() { // Do contact form stuff... LinkedinInsightTag::flashConversion('7652529'); return redirect()->action('ContactController@getContact'); }
在表单提交后,以下事件将在联系页面解析
<html> <head> <script>/* Linkedin Insight Tag's base script */</script> <!-- ... --> </head> <body> <script>window.lintrk('track', { conversion_id: 7652529 });</script> <!-- ... --> </html>
其他简单方法
use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag; // Retrieve your Partner id $id = LinkedinInsightTag::partnerId(); // XXXXXXXX // Check whether script rendering is enabled $enabled = LinkedinInsightTag::isEnabled(); // true|false // Enable and disable script rendering on the fly LinkedinInsightTag::enable(); LinkedinInsightTag::disable(); // Add conversion event to the conversion layer (automatically renders right before the tag script). Setting new values merges them with the previous ones. LinkedinInsightTag::conversion(123456); //only int values // Flash event for the next request. Setting new values merges them with the previous ones. LinkedinInsightTag::flashConversion(123456); //Clear the conversion layer. LinkedinInsightTag::clear();
宏化
将转化事件添加到页面可能是一个重复的过程。由于此包不倾向于您的事件外观,因此 LinkedinInsightTag 是宏化的。
use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag; //include this in your macrobale file LinkedinInsightTag::macro('purchase', function () { LinkedinInsightTag::conversion(123456); LinkedinInsightTag::conversion(654321); }); //in your controller LinkedinInsightTag::purchase();
测试
composer test
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全漏洞
请查看 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。