Stape
Search
Try for free

How to set up Facebook Conversion API + events deduplication & hash user data

Updated
Jan 10, 2025
Published
Feb 11, 2021
Also available in

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

For several years now, 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 a cookie lifetime? It can be done either by implementing Facebook Conversion API or Facebook Conversion API Gateway.

This article will focus on Facebook Conversion API and show you how to set up Facebook conversion API via Google Tag Manager Server Container. You can get more information on Facebook Conversion API Gateway on our blog. By the way, check out Stape’s pre-configured templates for Meta CAPI. Now it is easier than ever to configure your setup: everything is done and all ready for you!

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 your server to the Facebook server.

Facebook CAPI has the same purpose as a Facebook pixel, but they have different technologies behind them. The policies and restrictions made FB CAPI more tailored to the needs of the modern tracking environment. As for Facebook Conversion API, it doesn’t involve the user’s browser for sending tracking information. Everything is done through the cloud server. It makes user 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 any Facebook event. Along with click id (fbclid) Facebook uses browser ID (fbp). Fbp and fbc cookies helps FB determine what kind of user landed on your site and who converted. 

FB can match users through other parameters such as email, phone number, first/last name, etc. The more user data you send to Facebook Conversion API, the higher the 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 helping with your Ad account, he will most likely call you and recommend setting up a Facebook conversion API. 

These are the most important reasons to consider implementing Facebook Conversion API. See the details below the infographic.

Benefits of Facebook Conversion API
  1. It can help you track users who installed AdBlocker, those using Safari (or any other browser with intelligent tracking prevention algorithms) or people opted out of FB tracking in iOS 14/15. It is possible because the requests are sent from a server, not from the user browser. And third-party cookies will not be blocked. With the help of user parameters you send together with FB CAPI events, FB will match events to users in their database. As a result, you will have more reliable data. 
  2. An extended cookie lifetime. With the help of Facebook conversion API, you will extend the Facebook cookie lifetime to 6 months. If you are not using FB conversion API, Safari will limit cookie lifetime to 1-7 days.
  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 sales.

Real-world example of Meta Conversions API value

By integrating the Conversions API alongside the Meta Pixel, Ray-Ban was able to improve its advertising results significantly. The combination led to a 36% greater reach on Facebook and Instagram compared to using the Meta Pixel alone.

ray ban case study: results

Additionally, the brand saw a 19% reduction in cost per 1,000 views and a 7% decrease in cost per conversion, demonstrating the effectiveness of the Conversions API in optimizing their campaigns and driving better performance. 

How to set up Facebook Conversion API?

We will use the server Google Tag Manager container to set up Facebook Conversion API. Inside the Google Tag Manager server and web containers, you will need to set up server-side GA4, or use Data Tag/Data Client and configure events for those actions that you want to track with Facebook conversion API. 

To sum up, you will need these things to configure Facebook conversion API:

  • Configured Google Tag Manager web container
  • Configured Google Tag manager Server Container
  • Server-side Google Analytics 4 or Data Tag/Data Client to deliver data to sGTM.

We have a blog post about the Tag Manager server container and what benefits it offers on our blog as well.

? This video shows how to set up Facebook Conversion API using Google Analytics 4.

Steps to set up Facebook Conversion API

2. Send data to the server GTM container. The two most popular sending data to sGTM are Google Analytics 4 and Data Tag/Data Client.

3. Go to your Google Tag Manager Server Container. Add Facebook Conversion API tag from the Template Gallery. 

Facebook Conversion API tag for server GTM

4. Create a Facebook Conversion API Tag inside sGTM. Choose Tag → Click new → Choose Facebook Tag that you’ve added in the previous step.

