The 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. You can configure a server that you set up on the Google Cloud Platform (GCP) or any other cloud provider to send key web and offline event data through the Conversions API. With this setup, after you configure the Google Analytics 4 (GA4) Web Tag, you can send that data to your own server hosted on Google Cloud Platform (GCP) and eventually to Meta through the Conversions API.
The Conversions API Tag is written and maintained by Meta based on the Google Custom Tag Template. Please reach out to Google with any questions you have about setting up Google products or Google’s developer documentation.
This document outlines the following:
Before proceeding with this integration, we recommend that you:
If your system uses a version older than GA4, you’ll need to upgrade your existing tag manager setup to use GA4 before proceeding with this integration.
This allows you to manage and store tracking and marketing tags. It also helps you track how users interact with your website.
You will need to configure a server container and a web container:
Go to Google Tag Manager by visiting the Google Tag Manager website.
If you already have an account, select it. Otherwise, create a new GTM account.
Click on Create Container
Name your container and select "Server" as the target platform
Click Create
Setting up a server container requires configuring a tagging server. The default GCP deployment can be completed when setting up the server container. Refer to the following guidance. For any other cloud provider (for example, AWS or Microsoft Azure), refer to the manual server setup guide.
Configure web and server containers
graph.facebook.com
.Configure your web container to send your website data to the created tagging server. Learn more about how to configure the Google Analytics: GA4 Configuration Tag.
transport_url
You can configure additional fields for any other parameters you want to send for all events.
first_party_collection
true
If you have an existing GA4 Configuration already set up, you can either amend it, or create an additional Configuration tag for Server-Side GTM.
If you are setting up Server-Side GTM for the first time, adding the Server Container URL will start sending all your traffic to the Server Container. If you want to continue sending data to GA4, you’ll need to add the GA4 Server-Side tag in your Server Container, ensuring it fires on all events. You may need to create additional GA4 Event tags or modify existing ones to ensure a complete mapping to Meta Pixel events.
If you have set up a custom domain, and your GTM tagging server domain is first-party, the Meta Browser ID and Meta Click ID are sent automatically.
If you’re using the default domain provided, or notice that the Browser ID and Click ID fields are not being sent in Events Manager, you can configure these as follows:
_fbp
_fbc
Create a Data Layer Variable for each of the GTM common event schema's user_data parameters. Learn more about setting up data-layer variables. For example, to pass an email address to Server-Side GTM, create a variable, (for example, user_data_email_address
) that can be mapped to the Data Layer Variable Name, eventModel.user_data.email_address
.
If you’re not using the data layer, configure variables for each parameter as indicated below to use instead. The list below shows all the mappings for Meta and GTM user_data parameters and their general priority in helping increase Event Match Quality. To get the most out of Meta ads, we recommend using the Conversions API best practices when you set up an integration. If you have already set up the Conversions API, we recommend considering these best practices to improve your existing setup. The Conversions API best practices may help improve your ad performance by lowering your cost per action.
Conversions API Meta Parameter | GA4 Field Name | GTM Data Layer Variable Name | Priority |
---|---|---|---|
| user_data.email_address | eventModel.user_data.email_address | High |
Click ID
| x-fb-ck-fbc | N/A | High |
Facebook Login ID
| user_data.fb_login_id | N/A | Medium |
Date of Birth
| x-fb-ud-db | N/A | Medium |
Country
| user_data.address.country | eventModel.user_data.address.country | Medium |
Phone Number
| user_data.phone_number | eventModel.user_data.phone_number | Medium |
External ID
| x-fb-ud-external_id | N/A | Medium |
Browser ID
| x-fb-ck-fbp | N/A | Medium |
State
| user_data.address.region | eventModel.user_data.address.region | Medium |
Gender
| x-fb-ud-ge | N/A | Medium |
First Name
| user_data.address.first_name | eventModel.user_data.address.first_name | Low |
Last Name
| user_data.address.last_name | eventModel.user_data.address.last_name | Low |
City
| user_data.address.city | eventModel.user_data.address.city | Low |
Zip Code
| user_data.address.postal_code | eventModel.user_data.address.postal_code | Low |
Configure your web container to send your website data to the created tagging server to add the Google Analytics. Learn more about how to configure the Google Analytics: GA4 Configuration Tag.
Add the Google Analytics: GA4 Event Tag to your Workspace from the Template Gallery:
Meta Standard Event Name | Google Analytics Event Name |
---|---|
AddPaymentInfo | add_payment_info |
AddToCart | add_to_cart |
AddToWishlist | add_to_wishlist |
PageView | gtm.dom |
PageView | page_view |
Purchase | purchase |
Search | search |
InitiateCheckout | begin_checkout |
Lead | generate_lead |
ViewContent | view_item |
CompleteRegistration | sign_up |
In the Event Parameters section:
Every GTM server-side container comes with a default GA4 Client for listening to events configured from their GA4 Web Tag. The GA4 Client listens to the /g/collect route on your tagging server URL and sends the eventModel to the downstream tag. If the default GA4 Client is already installed in your server container under the Clients section, you can move to Step 4.
To send the event to the Conversions API, you need to install the Meta Conversions API Tag from the Template Gallery. The tag template is called Conversions API Tag by facebookincubator. This tag can be set up to be triggered on events received by the GA4 Client in the previous step and sent to the Conversions API. To install the Meta Conversions API Tag, you will need to have a Pixel ID, access token and specify the action source as “website”. By using the Conversions API, you agree that the action_source
parameter is accurate to the best of your knowledge.
We recommend using Google Tag Manager's preview mode to test integrations before publishing changes. Both web containers and server containers have preview modes, and you can run both of them at the same time.
If you change your setup whilst running preview mode, make sure to restart preview mode to ensure the changes are reflected whilst testing.
You can verify that your server events are received as intended by using the Test Events feature in Events Manager. To find the tool, go to Events Manager > Data Sources > Your Pixel > Test Events.
The Test Events tool generates a test ID. Send the test ID as the test_event_code
parameter in your Conversions API tag to start seeing event activity appear in the Test Events window. Be sure to remove this before publishing any changes.
The test events tool allows you to see if events are being received and deduplicated correctly. If you don’t see events show up after a minute or two, check the GTM Server-side debugger to ensure the request went through:
https://graph.facebook.com
. Review the Response Body at the bottom of the request details to see what the error was, and update your integration as appropriate. Remember to restart preview mode after making any changes.Once events are showing, verify that the Event IDs for each event are being sent correctly, and that all expected match keys and custom data parameters are showing correctly. The test event tool will show you if events are being deduplicated correctly. If the Event IDs are different, ensure the GA4 and Meta Pixel tags are firing on the same trigger, and review your Event ID variable implementation.
We recommend that you use a redundant event setup and share the same events from both the Conversions API and your Meta Pixel. Ensure that both events use the identical event_name
and that either event_id
or a combination of external_id
and fbp
are included.
This will help Meta to deduplicate events and reduce double reporting of identical events. Learn more about deduplication, when it’s necessary and how to set it up. The external_id and fbp are alternative solutions for deduplication and help also to improve the quality of setup. We recommend including these three parameters whenever possible.
GTM has multiple ways to set up a parameter with the same value across a browser tag and a server tag. One way is to use the same GA4 event as the trigger to fire your Meta Pixel tag and server event. To achieve this:
event_id
in both tags:
x-fb-event_id
) from the gtag event. Generate a unique ID (per event) on the website using a Javascript method (or using Google Tag Manager custom Javascript variable) and set the value in the event as:gtag('event', 'purchase', { 'x-fb-event_id': generateEventId(), ...:... });You can create a variable that points to the custom Javascript shown above. Whenever the var is referred, the below Javascript is loaded in line:
function() { var gtmData = window.google_tag_manager[{{Container ID}}].dataLayer.get('gtm'); return gtmData.start + '.' + gtmData.uniqueEventId; }
event_id
. You can do this by creating a new Data Layer Variable, for example, FBEventIdVar, with the Data Layer Variable Name as eventModel.event_id
.event_id
from a variable.fbq('track', Purchase, {..}, {eventID: FBEventIDVar });Configure the GA4 Event to send an extra parameter, named
event_id
, set to the FBEventIdVar
variable.
To send custom data, use the mappings below in your GA4 Event tags:
Meta Parameter Name | GA4 Parameter Name |
---|---|
value | value |
currency | currency |
search_string | search_term |
order_id | transaction_id |
content_ids | x-fb-cd-content_ids |
content_type | x-fb-cd-content_type |
content_name | x-fb-cd-content_name |
content_category | x-fb-cd-content_category |
contents* | items OR x-fb-cd-contents |
num_items | x-fb-cd-num_items |
predicted_ltv | x-fb-cd-predicted_ltv |
status | x-fb-cd-status |
delivery_category | x-fb-cd-delivery_category |
custom_properties* | custom_properties |
Please JSON.stringify x-fb-cd-contents and custom_properties before sending, as these are Meta defined JSON parameters.
After configuring your web and server containers, you can send a sample event from your website to verify the server event. A sample event with the configured parameters may look something like this
gtag('event', 'purchase', { 'event_id': generateEventId(), 'transaction_id': 't_12345', 'currency': 'USD', 'value': 1.23, user_data: { email_address: '<HASHED_DATA>', phone_number: '<HASHED_DATA>', address: { first_name: '<HASHED_DATA>', last_name: '<HASHED_DATA>', city: '<HASHED DATA>', region: '<HASHED_DATA>', postal_code: '<HASHED_DATA>', country: '<HASHED_DATA>' }, }, items: [ { item_id: '1', item_name: 'foo', quantity: 5, price: 123.45, item_category: 'bar', item_brand: 'baz' } ], });
Once the event is triggered, you should see a request sent to, for example, sample link: www.analytics.example.com/g/collect, with the configured parameters. You can add test event code to the Meta Conversions API Tag to verify events sent to the Conversions API. The test event code should only be used for testing. You need to remove it when sending your production payload.
After you have published your changes, use the Verifying your setup page here to ensure your events are being sent correctly by checking the following Verifying Setup - Conversions API and review the quality integration is meeting our best practices.
Are there plans to add the capability to send custom parameters? If yes, when will this be available?
A: We have added mapping for most of the Conversions API’s standard custom parameters that are supported in GTM’s schema. We have also provided custom mapping. See here for more.
Is a single server or cluster able to run multiple containers?
A: Currently, GTM supports only 1:1 mapping. Read recommendations on how to organize your containers.
Does Server-Side GTM require a browser-based tag to emit events?
A: Yes
Is it possible to keep GA4 separately with Server-Side integration?
A: To keep a separate GA4 and Server-Side GTM integration, you can create an additional Measurement ID in Google Analytics. Create a separate GA4 Configuration tag for Server-Side GTM using this Measurement ID, following the steps above. In this scenario, your existing GA4 Configuration tag will continue to send GA traffic through the Web Container, whereas the new Configuration tag will send data to the Server Container. Create additional GA4 Event tags as per Step 2 to send events server-side, using the new Configuration tag
Does the GTM Conversions API integration work with cloud hosting solutions other than GCP?
A: The GTM Conversions API integration should work with GCP or any other platform of your choosing. Read more here about manual provisioning.