New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jeffersongoncalves/laravel-pixel

This Laravel package offers a straightforward way to integrate Meta (Facebook) Pixel into your application. By configuring your Pixel ID, you can effortlessly track user interactions, page views, conversions, and other valuable events on your website. This helps you gather insights into your audience behavior and optimize your advertising campaigns. The package simplifies the process of adding the Pixel script to your Blade templates, enabling seamless analytics collection with minimal setup.
2,516 4
Install
composer require jeffersongoncalves/laravel-pixel
Latest Version:3.1.0
PHP:^8.2|^8.3|^8.4
Laravel:12 · 13
Older releases:11
License:MIT
Last Updated:Oct 16, 2026
Links: GitHub  ·  Packagist
Maintainer: jeffersongoncalves

Laravel Pixel

Laravel Pixel

Buy Me A Coffee

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

This Laravel package offers a straightforward way to integrate Meta (Facebook) Pixel into your application. The Pixel ID is stored in the database using spatie/laravel-settings, allowing you to manage it dynamically (e.g., via an admin panel) without relying on .env files or static config.

Compatibility

Package PHP Laravel
1.x 8.2 / 8.3 / 8.4 11.x / 12.x / 13.x

Installation

Install the package via composer:

composer require jeffersongoncalves/laravel-pixel

Publish and run the spatie/laravel-settings migrations (if not already done):

php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
php artisan migrate

Publish and run the pixel settings migration:

php artisan vendor:publish --tag="pixel-settings-migrations"
php artisan migrate

Usage

Setting the Pixel ID

You can set the Pixel ID programmatically using any of these methods:

Helper function:

$settings = pixel_settings();
$settings->pixel_id = '123456789';
$settings->save();

Facade:

use JeffersonGoncalves\Pixel\Facades\PixelSettings;

$settings = PixelSettings::getFacadeRoot();
$settings->pixel_id = '123456789';
$settings->save();

Container resolution:

use JeffersonGoncalves\Pixel\Settings\PixelSettings;

$settings = app(PixelSettings::class);
$settings->pixel_id = '123456789';
$settings->save();

Adding the Pixel script to your layout

Include the Blade component in your layout's <head> tag:

@include('pixel::script')

The script will only render when a valid Pixel ID is configured. If the Pixel ID is null or empty, nothing will be rendered.

Reading the Pixel ID

$pixelId = pixel_settings()->pixel_id; // returns string|null

Content Security Policy

When your app sets a CSP nonce through Laravel's Vite (Vite::useCspNonce(), as laravel-security-headers does), every <script> this package renders carries it, so a script-src 'self' 'nonce-{nonce}' policy works without 'unsafe-inline'. Scripts loaded afterwards from the vendor's own CDN still need that host in script-src (and its API in connect-src).

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

jeffersongoncalves/laravel-cookie-consent

This Laravel package provides a simple and elegant way to implement cookie conse...

18,107 5
jeffersongoncalves/laravel-gtm

This plugin seamlessly integrates Google Tag Manager (GTM) into your website, en...

6,920 4
jeffersongoncalves/laravel-cep

A simple and efficient PHP package for querying Brazilian postal codes (CEP). Th...

6,525 3
jeffersongoncalves/laravel-pwa-favicon

This Laravel package serves a spec-shaped PWA `manifest.json` (with Android dens...

5,222 3
jeffersongoncalves/laravel-favicon

This Laravel package serves a favicon.ico route, a browserconfig.xml for Windows...

4,205 2

Version History

Version Released PHP Laravel License
3.1.0 ^8.2|^8.3|^8.4 ^12.61.1|^13.12.0 MIT
3.0.0 ^8.2|^8.3|^8.4 ^12.61.1|^13.12.0 MIT
2.0.3 ^8.2|^8.3 ^11.0|^12.0|^13.0 MIT
2.0.2 ^8.2|^8.3 ^11.0|^12.0|^13.0 MIT
2.0.1 ^8.2|^8.3 ^11.0|^12.0|^13.0 MIT