Add your Facebook pixel ID and Facebook API Access Token (we 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 find it.

Facebook conversion API inherit from client

5. You have 2 options for configuring our Facebook conversion API tag: 

  • 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 six. This is the preferred option, but requires more time and knowledge to implement it. Using this you can have full control event’s payload and do it according to best practices so that your web FB events and server FB events are identical.
  • Inherit from client. In this case, tag will match your GA4/Data event’s payload into Facebook standard events. If tag can’t match the GA event to the standard FB event, tag will send it as a custom event. Everything will be done automatically, you don’t need to set up FB events.

6. If you’ve selected the override option, you’ll have to use GA4 or Data Tag/Data Client events to trigger Facebook server events. The Facebook pageview event should trigger on a custom event page_view that was claimed by a specific client (for example, if you chose to use GA4 as a data source for the Server GTM, then you should use the page_view event when the client name equals GA4).

To set up other events, go to sGTM preview mode, make an action on your site that you want to track inside Facebook, and check the event name that GA4 or Data Tag sends to your Server Container.

On the screenshot below we want to set up a Facebook event ViewContent when someone opens the product page on our site. Make sure you also send with your GA4 event / Data tag from the web container the additional data you want to use for the server event. The example below also uses standard FB ecommerce parameters and user data.

To do that we created a new tag inside the Server container, set it to override, selected standard event ViewContent, added API Access Token, Facebook Pixel ID. We also added User Data. And made a new trigger event name equals view_item and Client Name equals GA4.

7. You can pass custom parameters using fields Server Event Data Override, User Data and Custom Data. You can 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. Our Facebook tag automatically hashes needed data.

You can also enable Event Enhancement to use HTTP only secure cookie (gtmeec) in order to enhance event data. When this feature is enabled tag will store user data in cookies and enrich events with user data when user data is not available. This way you can increase event match quality and as the results conversion attribution to campaigns. 

enable event enhancement in facebook capi tag

8. When you are done setting up all your Facebook events, open Google Tag Manager debug mode and test if 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 the Facebook events manager under the test events tab. For more tips on how to easily implement Facebook conversion API, check this article. 

test Facebook conversion API

9. Once you’ve set up and verified that Facebook conversion API works correctly, you need to remove FB browser tracking or set up event deduplication. Otherwise, your events will be duplicated. 

Pre-build templates and guides for your platform

With Stape, you can boost tracking accuracy and campaign results with server-side tagging.

Based on the platform that you use, you can set up tracking quickly and effectively with our custom templates. Follow the step-by-step guides to set up Meta CAPI using server GTM for:

Templates and guides for Wix, Shopware, Prestashop and more are coming soon. Let us know if you need a template for another CMS.

Event deduplication for Facebook pixel and conversions API events

Facebook recommends using both the Pixel and Conversions API to track events, but without event deduplication, duplicated data from the browser and server can skew results. Deduplication ensures only one event is kept by using unique event IDs shared between both sources. Proper setup requires generating and syncing these IDs across browser and server events, which can be tested in Facebook’s Events Manager.

Additionally, sending user data via the Conversions API improves match quality and event match scores, enhancing ad performance. User data should ideally come from a data layer and comply with privacy policies. Tools like Stape plugins simplify integrating user data for better Facebook campaign optimization.

Send user parameters using Facebook conversion API

To match users who visit your site with their database, Facebook uses User Data for Conversion API. 

FB requires to hash some parameters before sending it to Facebook, but you don't have to worry about that, Facebook's tag will hash out all the data automatically before it's sent.

The more user parameters you send to Facebook, the higher chances they will match a user and the higher event match score you’ll get.

Sending user parameters from your site to Facebook is a sensitive topic since you’ll share users’ data with 3rd party service. So before sending this data to FB, make sure it complies with the privacy policy. 

Ideally you should have the user data added to the data layer, but if this is not possible - try to collect it from the page using custom javascript code and send it along with the conversions or events you are interested in.

For example all Stape plugins for CMS (for Shopify, WordPress, Magento, BigCommerce) add a data layer which also contains user data.

So you can easily take it from data layer and add this data to Facebook events on a web container:

Then add the transfer of the required data to the server container (in payload GA4 or Data tag - depending on what you use):

And finally also add this data to your server-side Facebook event:

This way you will achieve better match quality of your Facebook events and as a result potentially improve the performance of your advertising campaigns as Facebook will better understand your audience and will better optimize your advertising campaigns.

Conclusion

That’s it. We hope you’ve successfully moved Facebook tracking to the server. Facebook Conversions API is a great tool to get a better understanding of who your customer is, see the full customer journey up until the conversion takes place, and feed more data about your users to Facebook machine learning algorithms.

Try Stape for all things server-sideright now!