Skip to content

Server-Side GTM and Tracking Architecture: Hosting Costs, Safari ITP and Deduplication

Key Takeaways

  • Cloud Run is the costliest sGTM host at low traffic. Google's Cloud Run setup guide prices each always-on sGTM instance at roughly $45/month and recommends at least 2 instances ($90/mo compute baseline before Cloud Load Balancing, networking, and request logging).
  • Stape.io bills fixed request tiers. Paid plans start at $20/mo for 500k requests after a Free 10k tier, then $100/mo for 5M and $200/mo for 20M; annual billing drops those to $17, $83, and $167/mo.
  • Cloudflare Zaraz is the lowest-cost of the three hosts at every traffic tier compared here: it includes 1,000,000 free Zaraz Events per month and bills $5 per additional 1,000,000.
  • WebKit caps HTTP Set-Cookie lifetimes at 7 days on outside CNAME-cloaked and IP-cloaked subdomains. A same-origin path like yourdomain.com/metrics behind your CDN or load balancer is the fix, because the browser hits one origin.
  • A server GTM container receives roughly 10 to 12 incoming sGTM HTTP requests per session once it serves gtm.js, gtag.js, pageviews, and conversion hits.
  • Server-side deduplication needs one shared event_id between browser and server tags (your deterministic order_id on Purchase). Server-side consent needs Google Consent Mode (gcs / gcd) checks inside sGTM so server tags stay off when consent is denied.

Why does pointing sst.yourdomain.com at Cloud Run still get capped at 7 days in Safari?

Updated

A tagging subdomain like sst.yourdomain.com on a separate cloud host such as Cloud Run gets its Safari cookies capped at 7 days, because WebKit treats it as outside CNAME or IP-address cloaking. Moving Google Tag Manager (GTM) to a server container (sGTM) gives you a server-side layer to inspect, reshape, and route measurement data before forwarding it to vendors. It does not, on its own, keep Safari cookies alive past a week.

WebKit's Intelligent Tracking Prevention (ITP) caps HTTP Set-Cookie lifetimes at 7 days whenever a first-party subresource resolves through outside CNAME cloaking or outside IP-address cloaking. In Safari 16.4+, even an A-record subdomain hits that 7-day ceiling when its IP address shares fewer than the first 16 bits (IPv4) or 64 bits (IPv6) with your page's IP address. Proxying tagging hits through a same-origin path on your main CDN or load balancer avoids the IP mismatch altogether.

$90/mo

Cloud Run compute baseline for Google's recommended 2 min instances

$20/mo

Stape.io Pro monthly ($17 annual) for 500k requests + Cookie Keeper

7 days

Safari ITP cap on outside CNAME or IP-cloaked Set-Cookie headers

1,000,000

monthly free events included in Cloudflare Zaraz

Hosting cost math at real traffic

How much do Cloud Run, Stape.io and Cloudflare Zaraz cost by monthly volume?

Cloud Run, Stape.io and Cloudflare Zaraz cost $0 to $450/mo across four traffic tiers at list prices.

