2

I am using PHP with Laravel to create an E-commerce and integrating Facebook pixel and everything was working properly, then after IOS 14 update, the pixel integration isn't working properly, so I heard that if we integrated the Facebook conversion APIs and add the domain verification code it would solve the problem

so I tried to add this

<meta name="facebook-domain-verification" content="myCode" /> 

so my question is: is it correct that integration conversion APIs would solve the problem, and if it is correct - I don't know where and how to integrate these conversion APIs

3
  • HI I've just added the conversion API into my project can help, do you still need it ? Commented Sep 21, 2021 at 12:46
  • yes please i do Commented Sep 21, 2021 at 12:55
  • I'd provide the sample code and you can use the same just pass your credentials and pass the data from the ajax Commented Sep 21, 2021 at 13:03

1 Answer 1

4

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"); } }); } 

I just use this package

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

PHP API

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 )) ; 
Sign up to request clarification or add additional context in comments.

7 Comments

First time, someone posted clear code to set up the conversion API. I am getting error on inputs that trace , lastname, telephone are undefined index. Can you please guide me? 😭
undefined where on the Facebook panel or on the code ?
in the code. From where are you getting these inputs?
I have a form where user input their information and I did submitted according to the user information.
obviously you have to pass the input values otherwise it consider it undefined.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.