medboubazine/facebook-pixel

Facebook Pixel Events for PHP

0.1.1 2024-05-01 17:08 UTC

This package is auto-updated.

Last update: 2024-12-01 00:15:55 UTC


README

use Medboubazine\FacebookPixel\Elements\EventCredentialsElement;
use Medboubazine\FacebookPixel\Elements\Events\ProductElement;
use Medboubazine\FacebookPixel\Elements\Events\UserElement;
use Medboubazine\FacebookPixel\FacebookPixel;

require "../vendor/autoload.php";

$pixel_id = 'DATASET_ID';//PIXEL_ID
$access_token = 'ACCESS_TOKEN';

$pixel = new FacebookPixel(new EventCredentialsElement($pixel_id, $access_token));

///
/// PageView Event
///

$user = new UserElement("IP", "UserAgent");

$event = $pixel->page_view_event()->handle($user, "URL_HERE");

$response = $event->push();
///
/// Purchase Event
///
$user = new UserElement("IP", "UserAgent");
$product = new ProductElement("21", 1, "20.34", "usd", "URL_HERE");

$event = $pixel->purchase_event()->handle($user, $product);


$response = $event->push();