rsmmonaem / laravel-meta-ads-attribution
Production-ready Meta/Facebook Ads attribution, customer journey tracking, order attribution, and delivered-order Conversions API (CAPI) system for Laravel e-commerce.
Package info
github.com/rsmmonaem/laravel-meta-ads-attribution
pkg:composer/rsmmonaem/laravel-meta-ads-attribution
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0|^8.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/queue: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Production-ready Meta/Facebook Ads attribution, first-party cookie resilience, order attribution, and qualified DELIVERED order Conversions API (CAPI) system for Laravel e-commerce applications.
π Complete Tracking Pipeline Architecture
[ Customer Clicks Meta Ad (Facebook / Instagram) ]
β (URL decoration: ?fbclid=IwAR...&utm_source=facebook&utm_campaign=Summer_Drop)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STAGE 1: Ingress & First-Party Cookie Capture (Middleware) β
β β’ Generates / Refreshes 90-day cookie: meta_visitor_id β
β β’ Emits server HTTP cookies: _fbc & _fbp (SameSite=Lax, Safari ITP) β
β β’ Logs touchpoint in meta_ad_attributions & meta_tracking_sessions β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββββββββ βββββββββββββββββββββββββ βββββββββββββββββββββββββ
β STAGE 2: Browsing β β STAGE 3: Add to Cart β β STAGE 4: Checkout β
β β’ ViewContent event β β β’ AddToCart event β β β’ Order saved in DB β
β β’ DataLayer view_item β β β’ DataLayer add_to_cartβ β β’ HasMetaAttribution β
β β’ Shared event_id β β β’ Shared event_id β β binds attribution β
βββββββββββββββββββββββββ βββββββββββββββββββββββββ β β’ Status: pending β
β β βββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STAGE 5: Fulfillment & Qualified Conversion Trigger (Eloquent Hook) β
β β’ Admin or Webhook updates order status: pending -> processing -> shipped -> DELIVERED β
β β’ HasMetaAttribution detects status === 'delivered' and verifies Meta acquisition source β
β β’ Dispatches queued job: SendMetaDeliveredConversionJob β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STAGE 6: Customer Matching & SHA-256 Hashing (Conversions API Service) β
β β’ Resolves true original customer IP & User-Agent (avoiding worker 127.0.0.1 or admin IP) β
β β’ Automatically parses full customer_name into first_name (fn) and last_name (ln) β
β β’ Normalizes and hashes PII: em, ph, fn, ln, ct, st, zp, country, external_id β
β β’ Assigns deterministic event_id: purchase_{order_id} (100% duplicate protection) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STAGE 7: Meta Conversions API (Graph API v19.0) & Deduplication β
β β’ Dispatches JSON payload to Meta Graph API endpoint β
β β’ Meta Events Manager deduplicates browser pixel & server CAPI via shared event_id β
β β’ Records HTTP response, timestamp, and retry metrics in meta_conversion_events table β
β β’ Full visibility & 1-click manual event retry in Admin Dashboard (/admin/meta-attribution) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Key Features
- First-Party Attribution Engine: Intercepts
fbclid, UTM tags (utm_source,utm_medium,utm_campaign, etc.), and campaign IDs. - Safari ITP Defense: Sets 90-day HTTP response cookies (
_fbpand_fbcviaSet-CookiewithSameSite=Lax) to prevent Safari's 24-hour client JS cookie expiration. - Qualified Conversion Trigger: Dispatches Meta CAPI
Purchaseevents ONLY when an order reachesdeliveredstatus, protecting ad algorithms from cancelled/fake orders. - True Customer Match Quality (EMQ): Sends the customer's original browsing IP, User-Agent, and automatically splits full names into hashed
fnandlnparameters for 8.5+ Event Match Quality. - Idempotency & Deduplication: Deterministic
purchase_{order_id}IDs guarantee zero duplicate conversions, even during multiple status changes or queue retries. - Full GTM / DataLayer Support: Ready for browser-side Google Tag Manager event deduplication with server-side CAPI.
- Admin Dashboard: Real-time attribution analytics and conversion retry console at
/admin/meta-attribution.
π₯ Installation
composer require rsmmonaem/laravel-meta-ads-attribution
Run the package installer:
php artisan meta-attribution:install php artisan migrate
βοΈ Quick Configuration
Add to your .env:
META_ATTRIBUTION_ENABLED=true META_ENABLE_BROWSER_PIXEL=true META_ENABLE_CAPI=true META_PIXEL_ID=your_meta_pixel_id META_ACCESS_TOKEN=your_meta_system_user_token META_QUALIFIED_ORDER_STATUS=delivered
Register Middleware (bootstrap/app.php):
use RsmMonaem\MetaAdsAttribution\Middleware\CaptureMetaAttributionMiddleware; return Application::configure(basePath: dirname(__DIR__)) ->withMiddleware(function (Middleware $middleware): void { $middleware->web(append: [ CaptureMetaAttributionMiddleware::class, ]); }) ->create();
Attach Trait to Order Model:
namespace App\Models; use Illuminate\Database\Eloquent\Model; use RsmMonaem\MetaAdsAttribution\Traits\HasMetaAttribution; class Order extends Model { use HasMetaAttribution; }
π Pipeline Comparison: Standard vs Qualified Delivered CAPI
| Feature | Standard Browser Pixel Only | Third-Party Webhook Plugins | rsmmonaem/laravel-meta-ads-attribution |
|---|---|---|---|
| Trigger Point | Checkout button click | Order creation | Actual Delivery / Fulfillment |
| Cancelled Order Waste | π΄ 100% false conversions | π΄ 100% false conversions | π’ 0% (Filtered Out) |
| Ad Blocker Defense | π΄ Blocked by uBlock/Brave | π‘ Partial | π’ 100% Server-Side Resilience |
| Safari ITP Retention | π΄ 24 hours to 7 days max | π‘ Session only | π’ 90-Day First-Party HTTP Cookie |
| Customer Match Quality | π‘ 4.0 - 5.5 / 10 | π‘ 5.0 - 6.5 / 10 | π’ 8.5 - 9.5 / 10 (Full PII + Original IP/UA) |
| Duplicate Prevention | π΄ High duplicate risk | π‘ Basic timestamp | π’ Deterministic purchase_{id} Idempotency |
| Ongoing Cost | Free (Low Quality) | $50 - $200/mo (Third-Party SaaS / Stape) | π’ Free & Open-Source Forever |
π Comparison: Top Alternatives to Stape.io & Third-Party SaaS
While third-party server-side tracking providers offer cloud proxy containers or managed dashboards, they charge recurring monthly subscription fees and still trigger purchase events at initial checkout rather than after actual delivery.
Here is how direct native Laravel tracking compares with popular hosted alternatives:
- TAGGRS: A popular EU-hosted (GDPR-compliant) server-side GTM hosting provider offering free tiers and similar container setups to Stape. [1, 2]
- Tracklution: A fully managed tracking platform that bypasses the need for Google Tag Manager completely for a simpler plug-and-play setup. [1, 2]
- Conversios: An e-commerce focused tracking solution designed specifically with pre-configured setups for Shopify and WooCommerce stores. [1]
- ServerTrack.io: A simplified server-side tracking alternative advertised for ultra-fast setups without deep technical configuration. [1, 2]
- CustomerLabs: A first-party data operations platform focused on marketing stack integration and audience activation.
π‘ The Native Laravel Advantage: If you run a Laravel application, you don't need third-party proxy subscriptions or external container costs. This package runs directly on your server via background queues β guaranteeing zero monthly overhead, 100% data privacy, and event triggering strictly tied to actual order fulfillment.
π¬ Contact Me
Have questions, need custom tracking integrations, or want to discuss enterprise Meta/CAPI attribution? Feel free to reach out:
- Facebook: facebook.com/rsmmonaemid
π Complete Guides & Documentation
- Full Technical Reference (DOCUMENTATION.md) β Architectural deep-dive, configuration parameters, and API reference.
- GTM & DataLayer Setup Guide (use_case_and_setup_guide.md) β Step-by-step DataLayer schemas, GTM triggers, variables, and tags.
License
The MIT License (MIT). Please see License for more information.