Skip to main content
add ajax function and call
Source Link

The Facebook Conversion API eventsFacebook Conversion API events are more powerful overthan the Facebook Web PixelsFacebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

Facebook Pixel Conversion API

https://developers.facebook.com/docs/marketing-api/conversions-api/

you can generate the access token from https://business.facebook.com/event_manager select your site and generate the facebook pixleFacebook pixel

javascript ajax function and you can simply call this ajax function where you want to trigger pixel

Function Call

let event_id = d.getTime(); fbq_custom("PageView", window.location.href, {event_id: 'PageView-'+event_id}, {event_id: 'PageView-'+event_id}) } 

Function Definition

function fbq_custom(trace = 'PageView', source_url = '', data = {}){ data.trace = trace; data.source_url = source_url $.ajax({ url: "/conversionAPI/", data: data, type: "post", success: function (data) { console.log(data); console.log("server event test"); } }); } 

https://github.com/facebook/facebook-php-business-sdk

PHP API

The Facebook Conversion API events are more powerful over the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

you can generate the access token from https://business.facebook.com/event_manager select your site and generate the facebook pixle

https://github.com/facebook/facebook-php-business-sdk

The Facebook Conversion API events are more powerful than the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

Facebook Pixel Conversion API

https://developers.facebook.com/docs/marketing-api/conversions-api/

you can generate the access token from https://business.facebook.com/event_manager select your site and generate the Facebook pixel

javascript ajax function and you can simply call this ajax function where you want to trigger pixel

Function Call

let event_id = d.getTime(); fbq_custom("PageView", window.location.href, {event_id: 'PageView-'+event_id}, {event_id: 'PageView-'+event_id}) } 

Function Definition

function fbq_custom(trace = 'PageView', source_url = '', data = {}){ data.trace = trace; data.source_url = source_url $.ajax({ url: "/conversionAPI/", data: data, type: "post", success: function (data) { console.log(data); console.log("server event test"); } }); } 

https://github.com/facebook/facebook-php-business-sdk

PHP API

added 135 characters in body
Source Link

The Facebook Conversion API events are more powerful over the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

you can generate the access token from https://business.facebook.com/event_manager select your site and generate the facebook pixle

I just use this package

https://github.com/facebook/facebook-php-business-sdk

use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\ServerSide\Content; use FacebookAds\Object\ServerSide\CustomData; use FacebookAds\Object\ServerSide\DeliveryCategory; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\EventRequest; use FacebookAds\Object\ServerSide\Gender; use FacebookAds\Object\ServerSide\UserData; $trace = $_POST['trace']; $source_url = $_POST['source_url']; $firstname = $_POST['firstname'] ? $_POST['firstname']: ""; $lastname = $_POST['lastname'] ? $_POST['lastname']: ""; $phone = $_POST['telephone'] ? $_POST['telephone']: ""; $email = $_POST['email'] ? $_POST['email']: ""; $event_id = $_POST['event_id'] ? $_POST['event_id']: ""; $action_source = $_POST['action_source'] ? $_POST['action_source']: "website"; $access_token = 'here you need to add the access token'; $pixel_id = 'your pixel id'; if (is_null($access_token) || is_null($pixel_id)) { throw new Exception( 'You must set your access token and pixel id before executing' ); } Api::init(null, null, $access_token); $api = Api::instance(); $api->setLogger(new CurlLogger()); $events = array(); $user_data = (new UserData()) ->setClientIpAddress($_SERVER['REMOTE_ADDR']) ->setClientUserAgent($_SERVER['HTTP_USER_AGENT']) ->setEmail($email) ->setPhone($phone) ->setFirstName($firstname) ->setLastName($lastname); $custom_data = (new CustomData()); $event = (new Event()) ->setEventName($trace) ->setEventTime(time()) ->setEventId($event_id) ->setEventSourceUrl($source_url) ->setActionSource($action_source) ->setUserData($user_data) ->setCustomData($custom_data); $events = array(); array_push($events, $event); $request = (new EventRequest($pixel_id)) ->setEvents($events); $response = $request->execute(); print_r(array( "status" => 200, "message" => "pixel code added successfully", "source_url" => $source_url, 'trace' => $trace, 'event_id' => $event_id, "response" => $response, "user_data" => $user_data, "event" => $event )) ; 

The Facebook Conversion API events are more powerful over the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

I just use this package

https://github.com/facebook/facebook-php-business-sdk

use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\ServerSide\Content; use FacebookAds\Object\ServerSide\CustomData; use FacebookAds\Object\ServerSide\DeliveryCategory; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\EventRequest; use FacebookAds\Object\ServerSide\Gender; use FacebookAds\Object\ServerSide\UserData; $trace = $_POST['trace']; $source_url = $_POST['source_url']; $firstname = $_POST['firstname'] ? $_POST['firstname']: ""; $lastname = $_POST['lastname'] ? $_POST['lastname']: ""; $phone = $_POST['telephone'] ? $_POST['telephone']: ""; $email = $_POST['email'] ? $_POST['email']: ""; $event_id = $_POST['event_id'] ? $_POST['event_id']: ""; $action_source = $_POST['action_source'] ? $_POST['action_source']: "website"; $access_token = 'here you need to add the access token'; $pixel_id = 'your pixel id'; if (is_null($access_token) || is_null($pixel_id)) { throw new Exception( 'You must set your access token and pixel id before executing' ); } Api::init(null, null, $access_token); $api = Api::instance(); $api->setLogger(new CurlLogger()); $events = array(); $user_data = (new UserData()) ->setClientIpAddress($_SERVER['REMOTE_ADDR']) ->setClientUserAgent($_SERVER['HTTP_USER_AGENT']) ->setEmail($email) ->setPhone($phone) ->setFirstName($firstname) ->setLastName($lastname); $custom_data = (new CustomData()); $event = (new Event()) ->setEventName($trace) ->setEventTime(time()) ->setEventId($event_id) ->setEventSourceUrl($source_url) ->setActionSource($action_source) ->setUserData($user_data) ->setCustomData($custom_data); $events = array(); array_push($events, $event); $request = (new EventRequest($pixel_id)) ->setEvents($events); $response = $request->execute(); print_r(array( "status" => 200, "message" => "pixel code added successfully", "source_url" => $source_url, 'trace' => $trace, 'event_id' => $event_id, "response" => $response, "user_data" => $user_data, "event" => $event )) ; 