Multiply monthly sessions by 10 to 12 to approximate sGTM HTTP requests (container loader, gtag.js, 3 to 5 pageviews, scroll, and conversion hits). Stape counts every script load such as gtm.js and gtag.js as a request. Its rule of thumb is your last 30 days of GA4 events plus 30%, so roughly 13,000 requests for 10,000 monthly GA4 events. Cloud Run bills continuous compute for minimum instances plus outbound networking, with Cloud Load Balancing billed separately on GCP. Stape.io bills fixed monthly request tiers. Cloudflare Zaraz bills per Zaraz Event (pageviews and zaraz.track calls, typically ~6 to 7 events per session since Zaraz doesn't serve GTM scripts).

Example traffic (est. sGTM reqs / Zaraz events)Google Cloud Run (sGTM + Cloud Load Balancer)Stape.io (monthly / annual)Cloudflare Zaraz (edge)
10,000 sessions (~100k reqs / ~60k events)
$90+/mo (2 min instances + Load Balancer)
$20/mo Pro ($17 annual; up to 500k reqs)
$0/mo (within 1M free events)
50,000 sessions (~500k reqs / ~300k events)
$90+/mo + Load Balancer and egress
$20/mo Pro (500k ceiling)
$0/mo (within 1M free events)
400,000 sessions (~4.5M reqs / ~3M events)
$150-$250/mo (est. 3-5 instances + Load Balancer)
$100/mo Business ($83 annual; up to 5M reqs)
$10/mo (1M free + 2M paid x $5/M)
1,500,000 sessions (~18M reqs / ~10M events)
$250-$450/mo (est. autoscaling + Load Balancer)
$200/mo Enterprise ($167 annual; up to 20M reqs)
$45/mo (1M free + 9M paid x $5/M)
Watch Cloud Run min-instances and Cloud Logging bills
Dropping min-instances to 0 saves the ~$45/instance fee, but cold starts stall beacons and drop conversions on fast checkout redirects. Google recommends at least 2 tagging instances (autoscaling 2 to 10 instances handles roughly 35 to 350 req/sec). Google also advises excluding run.googleapis.com/requests from Cloud Logging above 1 million requests/month so log charges don't eclipse compute.

Should you choose Cloudflare Zaraz or sGTM?

Choose Cloudflare Zaraz when Cloudflare already proxies your domain and your stack uses standard integrations; choose sGTM when your team needs Tag Manager's tag, trigger and variable model.

Cloudflare Zaraz offloads analytics tools, advertising pixels, and scripts straight to Cloudflare's edge on any Cloudflare plan. If Cloudflare already proxies your domain and your stack uses standard ad and analytics integrations, Zaraz removes the GTM server-container layer completely. Stay with sGTM on Stape.io or Cloud Run if your analytics team works in Tag Manager's tag/trigger/variable model or needs custom community templates and Firestore/BigQuery lookups.

Defeating Safari ITP without breaking first-party cookies

How do you route sGTM through a same-origin path with a Cloudflare Worker?

A Cloudflare Worker routes sGTM through a same-origin path by forwarding /metrics/* from your main origin, so Safari treats the cookies as true first-party.

Under WebKit Tracking Prevention, JavaScript cookies (document.cookie) expire in 7 days, or in 24 hours after a visitor arrives with link-decoration click IDs. HTTP Set-Cookie headers escape the script cap only when served from a genuine first-party host: WebKit caps HTTP cookies at 7 days on both outside CNAME-cloaked and outside IP-cloaked responses.

Google's custom domain guide shows how to forward a path on your main domain (like https://yourdomain.com/metrics) through your CDN or load balancer to the tagging server. Because the browser hits the exact same hostname and IP as your webpage, Safari accepts the HTTP cookie as same-origin.

// Minimal Cloudflare Worker same-origin reverse proxy for sGTM
// Route: yourdomain.com/metrics/*
// Prerequisite in sGTM GA4 Client: set Cookie Domain explicitly to "yourdomain.com"
// (never "auto", or sGTM will emit Set-Cookie for upstream.host and browsers drop it).
// Also add a Cloudflare Cache Rule bypassing cache on /metrics/* so collect hits
// and x-gtm-server-preview stay live on Free/Pro/Business plans.
export default {
  async fetch(request) {
    const url = new URL(request.url);
    const upstream = new URL(
      url.pathname.replace(/^\/metrics/, "") + url.search,
      "https://sgtm-origin.example-host.net"
    );
    const headers = new Headers(request.headers);
    const clientIp = request.headers.get("CF-Connecting-IP");
    if (clientIp) headers.set("X-Forwarded-For", clientIp);
    const res = await fetch(new Request(upstream, {
      method: request.method,
      headers,
      body: request.method === "GET" || request.method === "HEAD" ? undefined : request.body,
      redirect: "manual",
    }));
    const out = new Response(res.body, res);
    out.headers.set("Cache-Control", "no-store");
    return out;
  },
};

Stape's Cookie Keeper power-up (Pro plans and higher) is the fallback for a locked hosted storefront that can't run a reverse proxy. Cookie Keeper restores shorter-lived marketing cookies from a first-party master cookie stored on your site so returning Safari 16.4+ visitors stay recognized for up to 13 months. Same-origin proxying is cleaner whenever you control your CDN; Cookie Keeper is the pragmatic choice when you don't.

Debugging deduplication, IP spoofing and consent leaks

Which four bugs inflate or drop server-side conversions?

The four bugs that inflate or drop server-side conversions are split event IDs, a dropped CF-Connecting-IP header, cached /metrics/* paths, and consent-blind server tags.

  • Generating separate UUIDs in web GTM and sGTM double-counts conversions. For pre-checkout events (ViewContent, AddToCart), generate one event_id in the dataLayer and forward it to both browser Pixel (eventID) and server tag (event_id). For Purchase, use your deterministic order_id so thank-you reloads and backend webhooks share the same key.
  • Dropping CF-Connecting-IP in your reverse proxy collapses Google Analytics 4 (GA4) geolocation and Meta Conversions API (CAPI) onto one datacenter IP and trips bot filters.
  • Letting CDN Cache Rules cache /metrics/* or strip x-gtm-server-preview leaves sGTM Preview completely blank.
  • Firing server-side Meta CAPI or Google Ads tags from incoming GA4 hits without checking Google Consent Mode parameters (gcs / gcd) violates EEA consent rules even when browser tags were blocked.

Which sGTM health checks should you run every Monday morning?

Run four sGTM health checks every Monday morning: Safari cookie expiry, IP or path routing, Meta deduplication, and the request-to-session ratio.

  1. 1Open Safari on iOS or macOS, load a landing page, inspect Storage > Cookies, and confirm your server-set FPID (GA4 First-Party ID) cookie expires beyond 7 days. If you also set Meta's _fbc click cookie server-side, check its expiry too.
  2. 2On a subdomain setup, compare dig +short sst.yourdomain.com against dig +short yourdomain.com to confirm matching IP prefixes (the first 2 octets of an IPv4 address). On a same-origin /metrics path, run curl -i https://yourdomain.com/metrics/healthy to confirm 200 OK with body ok, or run curl -I "https://yourdomain.com/metrics/gtm.js?id=GTM-XXXXXX" with your container ID. Then check Cache-Control on collect hits.
  3. 3Trigger one live Purchase in Meta Events Manager Test Events and check that browser and server rows show Deduplicated on the same event_id.
  4. 4Divide monthly sGTM incoming requests by GA4 sessions. Ratios above 20x usually mean an unthrottled scroll or timer trigger is inflating your hosting bill.

Common Questions

Does server-side GTM completely bypass ad blockers?

Server-side GTM does not completely bypass ad blockers. Serving gtm.js from a same-origin path recovers traffic blocked by domain lists targeting googletagmanager.com. Strict privacy browsers like Brave Shields still catch default /g/collect request paths unless you mask the collect path (either by setting a custom transport path in the sGTM GA4 client, or by exposing a custom browser path like /metrics/e and rewriting it to /g/collect inside your reverse proxy).

How much does Cloud Run actually cost when traffic spikes?

Cloud Run cost during a traffic spike is a fixed baseline plus compute for the extra instances while they run. Google prices a baseline of 2 minimum instances (1 vCPU, 0.5GB RAM, CPU always allocated) at roughly $45 per instance per month ($90/mo compute) before Cloud Load Balancing, egress, and Cloud Logging. During Black Friday, Cloud Run scales up to your max-instances cap and bills extra compute only while active, whereas Stape prices fixed monthly request tiers (10k Free, 500k, 5M, 20M).

Why did my GA4 direct traffic jump after turning on server-side GTM?

A GA4 direct-traffic jump after a server-side GTM launch points to lost referrer data. Check page_referrer and page_location forwarding on single-page app route changes and confirm your reverse proxy preserves the Referer header. Dropping X-Forwarded-For causes a separate symptom: GA4 geolocation collapses onto your proxy datacenter's city.

What happens if I exceed 1,000,000 events on Cloudflare Zaraz Free?

Exceeding 1,000,000 events on Cloudflare Zaraz Free disables Zaraz until the next billing cycle resets, unless you enabled Zaraz Paid ($5 per additional 1,000,000 events) before you hit the cap. Cloudflare emails warnings at 50%, 80%, and 90% of your 1,000,000-event monthly free allowance.