Engineering

Facebook Conversions API

Introduction

In January 2020, Google made clear its intention to stop supporting third-party cookies in Chrome. Third-party cookies have been the backbone of the display and native advertising industry for over a decade.

The Conversions API allows advertisers to send web events from their servers directly to Facebook. Server events are linked to a pixel and are processed like browser pixel events. This means that server events are used in measurement, reporting, and optimization in the same way as browser pixel events.

Requirements
There are three main requirements for implementing the Conversions API.

Pixel
Before implementing the Conversions API, make sure the Facebook pixel is correctly implemented on your website. We recommend that you use the same pixel for your browser and server events.
- We already have a pixel account that is currently working.
- I have created a personal pixel account for this POC.

Business Manager
You also need a Business Manager to use the API. Business Manager helps advertisers integrate Facebook marketing efforts across their business and with external partners.
- We also have it.
- I created one for this POC.

Access Token
To use the Conversions API, you need an access token.
To get an access token, follow this guide: https://developers.facebook.com/docs/marketing-api/conversions-api/get-started#via-events-manager

Note: you need admin or developer privileges to generate an access token.
Note 2: to send test data, add this parameter to the payload: {test_event_code: TEST6810}

Code
We can verify the request and response with the Payload Helper: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper

Using jQuery, I was able to call the Conversions API and register events. But we are not going to use this approach, because we don’t want to expose the access token on the client side.

Call from JS:

let userAgentString = navigator.userAgent;

let jsonData = JSON.stringify({
“data” : [
{

“event_time”: Math.round((new Date()).getTime() / 1000),
“event_name”: “Purchase”,
“user_data”: {
“em”: “7b17fb0bd173f625b58636fb796407c22b3d16fc78302d79f0fd30c2fc2fc068”,
“ph”: null,
“client_user_agent”: userAgentString,
“fbc”: “fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890”,
“fbp”: “fb.1.1558571054389.1098115397”,
“client_ip_address”: “123.123.123.123”
},
“custom_data”: {
“currency”: “USD”,
“value”: 143
},
“event_source_url”: “http://munir/123”,
“action_source”: “website-test”
}
]
});

url = “https://graph.facebook.com/v10.0/{PIXEL\_ID}/events?access\_token={ACCESS\_TOKEN}”;

$.ajax({
url: url,
data: jsonData,
contentType: “application/json”,
dataType: ‘json’,
type : “POST”,
success: function(result){
console.log(result);
}
});

1. Introduction

https://developers.facebook.com/docs/marketing-api/conversions-api/set-up-conversions-api-as-a-platform

Before starting, it is important to understand the relationship between server events and the Facebook Pixel. Server events are sent via the Conversions API and used in measurement, reporting, and optimization in the same way as browser pixel events.

2. Raw event example to Facebook

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

curl -X POST \
-F ‘data=[
{
“event_name”: “Purchase”,
“event_time”: 1616732932,
“user_data”: {
“em”: “309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd”,
“client_ip_address”: “123.123.123.123”,
“client_user_agent”: “$CLIENT_USER_AGENT”,
“fbc”: “fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890”,
“fbp”: “fb.1.1558571054389.1098115397”
},
“contents”: [
{
“id”: “product123”,
“quantity”: 1,
“delivery_category”: “home_delivery”
}
],
“custom_data”: {
“currency”: “usd”,
“value”: 123.45
},
“event_source_url”: “http://jaspers-market.com/product/123”,
“action_source”: “website”
}
]’ \
-F ‘access_token=<ACCESS_TOKEN>’ \
https://graph.facebook.com/v10.0/<PIXEL_ID>/events

3. Tasks

  1. Set up the Conversions API account and get all data required for the POST request - 8h

2. Set up a pipeline in Sitecore for all requests that need to send a server event - 6h

3. Map requests to events: View Page, Submit Application, Event Registration Confirmation - 3h

4. Implement an asynchronous call to the Conversions API in Sitecore - 6h

5. Set up interception for all required requests in the legacy system - 4h

6. Map legacy requests to events: View Page, Submit Application, Event Registration Confirmation - 3h

  1. Implement an asynchronous call to the Conversions API in the legacy system - 4h