Download the PHP package aghfatehi/laravel-meta-conversions without Composer
On this page you can find all versions of the php package aghfatehi/laravel-meta-conversions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aghfatehi/laravel-meta-conversions
More information about aghfatehi/laravel-meta-conversions
Files in aghfatehi/laravel-meta-conversions
Package laravel-meta-conversions
Short Description Laravel package for Facebook Pixel and Meta Conversion API (CAPI) with event deduplication, queue support, and ecommerce tracking.
License MIT
Homepage https://fsoftdev.com
Informations about the package laravel-meta-conversions
Laravel Meta Conversions — Meta Pixel & Facebook CAPI Package
The complete Meta Pixel & Facebook Conversions API solution for Laravel.
Laravel Meta Conversions is a complete Meta Pixel Laravel Package and Facebook Pixel Laravel Package that integrates Laravel Facebook Pixel browser tracking with Laravel Meta Conversions API (CAPI) server-side tracking. It delivers accurate Server Side Tracking Laravel for reliable Meta Conversion Tracking and Facebook Conversion Tracking across your entire ecommerce funnel.
Goal: High-precision Laravel Ecommerce Tracking with event deduplication via unified
event_idacross browser + server for maximum Meta Advanced Matching quality. Built for Laravel Marketing Analytics and data-driven ad optimization.
Features
General
- Laravel Meta Pixel + CAPI in a single package — full Laravel CAPI support
- Laravel 10.x / 11.x / 12.x and PHP 8.2+
- Auto-Discovery (install and run)
- Compatible with official Meta requirements
Client-side (Laravel Meta Pixel)
<x-facebook-conversion::pixel />— ready-to-use Blade component for Laravel Facebook Pixel@include('facebook-conversion::pixel')— alternative include approach- Auto
fbq('init')with your Pixel ID - Auto
fbq('track', 'PageView')on every page - Pass
event_idfrom backend to frontend for unified deduplication
Server-side (Laravel Meta Conversions API)
- Send events via Laravel Facebook Conversions API →
graph.facebook.com/{version}/{pixel_id}/events - 12 standard events: PageView, ViewContent, Search, AddToWishlist, AddToCart, RemoveFromCart, InitiateCheckout, AddPaymentInfo, Meta Purchase Event, Lead, CompleteRegistration, Contact
- Fluent API:
FacebookConversion::event()->name('...')->value(...)->send()
User Data & Meta Advanced Matching
- Automatic SHA-256 hashing as required by Meta Conversion Tracking
em,ph,fn,ln,ct,st,zp,country,external_id- Auto-extract
client_ip_addressandclient_user_agent - Auto-read
_fbp,_fbccookies - Auto-fill from
auth()->user()when available
Queue & Performance
- Queue support via
FACEBOOK_QUEUE=truefor non-blocking Server Side Tracking Laravel - Events dispatched through
SendFacebookEventJob - Auto-retry on failure: 3 attempts with 100ms delay
- Configurable HTTP timeout
Testing & Logging
- Artisan command:
php artisan facebook:test-eventto verify Laravel CAPI integration - Test Event Code support for validation in Meta Events Manager
- Dedicated
facebook_conversionlog channel with 30-day rotation - Access token is masked in all logs
Security & Error Handling
- Master switch:
FACEBOOK_ENABLED=falsedisables all tracking - Graceful failure — never breaks your application
- Configuration validation before sending
- GDPR-compliant: easy opt-out
Installation
Step 1: Install the package
Laravel auto-discovers the Service Provider. If you disable auto-discovery, register manually:
Step 2: Publish config
Config file published to config/facebook-conversion-service.php.
Step 3: Publish views (optional)
Views published to resources/views/vendor/facebook-conversion/pixel.blade.php.
Setup
1. Get your Facebook Pixel ID
- Open Facebook Events Manager → Meta Events Manager
- Select an existing pixel or create a new one for Laravel Meta Pixel
- Copy the Pixel ID from the top
- Set in your
.env:
2. Get your CAPI Access Token
- In Meta Events Manager → Settings
- Scroll to Conversion API
- Click Generate Access Token
- Copy the token (starts with
EAA...) - Set in your
.env:
Tokens may expire. Regenerate periodically. Enable domain verification in Business Manager.
3. Configure additional variables
Usage
Add Pixel to your layout
Insert this in your <head> tag:
Or using @include:
The pixel automatically fires
fbq('track', 'PageView')on every page load.
Real-world Examples from an Ecommerce Store
View Content (Product Page)
Use in HomeController@product when a visitor views a product page:
Add to Cart
Use in CartController@addToCart after adding a product:
Add to Wishlist
Use in WishlistController@store:
Purchase (most important event)
Use in OrderController@store after order creation:
Complete Event List
Event Builder (Fluent API)
For full control over your Laravel CAPI event payload:
Or build the event object and send it later:
Event Deduplication — Core of Meta Conversion Tracking
Meta requires a unified event_id sent from both Laravel Facebook Pixel (browser) and Laravel CAPI (server) to identify duplicate events. This is the foundation of accurate Facebook Conversion Tracking.
How it works
The package generates a UUID v4 automatically for every event. You can customize it:
To pass event_id from server to Pixel (e.g., from an API response):
User Data with Meta Advanced Matching
Automatic Data Collection — for Meta Advanced Matching
Whenever you fire an event, the package automatically collects user data to enhance Meta Events Manager with Meta Advanced Matching:
SHA-256 Hashing per Meta Requirements
All data is hashed with SHA-256 as required by Meta Conversion Tracking:
Hashing Reference
| Field | Original | Hashed |
|---|---|---|
em |
[email protected] |
SHA-256(lowercase(trim(email))) |
ph |
+966 55 123 4567 |
SHA-256(strip non-numeric) |
fn |
Ahmed |
SHA-256(lowercase(trim)) |
ln |
Ghfatehi |
SHA-256(lowercase(trim)) |
ct |
Riyadh |
SHA-256(lowercase(trim)) |
st |
Riyadh Province |
SHA-256(lowercase(trim)) |
zp |
12345 |
SHA-256(lowercase(trim)) |
country |
SA |
SHA-256(lowercase(trim)) |
external_id |
user_123 |
SHA-256 |
Queue Support
In production, enable the queue to avoid blocking HTTP requests when using Laravel CAPI:
Make sure a queue worker is running:
How it works with FACEBOOK_QUEUE=true:
The controller returns immediately. The event is processed in the background.
Middleware
TrackFacebookPageView
Automatically sends PageView via Server Side Tracking Laravel on every GET request:
Or on specific routes:
The middleware sends the PageView after the response is sent (terminate method) to avoid slowing down the page.
Testing Events via Meta Events Manager
1. Using Test Event Code
In development, use Meta's test code to validate your Laravel CAPI integration:
Open Meta Events Manager → Test Events and watch your Laravel Meta Conversions API events arrive in real time.
2. Using Artisan Command
3. Verify in Meta Events Manager
After sending events:
- Open Meta Events Manager → Meta Events Manager
- Go to Test Events tab (if using Test Event Code)
- Or go to Diagnostics to see real events
- Check Event Match Quality for each event
Logging
Logs are written to storage/logs/facebook-conversion.log with daily rotation (30 days).
Access token is masked:
EAAJjm****
Production Checklist
- [ ]
FACEBOOK_PIXEL_IDandFACEBOOK_PIXEL_APIare set - [ ]
FACEBOOK_ENABLED=true - [ ]
FACEBOOK_TEST_EVENT_CODEis empty (remove in production!) - [ ]
FACEBOOK_QUEUE=trueand queue is running - [ ]
php artisan queue:work(or Supervisor) is active - [ ] Domain is verified in Facebook Business Manager
- [ ] Laravel Facebook Pixel fires on all pages
- [ ] Events appear in Meta Events Manager
- [ ] Event Match Quality > 90%
Troubleshooting
| Problem | Solution |
|---|---|
| Events not appearing | Check FACEBOOK_ENABLED=true and valid Pixel ID |
| 401 Unauthorized | Regenerate Access Token in Meta Events Manager |
| Low match quality | Send more user data (email, phone, fbp, fbc) for Meta Advanced Matching |
| Duplicate events | Ensure event_id is unique per event (package generates UUID automatically) |
| Queue not working | Check php artisan queue:work and queue connection |
| Config error | Check storage/logs/facebook-conversion.log |
| Token expired | Regenerate in Meta Events Manager → Settings → Conversion API |
Testing
Architecture
Data flow:
License
MIT License. See LICENSE for details.
Built by Ahmed Ghfatehi · fsoftdev.com
All versions of laravel-meta-conversions with dependencies
illuminate/support Version ^10.0 || ^11.0 || ^12.0
illuminate/http Version ^10.0 || ^11.0 || ^12.0
illuminate/bus Version ^10.0 || ^11.0 || ^12.0
illuminate/view Version ^10.0 || ^11.0 || ^12.0
ramsey/uuid Version ^4.0
guzzlehttp/guzzle Version ^7.0