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 Conversions API or Facebook Conversions API Gateway.
This article will focus on Facebook conversion tracking and show you how to set up Facebook Conversions API via Google Tag Manager Server Container. 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!
Related: Facebook Lead Ads. |
Let’s take a look at what Facebook Conversions API is and how we can use it to improve event tracking, attribution, and data collection on Facebook. Facebook Conversions 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 Conversions 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 Conversions API, the higher the match rate you receive.
Facebook server-side tagging or Facebook Conversions API was available on Facebook for a couple of years. But starting from 2021, FB started to push Conversions 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 Conversions API.
These are the most important reasons to consider implementing Facebook Conversions API. See the details below the infographic.
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.
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.
We will use the server Google Tag Manager container to set up Facebook Conversions API. You will need these things to configure Facebook Conversions API:
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 Conversions API using Google Analytics 4.
2. Send data to the server GTM container. The two most popular sending data to sGTM are Google Analytics 4 and Data Client Stape.
3. Go to your Google Tag Manager Server Container. Add Facebook Conversions API tag from the Template Gallery.
4. Create a Facebook Conversions 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.
5. You have 2 options for configuring our Facebook Conversions API tag:
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 Conversions 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.
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 Conversions API, check this article.
9. Once you’ve set up and verified that Facebook Conversions API works correctly, you need to remove FB browser tracking or set up event deduplication. Otherwise, your events will be duplicated.
The first step of testing Facebook server side tracking is the same as for Google Analytics. You need to make sure that events are firing on the correct triggers. Open the GTM debug tool, click through your site’s pages, and perform events you want to test. Once you’ve done it, go to the Tag Manager debugger tab and check the results.
First, make sure that the FB base pixel is firing on a pageview. If you see the tag status Fail, check outgoing requests. It should show the reason why tag was failed.
If you are using our FB server-side tracking tag, you have two options for sending FB events:
Open events manager inside your Facebook business manager and click on test events. You will see a test event code that you should add to our Facebook Tag inside Google Tag Manager. With the help of this code, you will be able to test Facebook server events in the realtime.
Once you’ve added a test ID, open your site and perform actions triggering your FB events. Then return to the Facebook testing tool and check the events it shows you. In the column “Received From” you should see “Server”. You can click on the event and see the recorded parameters.
Note that the Facebook pixel helper Chrome plugin you used to check FB browser events won’t work for conversion API. That is why you need to check everything inside the testing tool.
Note: cookies will be extended only if you are using a custom subdomain inside the tagging URL. For example, your site’s URL is example.com, then a custom domain for tagging URL should look like gtm.example.com.
The third step is again similar to what we did but has a few differences. To check the Facebook cookies expiration date, you first need to generate it. To do that, open your site and add fbclid.
Once you’ve done that open developers tools, go to storage and click on cookies. Check _fbc and _fbp were extended.
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.
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.
To match users who visit your site with their database, Facebook uses User Data for Conversions 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 server-side tracking, Magento 2 Google Tag Manager, GTM app for 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.
Facebook's Events Testing Tool is a powerful new tool that allows you to debug and resolve issues with your FB pixels or server events. If there are errors, they will be displayed in the Diagnostics tab on the toolbar so you can review them more closely.
Errors marked red usually require a quick reaction and should be fixed right away. The yellow errors are non-critical warnings you should pay attention to and look into eventually.
Facebook allows to mark issues as resolved or ignore them. If you mark an error as resolved and this error repeats, Facebook will show it again in 3 days. In comparison, the ignored problems go to the Ignored section and stay there.
When you fix any issues with your FB tracking, I suggest marking them as resolved. This way, you will notify Facebook that the problems were fixed, and you will hear from the platform if these issues repeat.
You can see all domains that are sending data to your Facebook pixel. If FB notices traffic from a new subdomain or domain, the platform will send you this warning. You can whitelist or blacklist the domains. With the help of this feature, you can block traffic from your testing sites or technical URLs.
Most likely, you will also see the traffic from gtm-msr.appspot.com. It can happen when you run a debugging/publish container or users come to your site with disabled js (some bots).
To create the domain allow or block lists, open the events tool in the Business Manager → Click settings → Scroll down to Traffic Permissions.
That is the second most popular Facebook CAPI error from my experience. This error means that you are not sending some deduplication keys for your server events. Facebook uses these deduplication keys: event name, event ID, _fbp and external ID.
From my experience, Event ID parameters are causing this error 80% of the time. Check if you are sending an event ID for Facebook pixel and Facebook Conversions API. This event ID should be the same for the browser and server event. In this case, FB will see the same event name and event ID and start deduplication.
For example, for the PageView events, send the same event ID and event name from Facebook pixel and FB CAPI.
To test event ID, open the Facebook event testing tool. If everything is correct, you should see something similar to the screenshot. That is how FB shows it recorded PageView events from both browser and server. These events had the same event ID. So they processed browser events and deduplicated server events.
But there might be another situation where you see browser and server events randomly triggered. In this case, check the FB event ID. Most likely, event IDs are not identical. Speaking of which, you can use our custom variable for the web container to set up Facebook event ID. Also see more infortmation on Facebook event deduplication in the section above.
Sometimes this error can be caused when you did not remove Facebook test ID and publish FB CAPI tags to the production environment. I recommend setting up Test ID as a lookup table variable that works only when debug mode is true to fix this issue.
Here, Facebook wants to notify you that the values you are sending from the server are not unique or formatted correctly. For example, you can send user IP that includes symbols and not only numbers. Or maybe you’ve simply selected the wrong variable like sending a phone number in the email field.
To check what is wrong, open the preview mode of the Google Tag Manager server and web container (of course, if you used GTM to set up Facebook Conversions API). You should see what user parameters were sent to Facebook and if they were formatted correctly. Test the event, click on the tag in the debug mode, and select values.
This error can also mean you might have forgotten to include a parameter or it is incorrectly formatted.
For example, I had a client who wanted to send the user country, city based on the IP address. Facebook expects to see actual user address details they enter on the site and not the ones you automatically extracted from the IP. This setup also sent an error about invalid key parameters.
Or maybe you tried to cheat and send the same username for all events to increase the quality.
This error usually relates to the browser events and means that Facebook detected user data in the URL. Some CMS and other tools like Calendly or PayPal send user details in the URL after they registered or made a purchase.
This error is hard to fix, and that is a task for your developers. They should improve the URL query parameters and remove all the user information from the URL. Alternatively, you can follow instructions from this GitHub post and try to fix the issue inside the GTM. Another way is to switch to server-side Facebook tracking only. This way you can modify the URL before sending it to Facebook.
For each server event that you send to FB, there will be the event match quality score. This score depends on the number of user data you send to FB.
If you use a custom subdomain for your tagging server, only User IP, browser ID, _fbp, and _fbc are sent to FB CAPI. If you send only these user parameters, the match quality will be around 4 out of 10.
To have high quality score, it is pretty important to send as many parameters as possible. FB uses these data to match users on your site to the ones in their database. But before doing it, you should check if sending user data to FB complies with the privacy policy rules indicated on your site and other regulations first. But technically, it’s good to send more parameters. It means that the audience and conversion data will be more accurate, Facebook algorithms will have more specific data about your users, and campaigns will perform better.
How can you increase the event match quality score? The answer is simple: you need to send more user data. But the implementation remains a complex process. Here is how it works: I start by checking if the data layer is implemented on your site and whether it has all user data. For example, if the user can log in to your site, you need to check if user details are sent to the data layer when users are logged in.
If the data layer is not implemented, then assign a task of setting it up to your developers.
After that, make sure that you pass all user parameters from the web to the server container.
Another thing that will help you increase the match quality is a new feature from the Data Tag. We added the ability to store user data. For example, if the user submitted a contact form on the site, you can use the Data tag to store user data in the local storage and then use it on other pages.
If you are tracking Facebook events from both browser and server, then Facebook requires you to send a unique event ID for every event. For the matching events, Facebook pixel event name should be exact to the server events name. Same for the event ID, the same events from the FB pixel should match FB server events. This is when deduplication happens.
This error happens when you send the same event ID for many events. For example, a user landed on the product page. It means that two events should trigger on this page: PageView and ViewContent. You should send a unique event ID for each of the events. It means that FB events and eventIDs should look like:
FB browser: PageView, eventID: ‘69’
FB server: PageView, eventID: '69'
FB browser: ViewContent, eventID: '79'
FB server: ViewContent, eventID: '79'
Even though these events trigger on the same page and might use the same trigger in the Google Tag Manager web and server container, you should send a unique event ID for both of them.
Same Event ID Received for Many Event Instances will occur if you’ll have this situation:
FB browser: PageView, eventID: ‘69’
FB server: PageView, eventID: '69'
FB browser: ViewContent, eventID: '69'
FB server: ViewContent, eventID: '69'
In this example, we are sending eventID 69 for both PageView and ViewContent events. But Facebook expects to see a unique eventID for these two events.
Solution: add Facebook test ID, open the preview mode of web and server containers, and test the setup. After you find out when this error happens, we can do more to fix the issue.
We created a custom variable that generates a unique event ID. I suggest using this variable to set up FB event deduplication. You can add an event name to this variable to ensure that the eventID is unique. In this case, even if your events will use the same trigger, the eventID will be unique since it consists of event_name_eventID. You can read more about Facebook event deduplication in the section above.
By default, the tag tries to map GA standard events to Facebook standard events. If it cannot match it, the raw event name that came from the GA client will be used. For example, if you send an event name like this: gtag(‘event’, ‘UserLikedProduct’), you will get the event “UserLikedProduct” in the Facebook event manager.
Below you will find the scheme of mapping GA events to Facebook events that we use in this tag by default:
page_view | PageView |
add_payment_info | AddPaymentInfo |
add_to_cart | AddToCart |
add_to_wishlist | AddToWishlist |
sign_up | CompleteRegistration |
begin_checkout | InitiateCheckout |
generate_lead | Lead |
purchase | Purchase |
search | Search |
view_item | ViewContent |
contact | Contact |
customize_product | CustomizeProduct |
donate | Donate |
find_location | FindLocation |
schedule | Schedule |
start_trial | StartTrial |
submit_application | SubmitApplication |
subscribe | Subscribe |
To make migration of your web Facebook GTM tag to server-side container simpler, we tried to map all data that GA client receives to the Facebook event without any setup from your side. It also supports GA Enhanced Eccomerce events mapping, and of course, the tag can override all event parameters that will be sent to Facebook.
For example, if the tag detects that the event type is “Purchase”, we will determine the product list, their currency, and value.
In the sections below, we describe how exactly data mapped in every parameter group.
There are only a few parameters that are in the category of Server Event Data. See this documentation for more details on what data parameters exist.
Parameters that are set by default:
event_name | Event Name |
event_source_url | Page Location |
action_source | Where your conversions occurred. (For example: website, email, app) |
event_time | Current Time |
With the “User Data” tag option, you can override or add any user data that will be sent to Facebook. See this Facebook documentation for more details on what user data parameters you can add to the call. If the documentation calls for the parameter to be hashed, you must hash it with SHA256 or the hit will not be sent to Facebook.
fbc | Cookie value ‘_fbc’ or ‘fbclid’ url parameter if exist |
fbp | Cookie value ‘_fbp’ |
external_id | external_id or user_id or userId |
subscription_id | subscription_id or subscriptionId |
lead_id | lead_id or leadId |
ln | lastName or LastName or nameLast |
fn | firstName or FirstName or nameFirst |
em | |
ph | phone |
ge | gender |
ct | city |
st | state |
zp | zip |
country | countryCode |
You also can override any other parameters or add your own using the “Custom Data” section in the tag setup. Check out this documentation for more details on what data parameters you can add to the call.
If the EE parameter ‘items’ exists, tag set content_type to ‘product’. GA product parameters item_name, item_category map onto Facebook content_name, content_category accordingly.
Tag also tries to determine other product parameters, including the following:
value | x-ga-mp1-ev or value |
currency | currency |
transaction_id | order_id |
If the event type is “Purchase” but the currency can’t be mapped, ‘USD’ is used as the default value. That’s because Facebook doesn’t accept “Purchase” events without the currency parameters.
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.
Stape has lots of options! Click on Try for free to register and check all the benefits.
Subscribe for updates:
we don’t spam!
Comments