How to Setup Facebook Conversion API

Facebook Pixel allows you to track what users are doing on your site, collect remarketing audiences and create lookalikes. If Facebook pixel is implemented correctly, it will also feed relevant information to FB machine learning algorithms. FB ML will use pixel data to show your ads to those people who are most likely to convert. 

For several years, we could track events on the site via javascript code, Facebook SDK inside apps or upload offline events. But how can you track users who installed Ad Blocker or track events outside the site? Or how can you extend cookie lifetime? This can be done by implementing Facebook conversion API. This article will show you how to set up Facebook conversion API via Google Tag Manager Server Container.

What is Facebook Conversion API?

Let’s take a look at what Facebook Conversion API is and how we can use it to improve event tracking, attribution and data collection on Facebook. Facebook Conversion API allows sending any events from a cloud server to the selected Facebook pixel. 

Facebook CAPI has the same purpose as a Facebook pixel, but they have different technologies behind. FB CAPI is more adapted to the needs of the modern tracking environment with its policies and restrictions. Facebook Conversion API doesn’t involve users browser for sending tracking information. Everything is done through the cloud server. It makes users data more secure and accurate.

If we take a closer look at the link of Facebook ads, we will see that at the end of almost any URL, FB appends its additional parameter fbclid. The pixel code on the landing page stores the value of this parameter in a cookie and then sends it along with the any Facebook event. Facebook uses fbclid to determine what kind of user landed on your site and who converted. 

FB can match users with the help of other parameters such as email, phone number, first/last name, etc. The more user’s data you send to Facebook Conversion API, the higher match rate you receive.

What are the main benefits of Facebook conversion API?

Facebook server-side tagging or Facebook conversion API was available on Facebook for a couple of years. But starting from 2021 FB started to push Conversion API harder. If you have a dedicated Facebook representative that helps manage your Ad account, most likely they called you/or will call you and say that they highly recommend setting up a Facebook conversion API. 

These are the most important reason why you should consider implementing Facebook Conversion API:

  1. It will help to track users who installed AdBlocker or those who are using Safari (or any other browser with intelligent tracking prevention algorithms). It will be possible because requests will be sent from a server, not from the user browser. 3rd party cookies won’t be blocked. As a result, you will have more reliable data. 
  2. Extended cookie lifetime. With the help of Facebook conversion API, you will extend facebook cookie lifetime to 6 months. If you are not using FB conversion API then Safari will limit cookie lifetime to 7 days or 1 day. 
  3. The Conversions API gives you more control over your data and a better understanding of the customer journey. 
  4. You can use Facebook Conversion API to track events that happen not on the site. (for example, phone calls or offline sale).

How to set up Facebook Conversion API?

We will use Google Tag Manager server container to set up Facebook Conversion API. Inside the Google Tag Manager server container, you will need to set up server-side tracking for Universal Analytics and configure UA events for those actions you want to track using Facebook conversion API. 

To sum up, you will need these things to set up Facebook conversion API. 

  • Configured Google Tag Manager web container 
  • Configured Google Tag manager Server Container 
  • Universal Analytics base code and events that are working form server.

In this article, I won’t cover creating and setting up Google Tag Manager Web container. I will start with setting up Google Tag Manager server container. In case you want to learn more what is Tag Manager server container and what benefits it can give you, check this article. Let’s get started.

  1. Follow all steps from this article to set up Google Tag Manager server container and start sending Universal Analytics and GA4 from the server
  2. Go to Google Tag Manager Server Container. Download our custom Facebook tag template from GitHub repository and import it into Google Tag Manager Server Container Tag Template.  Open Google Tag Manager Server Container -> Click Templates -> Tag Templates -> New. Then on the right upper corner, click on dots, and choose import.
Import Tag
Import GTM Server Tag

3. Create Facebook Conversion API Tag inside Google Tag Manager Server Container. Choose Tag -> Click new -> Choose Facebook Tag that you’ve imported on the previous step. Add your Facebook pixel ID and Facebook API Access Token (I recommend adding it as a variable since you will need these values for each Facebook event you want to track). If you don’t know your Facebook API Access Token this documentation will help you to find it. Configure trigger for Facebook Conversion API base tag: click new trigger -> custom trigger -> event name equals page_view

Filling the Test ID field, in your Facebook tag
trigger for facebook event

4. You have 2 options of configuring our Facebook conversion API tag: 

  • Inherit from GA client. In this case, we will match your Universal Analytics or GA4 events into Facebook standard events. If we won’t be able to match GA event into the standard FB event, we will record it as a custom event. Everything will be done automatically, you don’t need to set up FB events. If you chose this option than Facebook tag should fire on a trigger Client Name equals Universal Analytics (or GA4 if you are not using UA). In this case, FB tag will be triggered every time UA is triggered and will map all UA (or GA4) events into Facebook events manager.
  • Override. In this case, you’ll need to set up FB events manually. We will cover how to manually set up FB server events in step #5.

5. If you’ve selected override option, you’ll have to use Universal Analytics (or GA4) events to trigger Facebook server events. 

Facebook pageview event should trigger on a custom event page_view. To set up other events go to Google Tag Manager Server Container preview mode, make an action on your site that you want to track inside Facebook and check the event name that UA (or GA4) sends to your Server Container.

On the screenshot below I want to set up a Facebook event ViewContent when someone opens the product page on my site. To do that I created a new tag inside the Server container, set it to override, selected standard event ViewContent, added API Access Token, Facebook Pixel ID. And made a new trigger event name equals view_item.

facebook conversion API tag server container
Facebook conversion API tag standard event

6. You can pass custom parameters using fields Server Event Data Override and Custom Data. You can also send users data to increase the matching score on Facebook via field User Data, note that users’ information that you want to send to Facebook conversion API should be hashed. 

7. When you’ve done setting up all your Facebook events open Google Tag Manager debug mode and test that Facebook events work correctly. You can also go to your Facebook tag inside the server container and add Facebook test ID. You can find the test ID inside Facebook events manager under the test events tab. For more instructions on how to test Facebook conversion API check this article

facebook conversion api tag server container

8. Once you’ve set up and verified that Facebook conversion API works correctly you need to remove FB browser tracking, otherwise, your events will be duplicated.

Conclusion: That’s it. Hope you’ve successfully moved Facebook tracking to server. Facebook Conversions API is a great tool to get a better understanding who your customer is, see their full journey till they convert, and feed more data about your users to Facebook machine learning algorithms.