Facebook Conversion API for Shopify: the full server-side setup with GTM and Stape
To set up the Facebook Conversion API on Shopify with full control, run Google Tag Manager from a custom pixel under Settings → Customer events, send each event to your own server-side GTM container on a subdomain of your store, and forward it to Meta with a Conversions API tag that uses the same event ID as your pixel. On Shopify this matters because the checkout and thank-you pages don't run your theme's code, but they do run customer event pixels. The quicker alternative is the Conversions API built into Meta's Facebook & Instagram app, but use one or the other for purchases, never both.
The video above shows the whole server-side setup on a Shopify store in about 14 minutes, using GTM and Stape. This post is the written version: what's different on Shopify, the steps in the order of the video, and the mistakes that cause double counting. For the general GTM side in more detail, see how to set up the Facebook Conversion API with Google Tag Manager.
What's different on Shopify
On most sites, you paste your tracking code into the theme and it runs on every page. Shopify works differently in three ways.
Checkout and thank-you pages run pixels, not theme code. Your theme's theme.liquid doesn't load on checkout. Shopify's customer event pixels do: they load on the storefront, the checkout, the Thank you page and the Order status page (Shopify Help, pixels overview). That's why your purchase event, and your GTM container, have to live in a custom pixel.
Additional scripts are gone for tracking. On Shopify's new Thank you and Order status pages, Additional scripts for tracking and analytics aren't supported. Shopify says to replace them with pixels (Shopify Help, replacing additional scripts). If an old guide tells you to paste a purchase script under Checkout settings, it's out of date.
Custom pixels run in a sandbox. It's an isolated environment: a pixel can't add anything to your page, and it can't pick up events by reading the page the way theme code can. Your data layer has to come from Shopify's customer events (such as the completed checkout), not from scraping the page.
Two ways to get the Conversion API on Shopify
Meta's Facebook & Instagram app. In Sales channels → Facebook & Instagram → Settings → Data sharing settings, you choose a data-sharing level: Standard, Enhanced or Maximum. Standard is the pixel only. Enhanced and Maximum add the Conversions API, which sends the purchase from Shopify's servers to Meta's (Shopify Help, Facebook data sharing). It's the fastest route, but you can't choose what's sent or check it in GTM.
Server-side GTM, as in the video. You control every parameter and every customer detail, the events go through your own subdomain, and the same setup can feed Google Ads and GA4 later. It takes more work.
Both are fine. Running both on the same pixel is not. Each sends its own copy of the purchase with its own event ID, so Meta can't pair them and counts the sale twice.
What you need
- Your web GTM container already running in a Shopify custom pixel, with Meta Pixel tags that send an event ID. That's the setup from my previous video on the Meta Pixel with GTM on Shopify. This video builds on it.
- A GTM server container in the same GTM account.
- Stape (or another host) to run the server container. In the video I needed a paid Stape plan for the custom subdomain.
- Access to your domain's DNS to add the subdomain.
- Your Meta Pixel ID and a Conversions API access token. This guide shows where both are.
Step 1: create the GTM server container
In Google Tag Manager, open the same account as your web container. Click the gear icon (Admin), then Create container. Name it and choose Server as the target platform.
GTM then shows a Container config, a long encoded string. Copy it.
Step 2: host it on Stape
In Stape, create a new sGTM container hosting container. Use your brand name as the name, paste the container config, and pick the server location closest to most of your customers. Click Create container, and your server is running.
Step 3: add your tracking subdomain
In Stape, go to Subdomains → Tagging server URLs and add a subdomain. Any prefix works, but avoid words like "pixel" or "tracking", which ad blockers look for. In the video I chose Stape's global CDN so the script loads faster.
Stape gives you two CNAME records. Add both, exactly as shown, wherever your domain's DNS lives: Cloudflare, Namecheap, GoDaddy, Hostinger or elsewhere. Then click Verify. In my experience it takes anywhere from 10 minutes to 72 hours. When it shows as ready, your subdomain is live.
Step 4: put the custom loader in your Shopify custom pixel
This is the Shopify-specific part.
In Stape, open Power-ups → Custom Loader and click Configure:
- Domain: your new subdomain.
- Web GTM ID: your web container's ID.
- Enhanced ad blocker protection: on. It encodes the requests to your server, so they're harder to block.
- Platform: Other.
Click Generate. Stape gives you two snippets: a script for the head, and a noscript part.
In Shopify admin, go to Settings → Customer events and open the custom pixel that holds your data layer and GTM. Replace the old GTM snippet with the custom loader script. A custom pixel takes JavaScript only, so remove the <script> tags and the HTML comment lines, or Shopify shows errors. Save, then click Connect.
Look at the new script: GTM now loads from your own subdomain, not from googletagmanager.com. That's what makes your tracking first-party, and it now runs on checkout and the thank-you page too.
The noscript part goes in your theme, since a custom pixel can't hold HTML. Go to Online Store → Themes, click the three dots, Edit code, open theme.liquid, paste it just before the closing </body> tag, and save. It's only a fallback for browsers with JavaScript turned off.
Step 5: add Data Tags in the web container
Your web container already has the variables, triggers and Meta Pixel tags. Leave those as they are. Now add a Data Tag (Stape's tag template) for each event. It sends the event from the browser to your server container.
In the Purchase Data Tag:
- Event name: standard, Purchase.
- Server URL: your subdomain.
- Add common cookie: on, for consistent user identification across sessions.
- Event data: content IDs, contents, currency, value, transaction ID, items, coupon, and the event ID. Use the same event ID variable as your Meta Pixel tag. This is what deduplication depends on.
- User data: email, phone, first and last name, city, region, postal code, country, and your customer ID as the external ID.
- Trigger: the same purchase trigger as your Meta Pixel tag.
Repeat it for ViewContent, AddToCart, InitiateCheckout and AddPaymentInfo. Same structure, different event names.
Step 6: build the server container
The server container has clients, triggers, tags and variables. This is where the Conversions API lives.
Variables. Create three Constant variables: your Conversions API access token, your Pixel ID and your test event code. To get the token, open your pixel in Meta Events Manager, go to Settings, scroll to Conversions API and click Generate access token.
Then create Event Data variables for everything the Data Tags send: first name, last name, email, phone, city, region, postal code, country, event ID, value, currency, transaction ID and so on. I prefix them "ED" so they're easy to find.
Triggers. One Custom trigger per event, each with the condition Client Name contains Data Client. The trigger then fires only on events that came in from your Data Tags, not from any other client. It stops accidental firing and keeps your data clean.
Tags. One Facebook Conversions API tag per event. In the Purchase tag:
- Event name setup: override, standard Purchase, action source website.
- Your access token, Pixel ID and test event code constants.
- Generate _fbp cookie and event enhancement: on.
- Server event data override: map Event ID to your ED event ID variable. This is the line that makes deduplication work.
- User data: the customer details and external ID, from your ED variables. The tag hashes them before sending, as Meta requires.
- Custom data: content IDs, value, currency and order ID.
- Trigger: your Purchase custom trigger.
Do the same for ViewContent, AddToCart and InitiateCheckout.
Step 7: publish and test in Meta
Submit and publish both containers.
Then open your pixel in Meta Events Manager and go to Test events. In another tab, go through your store like a customer: a product page, add to cart, checkout, and a real test purchase. GTM Preview shows what your tags sent; Test events shows what actually reached Meta, so it's the check that matters most.
For each event you should see it arrive from the browser and from the server. Open the Purchase and check what Meta received: value, currency, content IDs, contents and order ID, plus customer details such as email, name, city, country, postal code and external ID.
When everything is right, remove the test event code from your server tags and publish again.
How deduplication shows up
Meta counts the browser and server copies as one event when both have the same event name and the same event ID (Meta, handling duplicate pixel and Conversions API events). That's why the event ID in the Data Tag must use the same variable as the pixel tag, and why the server tag maps it explicitly.
In Events Manager, an event received from both sides shows both connection methods. After a day of normal traffic, check the Purchase event's deduplication details. One test order doesn't tell you much. For more on reading those numbers, see Meta CAPI deduplication and event_id.
At the end of the video I show the Events Manager overview of a live Shopify store with this setup. Browsing events like PageView and ViewContent show "Update recommended" for Event Match Quality, which is normal: the visitor hasn't given any details yet. The Purchase scores much higher, because by then the customer has entered their email, name, phone and address.
Common mistakes
The Facebook & Instagram app is still sharing data. If its data-sharing level is Enhanced or Maximum on the same pixel, the app sends its own Conversions API purchase with its own event ID. Meta can't pair it with yours. Turn off customer data sharing in the app if you use the GTM setup. Keep one source of Meta purchases.
Old pixel code left in the theme. A Meta Pixel or GTM snippet still in theme.liquid, or a pixel app, fires on the storefront next to your custom pixel. Events like ViewContent and AddToCart then arrive twice. Remove the old code when you move to the custom pixel.
Different event IDs on each side. If the Data Tag and the Meta Pixel tag use different variables, or one has none, nothing gets deduplicated.
No client filter on the server triggers. Without "Client Name contains Data Client", a server tag can fire on events from another client too, and send extra copies.
A subdomain called "pixel" or "tracking". Ad blockers look for those words. Pick something neutral.
The test event code left on. Remove it before you call it finished.
Questions people ask
Does Shopify have a built-in Facebook Conversion API?
Yes. Meta's Facebook & Instagram app uses the Conversions API when you set its data sharing to Enhanced or Maximum. It's the easiest option. Server-side GTM gives you control over what's sent and lets you reuse the same server for Google Ads and GA4.
Can I use the Facebook & Instagram app and server-side GTM together?
Not for sending events to the same pixel. Each sends its own copy of every purchase with a different event ID, so Meta counts them twice. Pick one, and turn off data sharing in the app if you go with GTM.
Why does GTM go in a custom pixel and not in theme.liquid?
Because the checkout and thank-you pages don't load your theme's code. Customer event pixels load on the storefront, checkout, Thank you page and Order status page, so a custom pixel is the only place one GTM setup can see every step, including the purchase.
Can I still use Additional scripts for the purchase?
No. Shopify doesn't support Additional scripts for tracking on its new Thank you and Order status pages, and says to use pixels instead.
Do I need Stape?
No. Stape hosts server-side GTM, and other hosts such as Google Cloud work too. I use Stape because its custom loader and Data Tags make the Shopify side simpler. I also walked through a full Shopify setup for a client, with GA4 on the same server, in this case study video.
Where KiteTrack fits
This is the setup KiteTrack builds and runs for Shopify stores. KiteTrack sends your events to Meta, Google Ads, GA4 and TikTok from your own tracking server on your store's subdomain, with customer data hashed and one event ID shared with the pixel, so each sale counts once. It also checks your tracking every 30 minutes, so a broken purchase event becomes an alert instead of a lost week. See how it works for Meta Conversions API on Shopify.
Not sure whether Meta is seeing all your Shopify sales, or seeing some twice? Start with the free Tracking Check. It looks at your site in about two minutes, no signup. If you'd rather talk it through, book a call with me.
Sources
- Shopify Help, Pixels overview: https://help.shopify.com/en/manual/promoting-marketing/pixels/overview
- Shopify Help, Reviewing and replacing additional scripts on your Thank you and Order status pages: https://help.shopify.com/en/manual/checkout-settings/customize-checkout-configurations/upgrade-thank-you-order-status/additional-scripts
- Shopify Help, Facebook data sharing: https://help.shopify.com/en/manual/promoting-marketing/analyze-marketing/meta-data-sharing
- Meta, Handling duplicate pixel and Conversions API events: https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events/
Get tracking tips by email
Short, practical fixes for Meta, Google Ads and GA4, from Abir.
You’re in. First tip lands soon.