Server-Side Tracking Migration.
Safari ITP, iOS ATT and ad-blockers eat 20-40% of browser-side measurement. Server-side GTM (sGTM) fixes it — tags run on your server, data flows through your 1st-party domain, PII gets filtered. This guide walks setup from zero to production: Cloud Run deploy, GA4 + Meta CAPI + Google Ads tags, GDPR-compliant structure.
Server-side GTM (sGTM) moves tags from the browser to your server. Benefit: 20-40% cookie loss drops to 5-10%, page speed improves, PII can be filtered. Cost: ~$30-60/mo on Google Cloud Run at small scale. Setup is 4 steps: (1) create Server container in GTM, (2) Cloud Run deploy, (3) 1st-party subdomain CNAME, (4) wire web container's GA4 Client to sGTM. Total time: 3-4 hours for an experienced devops, 8-12 hours first-time.
// 01Why server-side tracking
Classic client-side tracking — browser firing direct requests to Google, Meta, TikTok — has three problems:
- Cookie loss: Safari ITP expires 3rd-party cookies in 7-30 days. iOS 14.5+ ATT kills tracking for 75% of users. Ad-blocker usage exceeds 30%.
- Page speed: 5-10 third-party tags load serially. LCP +1.5-3s.
- Data control: everything goes directly to third parties — GDPR/CCPA exposure, no PII filtering.
Server-side GTM solves most of these.
// 02Architecture overview
Classic (client-side)
Browser → Google Analytics, Meta Pixel, Google Ads (parallel third-party requests).
sGTM
Browser → Web Container → 1st-party endpoint (e.g. track.yourbrand.com) → Cloud Run Server Container → Google/Meta/TikTok (server-to-server).
Critical: the browser only fires one request, to your own domain. From there fan-out happens server-side. Browser sees everything as 1st-party.
// 03Step 1: create Server Container in GTM
- Go to tagmanager.google.com, select your workspace.
- Admin → Container Settings → "Create Container" → Target: Server.
- Note the Container ID (GTM-XXXXX format).
- Choose "Manually provision" for Cloud Run control.
- Note the Server URL placeholder (will be replaced post-deploy).
// 04Step 2: Cloud Run deploy
In Google Cloud Console:
- Create or select GCP project.
- Enable Cloud Run API.
- "Create Service" → Container Image:
gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable - Region: pick close to your user base (us-central1, europe-west1, etc.).
- Authentication: "Allow unauthenticated invocations."
- Container port: 8080.
- Environment variables:
CONTAINER_CONFIG— config string from GTM Server Container.RUN_AS_PREVIEW_SERVER— false (preview gets a separate service).
- CPU 1 vCPU, Memory 512MB to start. Min instances 1 (avoid cold starts).
- Max instances: 10-100 by traffic.
// 05Step 3: 1st-party subdomain
Cloud Run's native URL (your-service-xxx.run.app) is third-party — ITP still hits it. Always serve via your own domain.
- Open DNS provider (Cloudflare, Route53, etc.).
- Add CNAME:
track.yourbrand.com→ghs.googlehosted.com. - Cloud Run console → Domain Mappings → Add Mapping →
track.yourbrand.com. - SSL cert auto-provisions (5-30 min).
- GTM Server Container settings → Server URL =
https://track.yourbrand.com.
// 06Step 4: route web container to sGTM
Update the GA4 Configuration tag in your web GTM container:
- "Send to server container" — true.
- Server container URL —
https://track.yourbrand.com. - Fill the Transport URL field.
Add corresponding server-side tags:
- GA4 Client: parses incoming GA4 requests.
- GA4 Tag: server fan-out to Google Analytics.
- Meta Conversions API Tag: sends same event to Meta.
- Google Ads Conversion Tag: for Ads conversion reporting.
// 07PII filtering + GDPR compliance
The biggest server-side advantage: clean data before sending to third parties.
What to do
- Email hashing: SHA-256 instead of raw email (already required for Enhanced Conversions).
- IP truncation: zero last octet (anonymized IP for GDPR).
- Phone normalization: hash + country-code normalize.
- URL params: filter PII-bearing query strings (e.g.
?email=).
Implement via "Custom Variable" + Transformation server-side. Showing this structure in GDPR audit qualifies as compliance evidence.
// 08Test and observe
- GTM Server Preview mode: test in preview first. Verify each event reaches the server and fires correct tags.
- GA4 DebugView: confirm server-sent events appear in GA4.
- Meta Events Manager: "Test Events" tool to confirm CAPI events arrive. Compare match rate before/after sGTM.
- Google Ads: "Conversion Diagnostics" — observe Enhanced Conversions match rate climbing.
Expected improvements (4-6 weeks in)
- GA4 vs Google Ads conversion gap shrinks from 20-30% to 5-10%.
- Enhanced Conversions match rate rises from 45-55% to 70-80%.
- Page LCP improves 0.3-0.8s.
- Meta CAPI match quality climbs to 6-8.
// relatedRelated glossary terms.
Quick definitions for the concepts referenced in this guide:
Server-side measurement = better decisions.
When 20-40% measurement error skews ROAS, betting budget on it is risky. Post-sGTM, d-lens reads server events directly — real conversion counts, real ROAS.