Stape
Search
Try for free

Set up Facebook server-side tracking with Facebook Conversions API

Ira Holubovska

Ira Holubovska

Author
Updated
May 7, 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 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!

What is Facebook Conversions API?

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.

What are the main benefits of Facebook Conversions API?

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.

Benefits of Facebook Conversion API
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 Conversions API, you will extend the Facebook cookie lifetime to 6 months. If you are not using FB Conversions 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 Conversions 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
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 Conversions API with server GTM?

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.

Steps to set up Facebook Conversions API

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. 

Facebook Conversions API tag for server GTM
Facebook Conversions API tag for server GTM

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.

Facebook conversions API inherit from client
Facebook conversions API inherit from client

5. You have 2 options for configuring our Facebook Conversions 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 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. 

enable event enhancement in facebook capi tag
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 Conversions API, check this article. 

test Facebook Conversions API
test Facebook Conversions API

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. 

Test Facebook Conversion API

2.1 Use the GTM server debug tool to verify that base code and FB events are triggering correctly.

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.

test Facebook capi in server Google Tag Manager
test Facebook capi in server Google Tag Manager

If you are using our FB server-side tracking tag, you have two options for sending FB events: 

  • Inherit from GA client. In this case, we automatically match GA events to FB standard events. If you are using the inherit option, you will see only the FB base tag inside GTM debug mode. 
  • Override. Selecting the override option requires setting up FB server events manually inside the server container. This way, it will be visible in the server debug mode.

2.2 Facebook testing tool for Facebook conversion API

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. 

Facebook event deduplication event testing tool
Facebook event deduplication event testing tool

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.

2.3 Check that Facebook cookies were expended

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.

check fbp and fbc cookies
check fbp and fbc cookies

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 Conversions API

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.

How to check if there are any Facebook pixel or Conversions API errors

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. 

1. New Domains Sending Data

new domains sending data 
new domains sending data 

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.

create allow block list in Facebook
create allow block list in Facebook

2. Event Missing Some Deduplication Parameters

event missing some deduplication parameters
event missing some deduplication parameters

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. 

event deduplication parameters
event deduplication parameters

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.

event deduplication Facebook testing tool
event deduplication Facebook testing tool

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. 

create facebook test ID google tag manager
create facebook test ID google tag manager

3. Server Sending Invalid Match Key Parameters for PageView Event

server sending invalid match key
server sending invalid match key

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.

4. Potentially Violating Personal Data Sent to Facebook

potential violating personal data sent to Facebook
potential violating personal data sent to Facebook

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.

5. Increase event match Quality

event match quality Facebook
event match quality 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.

6. Same Event ID Received for Many Event Instances

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.

Event Name mapping

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_viewPageView
add_payment_infoAddPaymentInfo
add_to_cartAddToCart
add_to_wishlistAddToWishlist
sign_upCompleteRegistration
begin_checkoutInitiateCheckout
generate_leadLead
purchasePurchase
searchSearch
view_itemViewContent
contactContact
customize_productCustomizeProduct
donateDonate
find_locationFindLocation
scheduleSchedule
start_trialStartTrial
submit_applicationSubmitApplication
subscribeSubscribe

Google Analytics to Facebook events

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.

facebook tag configuration
facebook tag configuration

Default mapping and overriding Server Event Data

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_nameEvent Name
event_source_urlPage Location
action_sourceWhere your conversions occurred. (For example: website, email, app)
event_timeCurrent Time

Default mapping and overriding User Data

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.

fbcCookie value ‘_fbc’ or ‘fbclid’ url parameter if exist
fbpCookie value ‘_fbp’
external_idexternal_id or user_id or userId
subscription_idsubscription_id or subscriptionId
lead_idlead_id or leadId
lnlastName or LastName or nameLast
fnfirstName or FirstName or nameFirst
ememail
phphone
gegender
ctcity
ststate
zpzip
countrycountryCode

Default mapping and overriding Custom Data

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:

valuex-ga-mp1-ev or value
currencycurrency
transaction_idorder_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. 

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.

Subscribe for updates:

we don’t spam!
author

Ira Holubovska

Author

Ira has 10+ years of digital marketing experience, with the last 5 focused on server-side tracking. She understands how and when it works across various digital marketing scenarios.

author

Comments

Try Stape for all things server-sideright now!