Setting up Facebook Conversion API via Google Tag Manager (GTM)
What is Facebook Conversion API and why do you need it?
Since the Apple IOS 14.5 update, many people have opted out of Facebook tracking.
As a result, your Facebook pixel cannot collect as much user data as it used to.
As the Facebook pixel collects fewer data about the users, the size of your custom audiences and lookalike audiences continues to shrink.
This has resulted in Facebook underreporting on conversions, events, ROAS and other results.
Many of the metrics used by Facebook Ad Manager for reporting purposes are no longer reliable.
To understand the full negative impact of the IOS 14.5+ updates on Facebook ads check out this article: The impact of Apple IOS 14.5 update on Facebook Ads
To mitigate some of the IOS updates’ negative impacts, Facebook recommends using the Facebook Conversion API (CAPI) along with your Facebook pixel.
“The Conversions API helps improve performance by sending data you already share with your pixel through an API connection, which is less impacted by ad blockers and browser connectivity issues. You can see how people interact with your business in ways the pixel alone can’t measure, like when purchases are initiated online but completed in a physical store.” – Source: Facebook
How to make your Facebook pixel more powerful?
You should do two things to make your Facebook pixel more powerful:
Get weekly practical tips on GA4 and/or BigQuery to accurately track and read your analytics data.
#1 Manually feed your pixel with more conversion data.
Create a custom audience based on your customer list. Upload as much data as possible via the list.
You can use your shopping cart or CRM to get customers’ data. Make sure to supply conversion value.
Do this once every week to keep your custom audience up to date. Use this audience to create new lookalike audiences and then use them in your campaigns.
These new lookalike audiences are likely to be far more accurate than the one you have right now.
#2 Start using Facebook conversion API to collect server-based events.
Such events feed your pixel in the absence of corresponding browser-based events.
Facebook will prioritize Conversion API over Facebook Pixel.
Currently, browser-based events are prioritized to feed your Facebook ad pixel, and server-based events are used only in the absence of corresponding browser-based events.
But starting next year (2023), Facebook will prioritize Conversion API over Facebook Pixel.
That means that server-based events will be prioritized to feed your Facebook ad pixel, and browser-based events will be used only in the absence of corresponding server-based events.
What is required to set up the Facebook Conversion API?
Unless you are running and maintaining your own servers (server-side tracking), you won’t be able to use the Facebook Conversion API via GTM (Google Tag Manager).
So the first step is to deploy server-side tracking on your website via GTM.
Check out this article for more details: Server Side Tracking for Google Analytics via GTM.
This article will teach you to set up your GTM Server Side container, Google Cloud Account, and the three virtual servers (as recommended by Google).
Once you have set up all this, then come back and follow the instructions below.
How Facebook Conversion API works with Server Side GTM Container?
#1: When the user interacts with a website, a server request is made, and at the same time, the GA4 web tag fires on the client-side GTM container.
#2: This GA4 web tag then transports the data captured from the website (events, pageviews, variables) and passes it to the GA4 web client in the server-side container.
#3: Now, the GA4 web client request is processed in the server-side container, and the related parameters are passed to the individual third-party server tags like Google Analytics 4 and Facebook.
#4: Once the required parameter is received in the Facebook Conversion API Tag, the data is finally dispatched to the Facebook server.
Now that you know how the Facebook tag works on the server-side container, let’s jump to configure it.
Configuration of the client-side GTM container
You need to configure the client-side GTM container to send values from the website to the GA4 client in the server-side container.
This is done by using the ‘transport_url‘ field. I have explained this in great detail here: How to send data from a website to a server-side container.
Since in this article we will talk about setting up the Facebook Conversion API tag using the basic GA4 tag, we will focus on the additional data parameters set up, as below.
Updating general parameters
You may want to send many data parameters to Facebook, e.g. ‘Event Name’, ‘Page location’, ‘Event ID’ ‘, Ecommerce variables’, etc. We will configure those parameters first.
Note: I assume you have already created the required event tags, triggers, and variables in the client-side GTM container.
If you need more information about how to create variables and use them, you can find it here.
- How to set up GA4 Custom Events via Google Tag Manager
- Google Tag Manager Variables and Triggers Tutorial
As an example, I am going to configure the purchase event, which we will send to Facebook
Follow the below steps, to begin with:
Step-1: Navigate to the GTM client-side container and click on ‘Tags’.
Step-2: Now click on ‘Purchase event’.
Step-3: As you can see from the below image, I have already configured the purchase event, and it is being sent to the server-side container.
Let’s add a general parameter like ‘Page location’ to this event.
Step-4: Under ‘Event parameters’, click on ‘Add Row’.
Step-5: Type ‘page_location’ under the parameter name and click on the + button beside the value text box.
Step-6: Now select the variable ‘Page URL’.
That’s it.
You are done! Just like we added the ‘page_location’ parameter, you can also add similar other parameters like:
- Event_ID: If you want to identify each event uniquely.
- Action_Source: Like website, application.
- Campaign_Details: If you are tracking any campaigns.
- Any other parameters useful to your organization that you would like to add.
Updating user data parameters
Along with general parameters, you may also like to pass a few user-related parameters to Facebook like ‘User Email Address’, ‘User City’, ‘User Phone Number’, etc.
You may think this is PII (personally identifiable information), so how can we pass this in the GA4 tag?
But hold on, we will pass it to our server-side container and not to GA4 directly. We will filter out such variables in later steps.
Step-7: To add user-related data parameters, click on ‘User Properties‘ and then click on ‘Add Row’.
Step-8: Now, type the parameter field you want to add.
For example, I am adding ‘user_data.email_address’ and then clicking on the + button to select the variable.
Step-9: Select the ‘User email’ variable from the list.
And that’s it. Similarly, you can also add the following user-related variables.
- user_data.phone_number
- user_data.address.first_name
- user_data.address.last_name
- user_data.address.city
- user_data.address.region
- user_data.address.postal_code
- user_data.address.country
Your final configuration may look like below
Updating custom data parameters
Along with general and user-related parameters, you can also pass custom data parameters such as ‘transaction_id’ ‘value’, ‘currency’, ‘ecommerce variables’, etc.
You can also pass facebook specific parameters like
- x-fb-ud-ge: Hashed user gender
- x-fb-ud-db: Hashed user date of birth
- x-fb-ud-external_id: External ID, e.g. advertiser loyalty ID with recommended hashing
- x-fb-ud-subscription_id: Subscription ID, no hashing needed
- x-fb-ck-fbp: Facebook cookies
Once you have added all the required parameters, the configuration at the client-side GTM container is done, and you can save the tag.
Configuring server-side GA4 Tag (exclusion of Facebook parameters)
Since we do not want to pass any PII data to the GA4 account, we need to exclude it from the GA4 tag in the server-side container.
Follow the below steps to know more:
Step-1: Navigate to your server-side container, click on ‘Tags’, and then click on the GA4 configuration tag.
Step-2: In the tag configuration, click on ‘Events Parameters‘ and then click on ‘Add Row’ under ‘Parameters to Exclude’.
Step-3: Now add all parameters that contain user-related PII data and Facebook-specific parameters.
Note: If you don’t remember which parameters to exclude, you can put the server-side container in preview mode and generate a specific event. You will get all the information about the parameter name which needs to be excluded, like in the below image.
Step-4: Save the tag, and you are done with configuring the GA4 server-side tag.
Configuring the Facebook Conversion API Tag
Now let’s set up the actual Facebook server-side tag. But, before you proceed to the set-up, let me tell you the requirements.
We will use the Facebook Conversion API Tag template here and need the parameters below.
- Facebook Pixel ID: To which we will send data. You can get this at https://www.facebook.com/events_manager
- API Access Token: So that we can interact with the API.
Read more about API Access Token here: https://developers.facebook.com/docs/marketing-api/conversions-api/get-started#access-token
- Test Event Code: Optional
Follow the below steps to continue.
Step-1: Navigate to your server-side container and click on ‘Templates’.
Step-2: Click on ‘Search Gallery’ under ‘Tag Templates’.
Step-3: Select ‘Facebook Conversion API Tag’ and add it to a workspace.
Step-4: Navigate to the ‘Tags’ tab and click on ‘New’.
Step-5: Give your tag a name like ‘Facebook Conversions API Tag’ and click on ‘Tag Configuration’.
Step-6: Now select the tag type as ‘Facebook Conversions API Tag’.
Step-7: Now add your Facebook Pixel ID and API Access Token code. You can type ‘Test1234’ in the ‘Test Event Code’ and select ‘Action Source’ as a website.
Step-8: Click on ‘Triggering’ to create a trigger for our tag.
Step-9: Now apply the below configuration to your trigger:
- Trigger fires on ‘Some events’
- Condition: Client Name ‘equals’ GA4.
Step-10: Save the tag, and you are done.
Preview and debug
Follow the below steps to preview and debug.
Step-1: Navigate to the server-side GTM container and click on ‘Preview’.
Step-2: A new window will open like the one below with a blank summary.
Step-3: Go to your website and perform the purchase event.
Once you do that, you should see that the purchase event is fired, like in the image below, and the Facebook Conversion API Tag has also fired.
Step-4: Now click on the ‘Request’ tab, and you should see the outgoing ‘HTTPS’ request to ‘https://graph.facebook.com/) with status code ‘200’.
If you click on the ‘Post-200’ status code, you will get more details like below.
Now navigate to the Facebook Event testing tool and click on ‘Test Events’. You should be able to see the purchase event just like below.
Congratulations!
You have successfully set up the Facebook Conversion API Tag using the server-side GTM container.
Note: Like this purchase event, you can send any event from your website to Facebook using the server-side GA4 client and the Facebook Conversion API Tag. Just keep in mind to exclude the PII-related parameters from the GA4 server-side tag and to hash the necessary parameters.
Other Articles on Server Side Tracking
- Server Side Tracking for Google Analytics via GTM
- How to Create Server Side Container for Google Tag Manager
- How to Configure DNS for GTM Server Side Container
- How to send data from Website to Server Side Container
- How to set up GA4 via GTM Server Side Tagging
- Google Tag Manager Tutorial
- How to set up Data Layer for GTM Server Side Container
- GTM Server Side Preview Mode – Tutorial
Frequently asked questions about GTM server-side tagging for Facebook tutorial.
Can you set up Facebook Events using a server-side GTM container?
Yes, server-side tagging is a new way to use Google Tag Manager (aka GTM) in Google’s cloud environment. Using the Facebook Conversion API Tag, you can use a GA4 (in a server-side environment) client to send events to Facebook.
You can use the below steps:
1. Configure client-side GTM container
2. Update general parameters
3. Update user data parameters
4. Update custom data parameters
5. Configure server-side GA4 Tag (exclusion of Facebook parameters)
6. Test the set-up
7. Configure Facebook Conversion API Tag
8. Preview and debug
What is the Facebook Conversion API?
The Facebook Conversion API allows you to send website events from the server-side GTM container to the Facebook Ads Manager or Events Manager.
The conversion API is linked to the pixel and processes the event request like normal browser events. You can use these event details for reporting and optimization.
What is the Facebook API Access Token?
To use Facebook Conversion API, you need an access token. The access token is passed as a parameter in each API call and allows the conversion API to process the request and send it to Facebook.
What is Facebook Conversion API and why do you need it?
Since the Apple IOS 14.5 update, many people have opted out of Facebook tracking.
As a result, your Facebook pixel cannot collect as much user data as it used to.
As the Facebook pixel collects fewer data about the users, the size of your custom audiences and lookalike audiences continues to shrink.
This has resulted in Facebook underreporting on conversions, events, ROAS and other results.
Many of the metrics used by Facebook Ad Manager for reporting purposes are no longer reliable.
To understand the full negative impact of the IOS 14.5+ updates on Facebook ads check out this article: The impact of Apple IOS 14.5 update on Facebook Ads
To mitigate some of the IOS updates’ negative impacts, Facebook recommends using the Facebook Conversion API (CAPI) along with your Facebook pixel.
“The Conversions API helps improve performance by sending data you already share with your pixel through an API connection, which is less impacted by ad blockers and browser connectivity issues. You can see how people interact with your business in ways the pixel alone can’t measure, like when purchases are initiated online but completed in a physical store.” – Source: Facebook
How to make your Facebook pixel more powerful?
You should do two things to make your Facebook pixel more powerful:
#1 Manually feed your pixel with more conversion data.
Create a custom audience based on your customer list. Upload as much data as possible via the list.
You can use your shopping cart or CRM to get customers’ data. Make sure to supply conversion value.
Do this once every week to keep your custom audience up to date. Use this audience to create new lookalike audiences and then use them in your campaigns.
These new lookalike audiences are likely to be far more accurate than the one you have right now.
#2 Start using Facebook conversion API to collect server-based events.
Such events feed your pixel in the absence of corresponding browser-based events.
Facebook will prioritize Conversion API over Facebook Pixel.
Currently, browser-based events are prioritized to feed your Facebook ad pixel, and server-based events are used only in the absence of corresponding browser-based events.
But starting next year (2023), Facebook will prioritize Conversion API over Facebook Pixel.
That means that server-based events will be prioritized to feed your Facebook ad pixel, and browser-based events will be used only in the absence of corresponding server-based events.
What is required to set up the Facebook Conversion API?
Unless you are running and maintaining your own servers (server-side tracking), you won’t be able to use the Facebook Conversion API via GTM (Google Tag Manager).
So the first step is to deploy server-side tracking on your website via GTM.
Check out this article for more details: Server Side Tracking for Google Analytics via GTM.
This article will teach you to set up your GTM Server Side container, Google Cloud Account, and the three virtual servers (as recommended by Google).
Once you have set up all this, then come back and follow the instructions below.
How Facebook Conversion API works with Server Side GTM Container?
#1: When the user interacts with a website, a server request is made, and at the same time, the GA4 web tag fires on the client-side GTM container.
#2: This GA4 web tag then transports the data captured from the website (events, pageviews, variables) and passes it to the GA4 web client in the server-side container.
#3: Now, the GA4 web client request is processed in the server-side container, and the related parameters are passed to the individual third-party server tags like Google Analytics 4 and Facebook.
#4: Once the required parameter is received in the Facebook Conversion API Tag, the data is finally dispatched to the Facebook server.
Now that you know how the Facebook tag works on the server-side container, let’s jump to configure it.
Configuration of the client-side GTM container
You need to configure the client-side GTM container to send values from the website to the GA4 client in the server-side container.
This is done by using the ‘transport_url‘ field. I have explained this in great detail here: How to send data from a website to a server-side container.
Since in this article we will talk about setting up the Facebook Conversion API tag using the basic GA4 tag, we will focus on the additional data parameters set up, as below.
Updating general parameters
You may want to send many data parameters to Facebook, e.g. ‘Event Name’, ‘Page location’, ‘Event ID’ ‘, Ecommerce variables’, etc. We will configure those parameters first.
Note: I assume you have already created the required event tags, triggers, and variables in the client-side GTM container.
If you need more information about how to create variables and use them, you can find it here.
- How to set up GA4 Custom Events via Google Tag Manager
- Google Tag Manager Variables and Triggers Tutorial
As an example, I am going to configure the purchase event, which we will send to Facebook
Follow the below steps, to begin with:
Step-1: Navigate to the GTM client-side container and click on ‘Tags’.
Step-2: Now click on ‘Purchase event’.
Step-3: As you can see from the below image, I have already configured the purchase event, and it is being sent to the server-side container.
Let’s add a general parameter like ‘Page location’ to this event.
Step-4: Under ‘Event parameters’, click on ‘Add Row’.
Step-5: Type ‘page_location’ under the parameter name and click on the + button beside the value text box.
Step-6: Now select the variable ‘Page URL’.
That’s it.
You are done! Just like we added the ‘page_location’ parameter, you can also add similar other parameters like:
- Event_ID: If you want to identify each event uniquely.
- Action_Source: Like website, application.
- Campaign_Details: If you are tracking any campaigns.
- Any other parameters useful to your organization that you would like to add.
Updating user data parameters
Along with general parameters, you may also like to pass a few user-related parameters to Facebook like ‘User Email Address’, ‘User City’, ‘User Phone Number’, etc.
You may think this is PII (personally identifiable information), so how can we pass this in the GA4 tag?
But hold on, we will pass it to our server-side container and not to GA4 directly. We will filter out such variables in later steps.
Step-7: To add user-related data parameters, click on ‘User Properties‘ and then click on ‘Add Row’.
Step-8: Now, type the parameter field you want to add.
For example, I am adding ‘user_data.email_address’ and then clicking on the + button to select the variable.
Step-9: Select the ‘User email’ variable from the list.
And that’s it. Similarly, you can also add the following user-related variables.
- user_data.phone_number
- user_data.address.first_name
- user_data.address.last_name
- user_data.address.city
- user_data.address.region
- user_data.address.postal_code
- user_data.address.country
Your final configuration may look like below
Updating custom data parameters
Along with general and user-related parameters, you can also pass custom data parameters such as ‘transaction_id’ ‘value’, ‘currency’, ‘ecommerce variables’, etc.
You can also pass facebook specific parameters like
- x-fb-ud-ge: Hashed user gender
- x-fb-ud-db: Hashed user date of birth
- x-fb-ud-external_id: External ID, e.g. advertiser loyalty ID with recommended hashing
- x-fb-ud-subscription_id: Subscription ID, no hashing needed
- x-fb-ck-fbp: Facebook cookies
Once you have added all the required parameters, the configuration at the client-side GTM container is done, and you can save the tag.
Configuring server-side GA4 Tag (exclusion of Facebook parameters)
Since we do not want to pass any PII data to the GA4 account, we need to exclude it from the GA4 tag in the server-side container.
Follow the below steps to know more:
Step-1: Navigate to your server-side container, click on ‘Tags’, and then click on the GA4 configuration tag.
Step-2: In the tag configuration, click on ‘Events Parameters‘ and then click on ‘Add Row’ under ‘Parameters to Exclude’.
Step-3: Now add all parameters that contain user-related PII data and Facebook-specific parameters.
Note: If you don’t remember which parameters to exclude, you can put the server-side container in preview mode and generate a specific event. You will get all the information about the parameter name which needs to be excluded, like in the below image.
Step-4: Save the tag, and you are done with configuring the GA4 server-side tag.
Configuring the Facebook Conversion API Tag
Now let’s set up the actual Facebook server-side tag. But, before you proceed to the set-up, let me tell you the requirements.
We will use the Facebook Conversion API Tag template here and need the parameters below.
- Facebook Pixel ID: To which we will send data. You can get this at https://www.facebook.com/events_manager
- API Access Token: So that we can interact with the API.
Read more about API Access Token here: https://developers.facebook.com/docs/marketing-api/conversions-api/get-started#access-token - Test Event Code: Optional
Follow the below steps to continue.
Step-1: Navigate to your server-side container and click on ‘Templates’.
Step-2: Click on ‘Search Gallery’ under ‘Tag Templates’.
Step-3: Select ‘Facebook Conversion API Tag’ and add it to a workspace.
Step-4: Navigate to the ‘Tags’ tab and click on ‘New’.
Step-5: Give your tag a name like ‘Facebook Conversions API Tag’ and click on ‘Tag Configuration’.
Step-6: Now select the tag type as ‘Facebook Conversions API Tag’.
Step-7: Now add your Facebook Pixel ID and API Access Token code. You can type ‘Test1234’ in the ‘Test Event Code’ and select ‘Action Source’ as a website.
Step-8: Click on ‘Triggering’ to create a trigger for our tag.
Step-9: Now apply the below configuration to your trigger:
- Trigger fires on ‘Some events’
- Condition: Client Name ‘equals’ GA4.
Step-10: Save the tag, and you are done.
Preview and debug
Follow the below steps to preview and debug.
Step-1: Navigate to the server-side GTM container and click on ‘Preview’.
Step-2: A new window will open like the one below with a blank summary.
Step-3: Go to your website and perform the purchase event.
Once you do that, you should see that the purchase event is fired, like in the image below, and the Facebook Conversion API Tag has also fired.
Step-4: Now click on the ‘Request’ tab, and you should see the outgoing ‘HTTPS’ request to ‘https://graph.facebook.com/) with status code ‘200’.
If you click on the ‘Post-200’ status code, you will get more details like below.
Now navigate to the Facebook Event testing tool and click on ‘Test Events’. You should be able to see the purchase event just like below.
Congratulations!
You have successfully set up the Facebook Conversion API Tag using the server-side GTM container.
Note: Like this purchase event, you can send any event from your website to Facebook using the server-side GA4 client and the Facebook Conversion API Tag. Just keep in mind to exclude the PII-related parameters from the GA4 server-side tag and to hash the necessary parameters.
Other Articles on Server Side Tracking
- Server Side Tracking for Google Analytics via GTM
- How to Create Server Side Container for Google Tag Manager
- How to Configure DNS for GTM Server Side Container
- How to send data from Website to Server Side Container
- How to set up GA4 via GTM Server Side Tagging
- Google Tag Manager Tutorial
- How to set up Data Layer for GTM Server Side Container
- GTM Server Side Preview Mode – Tutorial
Frequently asked questions about GTM server-side tagging for Facebook tutorial.
Can you set up Facebook Events using a server-side GTM container?
Yes, server-side tagging is a new way to use Google Tag Manager (aka GTM) in Google’s cloud environment. Using the Facebook Conversion API Tag, you can use a GA4 (in a server-side environment) client to send events to Facebook.
You can use the below steps:
1. Configure client-side GTM container
2. Update general parameters
3. Update user data parameters
4. Update custom data parameters
5. Configure server-side GA4 Tag (exclusion of Facebook parameters)
6. Test the set-up
7. Configure Facebook Conversion API Tag
8. Preview and debug
What is the Facebook Conversion API?
The Facebook Conversion API allows you to send website events from the server-side GTM container to the Facebook Ads Manager or Events Manager.
The conversion API is linked to the pixel and processes the event request like normal browser events. You can use these event details for reporting and optimization.
What is the Facebook API Access Token?
To use Facebook Conversion API, you need an access token. The access token is passed as a parameter in each API call and allows the conversion API to process the request and send it to Facebook.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.