The Facebook Conversion API events are more powerful over the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

you can generate the access token from https://business.facebook.com/event_manager select your site and generate the facebook pixle

I just use this package

https://github.com/facebook/facebook-php-business-sdk

use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\ServerSide\Content; use FacebookAds\Object\ServerSide\CustomData; use FacebookAds\Object\ServerSide\DeliveryCategory; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\EventRequest; use FacebookAds\Object\ServerSide\Gender; use FacebookAds\Object\ServerSide\UserData; $trace = $_POST['trace']; $source_url = $_POST['source_url']; $firstname = $_POST['firstname'] ? $_POST['firstname']: ""; $lastname = $_POST['lastname'] ? $_POST['lastname']: ""; $phone = $_POST['telephone'] ? $_POST['telephone']: ""; $email = $_POST['email'] ? $_POST['email']: ""; $event_id = $_POST['event_id'] ? $_POST['event_id']: ""; $action_source = $_POST['action_source'] ? $_POST['action_source']: "website"; $access_token = 'here you need to add the access token'; $pixel_id = 'your pixel id'; if (is_null($access_token) || is_null($pixel_id)) { throw new Exception( 'You must set your access token and pixel id before executing' ); } Api::init(null, null, $access_token); $api = Api::instance(); $api->setLogger(new CurlLogger()); $events = array(); $user_data = (new UserData()) ->setClientIpAddress($_SERVER['REMOTE_ADDR']) ->setClientUserAgent($_SERVER['HTTP_USER_AGENT']) ->setEmail($email) ->setPhone($phone) ->setFirstName($firstname) ->setLastName($lastname); $custom_data = (new CustomData()); $event = (new Event()) ->setEventName($trace) ->setEventTime(time()) ->setEventId($event_id) ->setEventSourceUrl($source_url) ->setActionSource($action_source) ->setUserData($user_data) ->setCustomData($custom_data); $events = array(); array_push($events, $event); $request = (new EventRequest($pixel_id)) ->setEvents($events); $response = $request->execute(); print_r(array( "status" => 200, "message" => "pixel code added successfully", "source_url" => $source_url, 'trace' => $trace, 'event_id' => $event_id, "response" => $response, "user_data" => $user_data, "event" => $event )) ; 
Source Link

The Facebook Conversion API events are more powerful over the Facebook Web Pixels. The Conversion API event gets fired through backend logic. you can use the ajax call from the front end, and check the event triggers on the Facebook panel

I just use this package

https://github.com/facebook/facebook-php-business-sdk

use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\ServerSide\Content; use FacebookAds\Object\ServerSide\CustomData; use FacebookAds\Object\ServerSide\DeliveryCategory; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\EventRequest; use FacebookAds\Object\ServerSide\Gender; use FacebookAds\Object\ServerSide\UserData; $trace = $_POST['trace']; $source_url = $_POST['source_url']; $firstname = $_POST['firstname'] ? $_POST['firstname']: ""; $lastname = $_POST['lastname'] ? $_POST['lastname']: ""; $phone = $_POST['telephone'] ? $_POST['telephone']: ""; $email = $_POST['email'] ? $_POST['email']: ""; $event_id = $_POST['event_id'] ? $_POST['event_id']: ""; $action_source = $_POST['action_source'] ? $_POST['action_source']: "website"; $access_token = 'here you need to add the access token'; $pixel_id = 'your pixel id'; if (is_null($access_token) || is_null($pixel_id)) { throw new Exception( 'You must set your access token and pixel id before executing' ); } Api::init(null, null, $access_token); $api = Api::instance(); $api->setLogger(new CurlLogger()); $events = array(); $user_data = (new UserData()) ->setClientIpAddress($_SERVER['REMOTE_ADDR']) ->setClientUserAgent($_SERVER['HTTP_USER_AGENT']) ->setEmail($email) ->setPhone($phone) ->setFirstName($firstname) ->setLastName($lastname); $custom_data = (new CustomData()); $event = (new Event()) ->setEventName($trace) ->setEventTime(time()) ->setEventId($event_id) ->setEventSourceUrl($source_url) ->setActionSource($action_source) ->setUserData($user_data) ->setCustomData($custom_data); $events = array(); array_push($events, $event); $request = (new EventRequest($pixel_id)) ->setEvents($events); $response = $request->execute(); print_r(array( "status" => 200, "message" => "pixel code added successfully", "source_url" => $source_url, 'trace' => $trace, 'event_id' => $event_id, "response" => $response, "user_data" => $user_data, "event" => $event )) ;