Download the PHP package coversgift/facebook-pixel-capi without Composer
On this page you can find all versions of the php package coversgift/facebook-pixel-capi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coversgift/facebook-pixel-capi
More information about coversgift/facebook-pixel-capi
Files in coversgift/facebook-pixel-capi
Package facebook-pixel-capi
Short Description A simple Laravel package to send server-side events to the Facebook Conversions API (CAPI).
License MIT
Informations about the package facebook-pixel-capi
Facebook Conversions API Service for Laravel
A simple Laravel package to send server-side events to the Facebook Conversions API (CAPI). This helps in tracking user actions more reliably, especially when browser-based tracking (like the Pixel) is blocked or limited.
Features
- Easy-to-use Facade for sending events.
- Handles hashing of user data (
phone
,userID
). - Configurable via
.env
file. - Supports test events for debugging.
1. Installation
Since this is a local package, it's already integrated into your project. If it were a standard Composer package, you would run:
2. Configuration
a. Register Service Provider and Facade
The package's Service Provider and Facade must be registered in your config/app.php
file. Your project already has this configured.
config/app.php
b. Publish Configuration File
To customize the configuration, publish the config file using the following Artisan command:
This command will create a config/facebookpixel.php
file in your project, allowing you to manage settings centrally.
c. Set Environment Variables
Add the following keys to your .env
file with your Facebook App credentials.
FACEBOOK_PIXEL_ID
: Your Facebook Pixel ID.FACEBOOK_ACCESS_TOKEN
: A server-side access token generated from your Business Manager.FACEBOOK_TEST_EVENT_CODE
: (Optional) Use this to test events in the Events Manager without affecting your production data. The package automatically uses this whenAPP_ENV
is notproduction
.
3. Usage
The primary way to use the service is through the FacebookPixel
facade.
a. Capturing the _fbp
Cookie (Frontend)
For accurate event matching and deduplication, it's crucial to send the _fbp
(Facebook browser ID) cookie value with your server-side events. This value is created by the Facebook Pixel script on the user's browser.
You can capture it by adding a hidden input field to your forms and using a small JavaScript snippet to populate it.
1. Add a hidden input to your form:
2. Add the following JavaScript to your page:
This script will find the _fbp
cookie and set its value to the hidden input field.
Now, when the form is submitted, the fbp
value will be available in your controller via $request->fbp
.
b. Sending an Event (Backend)
To send an event, call the sendPixelEvent
method with an array of event data.
Event Data Parameters
The $eventData
array should contain the following keys:
Key | Required | Description |
---|---|---|
event_name |
Yes | The type of event (e.g., Purchase , AddToCart , ViewContent ). |
event_time |
Yes | Unix timestamp of when the event occurred. |
event_id |
Yes | A unique ID for this specific event. Required for deduplication. |
userID |
Yes | The unique ID of the logged-in user in your system. Will be hashed. |
phone |
Yes | The user's phone number. Will be hashed. |
fbp |
Yes | The _fbp cookie from the user's browser. Helps with matching. |
client_ip_address |
Yes | The user's IP address. |
client_user_agent |
Yes | The user's browser user agent string. |
value |
Yes | The monetary value of the event (e.g., total order price). |
currency |
Yes | The currency code (e.g., BDT , USD ). |
content_ids |
Yes | An array of product IDs associated with the event. |
content_type |
Yes | The type of content (usually product or product_group ). |
order_id |
Yes | The unique ID for the order. |
email |
No | The user's email address. The service will hash it if provided. |
4. Example: Tracking a Purchase Event
This example shows how to track a purchase event from a controller and ensure it's deduplicated with the browser-side Pixel event.
Controller (OrderController.php
)
This is a simplified version of your placeOrder
method, highlighting the CAPI integration steps.
View (thank-you.blade.php
)
To prevent duplicate event counting, you must send the same event_id
from both the server (CAPI) and the browser (Pixel).
This setup ensures that Facebook receives both events but understands they represent the same purchase, correctly deduplicating them in your Events Manager.
All versions of facebook-pixel-capi with dependencies
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0