A complete Laravel package for LinkedIn Conversion Tracking
You can install the package via composer:
composer require combindma/laravel-linkedin-insight-tag
You can publish the config file with:
php artisan vendor:publish --tag="linkedin-insight-tag-config"
This is the contents of the published config file:
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),
];
If you plan on using the flash-functionality you must install the LinkedinInsightTagMiddleware, after the StartSession middleware:
// app/Http/Kernel.php
protected $middleware = [
...
\Illuminate\Session\Middleware\StartSession::class,
\Combindma\LinkedinInsightTag\LinkedinInsightTagMiddleware::class,
...
];
Insert head view after opening head tag, and body view after opening body tag
<!DOCTYPE html>
<html>
<head>
@include('linkedinInsightTag::head')
</head>
<body>
@include('linkedinInsightTag::body')
</body>
Your conversion events will also be rendered here. To add an event, use the conversion()
function.
// HomeController.php
use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag;
public function index()
{
LinkedinInsightTag::conversion('7652529'); //your conversion_id provided by Linkedin
return view('home');
}
This renders:
<html>
<head>
<script>/* Linkedin Insight Tag's base script */</script>
<!-- ... -->
</head>
<body>
<script>window.lintrk('track', { conversion_id: 7652529 });</script>
<!-- ... -->
</html>
The package can also set event to render on the next request. This is useful for setting data after an internal redirect.
// ContactController.php
use Combindma\LinkedinInsightTag\Facades\LinkedinInsightTag;
public function postContact()
{
// Do contact form stuff...
LinkedinInsightTag::flashConversion('7652529');
return redirect()->action('ContactController@getContact');
}
After a form submit, the following event will be parsed on the contact page:
<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();
Adding conversion events to pages can become a repetitive process. Since this package isn't supposed to be opinionated on what your events should look like, the LinkedinInsightTag is macroable.
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
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.