Stape

How to set up Facebook event deduplication in Google Tag Manager

Author
Stape
Published
March 12, 2021
Also available in

Using Facebook server-side tracking (Facebook Conversions API) is getting more popular due to its ability to prevent tracking pixel blocking by ITPs and AdBlockers. Another massive benefit of Facebook conversion API is that it increases FB cookie lifetime. If you haven’t yet implemented FB Conversions API on your site, follow this guide. 

In this article, I will describe how to set up Facebook events deduplication if you are using both browser and server tracking methods for your site.

Why do you need to set up Facebook event deduplication?Copy link to this section

The Facebook pixel and Conversions API lets you share standard and custom events with FB so that you can measure and optimize ad performance. The pixel enables you to share web events from a web browser, while the Conversions API lets you share web events directly from the cloud server. 

Both Facebook pixel and Facebook conversion API let you send events. The difference is that pixel sends events from the browser, and CAPI sends events from the server. If you tell Facebook that the browser and server method send identical events, they will accept one and discard another.

There are several ways of setting up Facebook tracking, including the following:

  1. Using solely browser (pixel) method. It is not recommended by FB because of user tracking restrictions.
  2. Using only server tracking. The main benefit of having tracking only on the server is that FB pixel will not overload your website. Your site will load faster, and it will lead to a better user experience.
  3. Combine browser and server tracking. Here you have several options:
  • Send some events from the browser and another from server. For example, Shopify native FB Conversion API integration will send all FB events through the browser and purchase events from the Server. In this case, you do not need the deduplication.
  • Send all events from the browser and server.


If you decide to use both browser and server events tracking for all your events, in this case, you will need to set up event deduplication. With Facebook event deduplication, FB will receive all your events, understand that events are identical, clean some of them, and keep others. If you combine the browser and server method but do not set up event deduplication, your data will not be correct because all the events will be tracked twice.

Facebook requires sending two event parameters for event deduplication: its event name and event ID. You already sending the event name with the existing setup. This article will cover how to configure Facebook event ID inside the Google Tag Manager container.

How does Facebook event deduplication work?Copy link to this section

Facebook has two way of identifying duplicated events that were sent from browser and server:

1. Event ID and event name. 

Facebook recommends this method, and we will cover it in our how-to. For this method, you must use event ID for all events you send via pixel and CAPI. FB will deduplicate Facebook Pixels and Conversion API events with identical event names and event IDs. Facebook gives more credit to the browser event, and if they see similar events and come within 5 minutes difference, they will keep browser events and clean server events. 

2. FBP or External ID

This method exists but is not recommended by Facebook. In this case, you will need to send the event name, fbp, and/or external_id for all your browser and server events. Facebook compares all these parameters and identifies if they already have a browser event with these parameters, and if they do, they discard server events. FB does not recommend using these events since they can identify deduplication only if the browser event was sent first. It means that if you send a server event first, events will be duplicated. 

Facebook also can merge events. For example, if you send some enriched data from the server, you can add the missing data to the browser event. That is not a default feature. To enable it, you should contact a Facebook representative.

How to set up Facebook event deduplication via Google Tag Manager?Copy link to this section

We created a custom Google Tag Manager variable that generates unique event ID you can use it in  your web and server Facebook events. It will allow you to track users both from browser and server and deduplicate events. This method will work if your Facebook pixel is set up inside the Google Tag Manager Web Container and if Facebook conversion API is set up via Google Tag Manager Server Container.

1. You need to have Facebook conversion API setup via Google Tag Manager server container. Please follow this how-to if it’s not yet set up on your site. 

2. Click on this link to download a custom variable that sends a unique event ID or add it using Template Gallery.

3. If you downloaded variable template from GitHub -> Go to your Google Tag Manager Web Container and import the variable that you’ve just downloaded. Click Templates -> New (inside the Variable Templates) -> click on the three dots on the top right corner -> import -> select variable -> When done, click Save. Go to the Variables tab inside the Web container -> Under User-Defined Variables click New -> create a Unique event ID variable using the template you’ve imported.  

import data client template 
import data client tag to the web gtm

4. Add this variable to all Facebook tags you have inside the Web Container. 

If you are using FB tag template:

Open Facebook Tag -> Click More Settings -> Add variable to the fields Event ID -> Click Save. 

add event id to the Facebook tag

