Zum Inhalt springen
← Zurück zu den Projekten

Laravel Pixel

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

#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.

Neue Version verfügbar.