Set up Ways

How to Set Up Facebook Conversion API with Google Tag Manager

Use Google Tag Manager's server-side container to implement Facebook CAPI without writing custom server code.

Why Use GTM for CAPI Implementation

Google Tag Manager Server-Side (sGTM) has emerged as one of the most popular methods for implementing Facebook's Conversion API, especially for marketing teams that already use GTM for tag management. Server-side GTM acts as a middleware layer between your website and Facebook, processing and forwarding conversion events from a cloud server rather than the user's browser.

The primary advantage of using GTM for CAPI is that it doesn't require custom backend development. If your team is already comfortable with GTM's interface for managing tags and triggers, extending to server-side CAPI implementation is a natural progression. The server-side container handles the API calls, data formatting, and hashing automatically.

This approach is particularly valuable for agencies managing multiple client accounts, as it provides a standardized, repeatable implementation process. It also centralizes your tag management across both client-side and server-side tracking in a single platform.

GTM Server-Side vs. Other CAPI Methods

CriteriaGTM sGTMPlatform PluginDirect API
Setup difficultyMediumLowHigh
Developer neededNoNoYes
CustomizationHighLimitedMaximum
Multi-platformYesPlatform-specificYes
Running cost$50-300/moFree-$50/moServer costs
First-party cookiesYesNoManual
Data enrichmentYesLimitedManual

Architecture Overview

Server-Side GTM Container

The server-side GTM container runs on Google Cloud Platform (or another cloud provider) and receives data from your web GTM container. It processes incoming events, enriches them with server-side data, and forwards them to Facebook's Conversion API endpoint.

Data Flow: Browser → Server → Facebook

Events originate from user interactions on your website, are captured by the web GTM container, sent to your server-side container via a first-party endpoint, and then forwarded to Facebook via CAPI. This three-step flow provides data enrichment opportunities at the server level.

First-Party Data Collection

By routing tracking through your own server-side GTM container on a first-party domain, you improve data quality and user privacy. Cookies set by your server are first-party cookies with longer lifespans, and data processing happens on your infrastructure.

Setup Steps

01

Set Up Server-Side GTM Container

Create a new server-side container in GTM. Deploy it to Google Cloud Platform using the automatic provisioning option, or manually configure it on your preferred cloud provider. Set up a custom domain (e.g., tracking.yourdomain.com) to enable first-party data collection.

02

Configure the GA4 Client in sGTM

Add a GA4 Client to your server-side container to receive incoming data from the web container. This client parses the GA4 measurement protocol requests and makes the event data available to server-side tags. Configure it to accept requests from your web property.

03

Add the Facebook CAPI Tag

Install the Facebook Conversions API tag template from the GTM Community Template Gallery. Configure it with your Pixel ID and CAPI access token. Map incoming GA4 events to Facebook standard events (e.g., 'purchase' → 'Purchase', 'add_to_cart' → 'AddToCart').

04

Configure User Data Parameters

Map customer data fields from your events to Facebook's user data parameters. Include hashed email, phone, name, address fields, and browser identifiers (fbp, fbc). The tag template handles SHA-256 hashing automatically for personal data fields.

05

Set Up Event Deduplication

Configure event ID matching between your web-side pixel and server-side CAPI events. In the web GTM container, ensure the Facebook Pixel tag sends an event_id parameter. In the server-side CAPI tag, map this same event_id to prevent duplicate event counting.

06

Test and Deploy

Use GTM's preview mode for both web and server containers simultaneously. Verify events flow from browser to server to Facebook. Check Events Manager's Test Events tool to confirm receipt. Once validated, publish both containers.

GA4 to Facebook Event Mapping

When using the GA4 client in sGTM, you need to map GA4 event names to Facebook standard events:

GA4 EventFacebook EventKey Parameters to Map
purchasePurchasevalue, currency, transaction_id, items
add_to_cartAddToCartvalue, currency, items
begin_checkoutInitiateCheckoutvalue, currency, items
view_itemViewContentitem_id, item_name, value
add_payment_infoAddPaymentInfovalue, currency
generate_leadLeadvalue, currency
sign_upCompleteRegistrationmethod
searchSearchsearch_term

Server-Side GTM Hosting Costs

Running a server-side GTM container requires cloud hosting. Here's what to expect:

Small Sites

< 100K visits/mo

$30-50/mo

1 Cloud Run instance, basic setup

Medium Sites

100K-1M visits/mo

$50-150/mo

Auto-scaling, custom domain

Enterprise

1M+ visits/mo

$150-500/mo

Multi-region, high availability

Troubleshooting GTM Server-Side CAPI

Events not reaching the server container

Verify your web GTM container is sending events to the correct server container URL. Check that the transport_url in your GA4 config tag points to your sGTM domain (e.g., tracking.yourdomain.com). CORS issues can also block requests.

Facebook CAPI tag showing errors

Common causes: invalid access token (regenerate in Events Manager), incorrect Pixel ID, or malformed event data. Check the sGTM preview mode's console output for specific error messages from Facebook's API response.

Duplicate events in Events Manager

Ensure the event_id parameter is properly mapped in both the web pixel tag and the server CAPI tag. Use the same data layer variable for event_id in both. Verify in Events Manager that events show 'Browser & Server' connection method.

High server container costs

Filter out unnecessary events (like page_view or scroll events) in the server container before they trigger the CAPI tag. Only forward conversion-relevant events to Facebook to reduce API calls and processing costs.

GTM CAPI Best Practices

  • Use a first-party subdomain for your server-side container to improve cookie longevity
  • Enable the GA4 client's cookie mirroring feature for consistent user identification
  • Send the fbclid parameter through the data layer for click-level attribution
  • Monitor server container costs — optimize by filtering unnecessary events before forwarding
  • Use GTM's built-in logging to debug event flow and parameter mapping issues
  • Keep the Facebook CAPI tag template updated for latest API version compatibility

GTM CAPI FAQ

Do I need Google Cloud Platform to run sGTM?

Google Cloud Platform (GCP) is the default and easiest option, but you can also deploy sGTM on AWS, Azure, or any cloud provider that supports Docker containers. Third-party services like Stape.io and Addingwell offer managed sGTM hosting with simplified setup.

Can I use sGTM CAPI with any website platform?

Yes! That's one of the biggest advantages of GTM Server-Side. Since it works through the GTM web container and GA4, it's platform-agnostic. It works with Shopify, WordPress, Magento, custom websites, and any platform that supports GTM.

Will server-side GTM replace the web container?

No. The web container remains essential for capturing browser-side interactions and sending data to the server container. Think of sGTM as an extension of your existing GTM setup, not a replacement. Both containers work together.

How do I pass user data (email, phone) through GTM to CAPI?

Push customer data to the GTM data layer when users log in, fill out forms, or complete purchases. In the web container, include this data in your GA4 event tags using user_data parameters. The server-side CAPI tag will pick up this data and hash it automatically before sending to Facebook.

Can I use sGTM for other platforms besides Facebook?

Absolutely. sGTM supports tags for Google Ads, TikTok, Pinterest, Snapchat, and more. You can forward the same server-side events to multiple advertising platforms simultaneously, creating a unified server-side tracking architecture.