If you’ve added FB tags via custom HTML:

Open Facebook Tag -> add event ID parameter to the Facebook event -> Click Save. 

eventID: ‘{{Event ID}}’

add event id to the Facebook pixel
!

Follow the next steps if you use Universal Analytics. If you use GA4, please scroll down to step 9

5. We will configure a setup that will pass the same event ID to the Google Tag Manager Server container in this step. Since our Facebook server tag works based on the Google Analytics events, we will add Facebook events ID to Google Analytics tags inside the Web container. In this example, I will send an Event ID inside the Google Analytics Custom Dimension. You can send it via other fields. 

Open Universal Analytics tag inside the Web container -> Click More settings -> Custom Dimension -> Add index and select Event ID variable.

add event ID to universal analytics 

Add Facebook event ID to all GA custom dimensions (or other parameters you’ve selected) that you want to track inside the server container. 

Once you’ve done it, go to the preview mode and verify that everything works correctly. Then, Publish the updates.

test event ID in the universal analytics 
test event ID Facebook

6. Go to your Google Tag Manager Server Container -> Click Variables -> New Variable -> select variable type Query Parameter -> Parameter name cd1 (in my case because the index of the custom dimension that I’ve created in the web container is 1) -> Click Save.

7. Go to the Preview mode and check that the Google Tag Manager Server container sees the variable you’ve created. 

add event ID as a custom dimension
test event ID as a custom dimension

8. Open Facebook Tag inside the Google Tag Manager Server Container -> Click Server Event Data Override -> in the Property Name select Event ID -> in the Property Value select variable that you’ve created in the server Container.

Add Event ID Variable to all Facebook tags inside the server container. Once the tag goes to the server preview mode, that test changes. 

add event ID to Facebook conversion API
test event ID in Server GTM
!

The next steps are for setup event id thru GA4. If you use Universal Analytics, please proceed to step 13

9.  Create or use your existing GA4 event tag inside the Web container -> Event Parameters -> Add event_id as Parameter name and select Event ID variable as a value. Also, check what trigger you use for the GA4 event. You always should use the same trigger for Facebook tag and GA4 for identical events. For example, GA4 and FB add to cart tags should use the same trigger, in this case the vent ID will be identical. Add Facebook event ID to all GA4 event tags that you want to track inside the server container.

To reduce chances of the same event ID sent for multiple properties, you can add event name before the event ID variable. (similar to the screenshot bellow).👇

add Facebook event id to google analytics 4 tag

Once you’ve done it, go to the preview mode and verify that everything works correctly. Then, Publish the updates.

10. Go to your Google Tag Manager Server Container -> Click Variables -> New Variable -> select variable type Event Data -> Key path event_id (in my case because the parameter name that I’ve created in the web container is event_id) -> Click Save.

create event data variable Server GTM

11. Open Facebook Tag inside the Google Tag Manager Server Container -> Click Server Event Data Override -> in the Property Name select Event ID -> in the Property Value select variable that you’ve created in the server Container.

Add Event ID Variable to all Facebook tags inside the server container.

add event id to Facebook conversion api tag

12. Go to the preview mode and check that the event_id variable you created on the web container is the same as what you send to Facebook

.

test event ID Facebook CAPI
test event ID Facebook CAPI in GA4

13. In this step, we will verify that Facebook event deduplication worked. Go to the Test Event tool inside your Facebook Business Manager -> Make sure that you’ve added test ID to the Facebook tag inside the Google Tag Manager Server container -> Check that Facebook shows server and browser events in the testing tool and one of the events was deduplicated. 

Make sure you remove test ID from Facebook conversion API tags after testing or set up a Test ID as a look-up table variable that works when debug mode is true. Otherwise, you might see a deduplication error in the FB events manager.

Facebook event testing tool

14. Don’t forget to publish your changes. 

Conclusion:Copy link to this section

Facebook conversion API is an excellent solution if you want to track your site users more accurately, bypass ad blockers and ITPs, and extend cookie lifetime.  With a combined server and browser method, you will still run Facebook pixels in the browser, making your site heavier. Using this method, you can be 100% sure that you did not miss any users or events on your site. 

If you have some questions or comments about implementing Facebook event deduplication, please let me know in the comments.

Tagged with:Facebook

Host your GTM server at Stape

By signing up you agree to Stape’s Terms of Use and Privacy Notice