An easy Facebook Pixel implementation for your Laravel application.
The Facebook pixel is a snippet of JavaScript code that allows you to track visitor activity on your website. It works by loading a small library of functions which you can use whenever a site visitor takes an action (called an event) that you want to track (called a conversion). Tracked conversions appear in the Facebook Ads Manager and in the Facebook Analytics dashboard, where they can be used to measure the effectiveness of your ads, to define custom audiences for ad targeting, for dynamic ads campaigns, and to analyze that effectiveness of your website's conversion funnels.
For concrete examples of what you want to send throught the Standard Events
You can install the package via Composer:
composer require weblagence/laravel-facebook-pixel
In Laravel 5.5 and up, the package will automatically register the service provider and facade
In L5.4 or below start by registering the package's the service provider and facade:
// config/app.php
'providers' => [
...
WebLAgence\LaravelFacebookPixel\LaravelFacebookPixelServiceProvider::class,
],
'aliases' => [
...
'LaravelFacebookPixel' => WebLAgence\LaravelFacebookPixel\LaravelFacebookPixelFacade::class,
],
Next, publish the config file:
php artisan vendor:publish --provider="WebLAgence\LaravelFacebookPixel\LaravelFacebookPixelServiceProvider"
The configuration file is fairly simple.
return [
/*
* The Facebook Pixel id, should be a code that looks something like "XXXXXXXXXXXXXXXX".
*/
'facebook_pixel_id' => '',
/*
* Use this variable instead of `facebook_pixel_id` if you need to use multiple facebook pixels
*/
'facebook_pixel_ids' => [],
/*
* Enable or disable script rendering. Useful for local development.
*/
'enabled' => true,
];
First you'll need to include Facebook Pixel's script. Facebook's docs recommend doing this right after the body tag.
{{-- layout.blade.php --}}
<html>
<head>
@include('facebook-pixel::head')
{{-- ... --}}
</head>
<body>
@include('facebook-pixel::body')
{{-- ... --}}
</body>
</html>
At any moment, you can use the next function to create a Standard Event
\LaravelFacebookPixel::createEvent($eventName, $parameters = []);
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email jeremy@weblagence.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.