All Collections
Datatrics' key features explained
Advanced
Enabling the Meta (Facebook) Conversion API sync
Enabling the Meta (Facebook) Conversion API sync

How to synchronize page views, item views, carts and conversions with Meta through the Conversion API

Christiaan Proper avatar
Written by Christiaan Proper
Updated over a week ago

The Meta (Facebook) Conversions API is designed to create a direct connection between your marketing data and the systems which help optimize ad targeting, decrease cost per action, and measure results across Meta technologies.

Since you connected your marketing channels to Datatrics and deployed the Datatrics tracker on your website, Datatrics already captures all the data you would normally sync to Meta via the Meta Pixel. Since the Meta Pixel needs third-party cookies enabled, and the Datatrics tracker works without them, using the Meta Conversion API sync in Datatrics prevents you from losing a valuable marketing data sync.

The most significant benefits of enabling the sync are:

  • Reducing your cost per action as a result of improved connectivity.

  • Reducing your cost per action as a result of increased event matching.

  • Improving measurement across your customer’s full journey.

  • Increased data control.

You can enable four synchronizations in the Conversion API sync between Datatrics and Meta. You can find them below, with the included data points listed:

PageView

Synchronization of page views:

  • Event ID

  • DateTime of the event

  • Page URL

  • User data

ViewContent

Synchronization of viewed items:

  • Event ID

  • DateTime of the event

  • Page URL

  • Item ID

  • User data

AddToCart

Synchronization of items added to the cart:

  • Event ID

  • DateTime of the event

  • Item IDs of products added to the cart

  • Quantities per product added to the cart

  • Prices of products added to the cart

  • Value (revenue) of the cart

  • Number of items added to the cart

  • User data

Purchase

Synchronization of conversions:

  • Event ID (this equals the conversion ID)

  • DateTime of the event

  • Item IDs of purchased products

  • Quantities of purchased products

  • Prices of purchased products

  • Order ID (this equals the conversion ID)

  • Number of purchased items

  • User data


Enabling the Conversion API synchronizations

Navigate to your (connected) Facebook Integration in Datatrics. Edit the connected integration you want to enable the synchronizations for. At the bottom of the next page, you have the option to toggle all synchronizations on and off individually:

After enabling one or more synchronizations, you can find the Conversion API events in the Meta Event Manager:

Events synchronized via the Datatrics’ Conversion API synchronization have the connection method: “Browser - Server”.


Deduplicating Meta Pixel and Datatrics’ Conversions API Events

If you connect website activity using both the Meta Pixel and Conversions API, Meta may receive the same events from the browser and Datatrics. If they know that the events are the same and therefore redundant, they can keep one and discard the rest. This is called deduplication.

Meta can deduplicate when event names (like AddToCart & Purchase) are the same, as well as the Event ID. Datatrics sends the Event IDs to Meta via the Conversion API synchronization, as seen in the event list above. It is important for you to also do this with the events you share with Meta via the Meta Pixel.

As an Event ID, we simply enter a Unix timestamp, which is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds. You can easily generate this number with JavaScript in the browser of a visitor with this simple code:

<script>Date().getTime();</script>

Deduplicating PageView events by adding an Event ID

On every page of your website, you initiate the basic Meta Pixel and track a pageview. This script normally looks something like this:

<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js’);

fbq('init', '{your-pixel-id-goes-here}’);
fbq('track', ‘PageView’);
</script>

As explained, we’d like to generate a timestamp and add it as an Event ID to the pageview. To do this, replace the last line (fbq('track', ‘PageView’);) of your own tracking code with the last two lines of the code below:

<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js’);

fbq('init', '{your-pixel-id-goes-here}’);
var FB_pageview_id = new Date().getTime();
fbq('track', ‘PageView’, {}, {eventID: FB_pageview_id});
</script>

So this piece of code:

fbq('track', ‘PageView’);

Becomes:

var FB_pageview_id = new Date().getTime();
fbq('track', ‘PageView’, {}, {eventID: FB_pageview_id});

Make sure you don’t copy the entire code in this article but change the one you’re already using, since it needs to include the correct Pixel ID.

Datatrics automatically reads the timestamp value in the FB_pageview_id variable, and adds it to the Conversion API PageView events.

Deduplicating ViewContent events by adding an Event ID (optional)

Altering this script is optional since duplicating doesn’t change ads' working. For example, Meta doesn’t allow you to target users who viewed three items of product group X, but it is good practice to deduplicate here.

The ViewContent script on your website will look something like this:

<script>
fbq('track', 'ViewContent', {
content_ids: {{Product ID Variable Here}},
content_type: 'product_group',
value: {{Product Price Variable Here}},
currency: 'EUR'
});
</script>

Again, you need to create a new variable with the Unix timestamp and use the variable as the eventID for the ViewContent event. Make sure you don’t copy this full script but alter your own with these two changes. Below you'll find an example script with the variable and eventID added:

<script>
var FB_viewcontent_id = new Date().getTime();
fbq('track', 'ViewContent', {
content_ids: {{Product ID Variable Here}},
content_type: 'product_group',
value: {{Product Price Variable Here}},
currency: 'EUR'
}, {eventID: FB_viewcontent_id});
</script>

This is the first piece of code added, to create a variable with the timestamp:

var FB_viewcontent_id = new Date().getTime();

This addition of code adds the eventID with the timestamp to the Meta Pixel event:

, {eventID: FB_viewcontent_id}

Datatrics automatically reads the timestamp value in the FB_viewcontent_id variable, and adds it to the Conversion API ViewContent events.

Deduplicating AddToCart events by adding an Event ID (optional)

Altering this script is optional since duplicating doesn’t change ads' working. For example, Meta doesn’t allow you to target users who have three items of product group X in their cart. But it is good practice to deduplicate here.

The AddToCart script on your website will look something like this:

<script>
fbq('track', 'AddToCart', {
content_ids: {{Product ID Variable Here}},
content_type: 'product_group’,
value: {{Product Price Variable Here}}
currency: 'EUR'
});
</script>

Again, you need to create a new variable with the Unix timestamp and use the variable as the eventID for the AddToCart event. Make sure you don’t copy this full script but alter your own with these two changes.

<script>
var FB_cart_id = new Date().getTime();
fbq('track', 'AddToCart', {
content_ids: {{Product ID Variable Here}},
content_type: 'product_group’,
value: {{Product Price Variable Here}}
currency: 'EUR'
}, {eventID: FB_cart_id});
</script>

These are the pieces of code added, they work the same as the code added to the ViewContent events:

var FB_cart_id = new Date().getTime();

, {eventID: FB_cart_id}

Datatrics automatically reads the timestamp value in the FB_cart_id variable, and adds it to the Conversion API AddToCart events.

Deduplicating Purchase events

It is not needed to deduplicate Purchase events by adding event IDs. Meta already recognizes the conversion/order ID and automatically deduplicates these events.

Did this answer your question?