Browser-based tracking is deteriorating. Safari’s Intelligent Tracking Prevention limits client-side cookies to seven days. Firefox has Enhanced Tracking Protection. Chrome is rolling out Privacy Sandbox and third-party cookie deprecation. Ad blockers strip tracking scripts before they execute. The result: client-side analytics data is becoming progressively less accurate, and ecommerce stores relying solely on browser-based tracking are making decisions on increasingly incomplete data.
Server-side Google Tag Manager addresses this by moving tag processing from the browser to a server you control. Instead of loading Google Analytics, Meta Pixel, and a dozen other tracking scripts in your customer’s browser, you send a single data stream to your tagging server, which distributes data to each platform’s server-side API. The benefits are significant: better data accuracy, improved page speed, longer cookie durations through first-party domain configuration, and a more privacy-respecting architecture.
This guide walks through the complete process of implementing server-side GTM on Shopify — from provisioning your tagging server to configuring the data layer, setting up first-party cookies, and integrating with GA4 ecommerce tracking and Meta’s Conversions API. It assumes familiarity with standard GTM and basic ecommerce tracking concepts. If you need to get your analytics foundations right first, start there.
Why server-side tracking matters now
The shift to server-side tracking is not optional for serious ecommerce operators. It is a response to three converging forces that are making client-side tracking unreliable:
Browser privacy restrictions
Safari’s ITP limits JavaScript-set cookies to a maximum of seven days. This means if a customer visits your store, leaves, and returns eight days later, Safari treats them as a new user. For attribution, this is devastating — you lose the ability to connect their original marketing touchpoint to the eventual purchase. Server-side GTM allows you to set cookies from your own domain’s server, extending cookie lifetimes beyond ITP restrictions.
Ad blocker prevalence
Approximately 30-40% of UK internet users run ad blockers. These tools do not just block ads — they block tracking scripts, including Google Analytics and Meta Pixel. Server-side tracking routes data through your own domain, making it significantly harder for ad blockers to identify and strip tracking requests.
Platform API requirements
Meta, Google, TikTok, and other advertising platforms now require or strongly recommend server-side event data. Meta’s Conversions API (CAPI) is a server-to-server integration that supplements browser pixel data. Google’s Enhanced Conversions uses server-side data to improve conversion measurement. These platform requirements make server-side infrastructure essential, not optional.
Client-side tracking is not going away. Server-side tracking supplements it. The goal is redundancy: browser events capture what they can, server events fill the gaps, and deduplication ensures accuracy.
Server-side GTM architecture
The architecture has three layers:
- Client-side GTM container (web) — runs in the browser. Reads the data layer, captures user interactions, and sends events to your tagging server instead of directly to third-party endpoints.
- Tagging server — a server you control, running the server-side GTM container. It receives events from the client-side container, processes them, and forwards data to Google Analytics, Meta, and other platform APIs.
- Platform APIs — GA4 Measurement Protocol, Meta Conversions API, Google Ads API, etc. These receive processed event data from your tagging server.
The critical architectural decision is your tagging server’s subdomain configuration. For first-party cookie benefits, the tagging server must run on a subdomain of your store’s primary domain. For example, if your store is yourstore.co.uk, your tagging server should be at something like data.yourstore.co.uk or gtm.yourstore.co.uk.
Setting up your tagging server
You have several hosting options for your tagging server:
Google Cloud Run (recommended)
Google provides an official deployment process for server-side GTM on Cloud Run. This is the most common approach and benefits from Google’s infrastructure:
# Deploy via the GTM interface:
# 1. Create a new Server container in GTM
# 2. Choose "Automatically provision tagging server"
# 3. Select Google Cloud project
# 4. Configure Cloud Run settings
# Or deploy manually via gcloud CLI:
gcloud run deploy gtm-server \
--image gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable \
--platform managed \
--region europe-west2 \
--allow-unauthenticated \
--set-env-vars CONTAINER_CONFIG=YOUR_CONTAINER_CONFIG
Stape.io (managed alternative)
Stape provides managed server-side GTM hosting that abstracts away the infrastructure complexity. It is a solid option for teams without DevOps capability. Pricing starts at roughly £15 per month for lower-traffic stores.
Custom subdomain configuration
Regardless of hosting provider, you need to configure a custom subdomain pointing to your tagging server. This is essential for first-party cookie benefits:
# DNS configuration
# Add a CNAME record pointing your subdomain to the tagging server
Type: CNAME
Name: gtm
Value: your-cloud-run-url.run.app
TTL: 300
Your tagging server URL then becomes https://gtm.yourstore.co.uk, which shares the same root domain as your store. Cookies set by this server are treated as first-party cookies by browsers.
Shopify data layer configuration
A robust data layer is the foundation of server-side tracking. On Shopify, you need to push structured event data to the dataLayer object for every key interaction:
// Product page view
dataLayer.push({
event: 'view_item',
ecommerce: {
currency: 'GBP',
value: 49.99,
items: [{
item_id: 'SKU-12345',
item_name: 'Organic Cotton T-Shirt',
item_brand: 'Your Brand',
item_category: 'Clothing',
item_variant: 'Navy / Medium',
price: 49.99,
quantity: 1
}]
}
});
// Add to cart
dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'GBP',
value: 49.99,
items: [{
item_id: 'SKU-12345',
item_name: 'Organic Cotton T-Shirt',
price: 49.99,
quantity: 1
}]
}
});
Shopify checkout and purchase tracking
Shopify’s checkout is a controlled environment. For purchase event tracking, you have two approaches:
- Web Pixel API — Shopify’s official mechanism for tracking events in the checkout. It runs in a sandboxed iframe and provides access to checkout events including
checkout_started,payment_info_submitted, andcheckout_completed. - Thank you page script — a simpler approach where you add a data layer push to the order status page via Shopify admin → Settings → Checkout → Additional scripts (or the newer Customer events section).
// Order status page / thank you page data layer push
{% if first_time_accessed %}
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: '{{ order.name }}',
value: {{ order.total_price | money_without_currency }},
tax: {{ order.tax_price | money_without_currency }},
shipping: {{ order.shipping_price | money_without_currency }},
currency: '{{ order.currency }}',
items: [
{% for line_item in order.line_items %}
{
item_id: '{{ line_item.sku }}',
item_name: '{{ line_item.product.title | escape }}',
price: {{ line_item.final_price | money_without_currency }},
quantity: {{ line_item.quantity }}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
}
});
{% endif %}
Client-to-server event flow
In your client-side GTM container, instead of sending events directly to Google Analytics or Meta, you configure a GA4 tag that sends to your tagging server endpoint:
// Client-side GA4 Configuration tag
// Transport URL: https://gtm.yourstore.co.uk
// This routes all GA4 events through your server container
// instead of sending directly to google-analytics.com
The server-side container receives these events via a “client” (a server-side concept that receives incoming requests). The GA4 client parses the incoming event data and makes it available to server-side tags, which then forward the data to the appropriate APIs.
First-party cookie strategy
One of the most valuable benefits of server-side GTM is the ability to set first-party cookies from your server. When your tagging server runs on a subdomain of your store domain, cookies it sets are treated as first-party cookies with extended lifetimes.
The key cookie to manage is the GA4 client ID cookie (_ga). In a standard client-side setup, JavaScript sets this cookie with a maximum lifetime of seven days in Safari. With server-side GTM, the server sets this cookie via an HTTP response header, bypassing ITP restrictions and extending the lifetime to up to two years.
// Server-side GTM: Cookie override in the GA4 client
// Set cookie domain to your root domain
// Set cookie path to /
// Set cookie expiry to 730 days (2 years)
// The server sets the cookie via Set-Cookie header,
// bypassing browser-side cookie restrictions
This dramatically improves user identification for returning visitors, which in turn improves attribution accuracy for your marketing channels.
GA4 server-side integration
The GA4 integration is the most straightforward server-side tag setup. In your server container:
- The GA4 client receives events from the web container.
- A GA4 tag forwards events to Google Analytics via the Measurement Protocol.
- The server enriches events with server-side data (user agent, IP for geo, etc.).
Key configuration points:
- Set the Measurement ID in the server-side GA4 tag.
- Enable “Send to GA4 via Measurement Protocol”.
- Configure IP anonymisation if required by your privacy policy.
- Map ecommerce parameters correctly to ensure revenue data flows through.
For comprehensive GA4 ecommerce tracking configuration, see our GA4 ecommerce tracking guide.
Meta Conversions API via sGTM
Meta’s Conversions API (CAPI) is a server-to-server integration that sends event data directly to Meta’s servers, complementing the browser pixel. Server-side GTM is an excellent way to implement CAPI without building a custom integration.
// Server-side Meta CAPI tag configuration
// Access Token: Your Meta CAPI access token
// Pixel ID: Your Meta Pixel ID
// Event Name: Maps from the incoming GA4 event
// Event Parameters: Map ecommerce data to Meta's schema
//
// Key mappings:
// view_item → ViewContent
// add_to_cart → AddToCart
// begin_checkout → InitiateCheckout
// purchase → Purchase
//
// Required parameters for Purchase:
// value, currency, content_ids, content_type, num_items
Deduplication is critical. Both the browser pixel and server-side CAPI will send purchase events. Use the event_id parameter to ensure Meta deduplicates correctly. Generate a unique event ID client-side and pass it through both the browser pixel and the server-side event.
Consent Mode v2 integration
Server-side GTM must respect user consent preferences. Google’s Consent Mode v2 provides a framework for this. Your consent management platform (CMP) sets consent state on the client side, and this state must be forwarded to your server container.
The consent signals flow as follows:
- Customer interacts with your cookie consent banner.
- CMP sets consent state in the data layer (
ad_storage,analytics_storage,ad_user_data,ad_personalization). - Client-side GTM reads consent state and includes it in the event payload sent to your server.
- Server-side tags check consent state before firing or adjust their behaviour accordingly.
For a complete walkthrough of Consent Mode v2 implementation on Shopify, see our dedicated Consent Mode v2 guide.
Testing and debugging
Server-side GTM adds complexity to debugging. Here are the tools and techniques we use:
Server-side preview mode
GTM’s preview mode works for server containers, showing incoming requests and tag execution in real time. Access it from the server container’s GTM interface.
Request inspection
Use browser DevTools → Network tab to verify that client-side events are being sent to your tagging server domain (not directly to google-analytics.com). The request URL should show your custom subdomain.
GA4 DebugView
GA4’s DebugView shows events in real time, regardless of whether they arrived via client-side or server-side. Enable debug mode by adding debug_mode: true to your GA4 configuration.
Meta Events Manager
Meta’s Events Manager shows server events separately from browser events. Use the Test Events tool to verify CAPI events are arriving correctly and deduplication is working.
// Enable GA4 debug mode for testing
gtag('config', 'G-XXXXXXXXXX', {
debug_mode: true,
server_container_url: 'https://gtm.yourstore.co.uk'
});
Server-side GTM is not a set-and-forget implementation. It requires ongoing maintenance as platforms update their APIs, consent requirements evolve, and your store’s tracking needs change. But the investment pays for itself in better data accuracy, improved page performance, and more reliable marketing attribution.
If your current tracking setup is losing data to ad blockers and browser restrictions, server-side GTM is the most effective solution available. The implementation requires technical expertise, but the architecture is well-established and the benefits are measurable from day one.
We implement server-side tracking for Shopify stores as part of our SEO and analytics services and Shopify development work. If you want to upgrade your tracking infrastructure, get in touch.