Why Server-Side Analytics Matter in 2026
Client-side GA4 runs JavaScript in the browser, which means it's transparent to blockers. uBlock Origin, Ghostery, Safari Intelligent Tracking Prevention, even vanilla DNS filters can intercept it. Your conversion data evaporates. Enterprise browsers block it by policy. European users lose it to ITP3+. You end up with a 30–50% data loss floor just from privacy tooling.
Server-side GTM flips the model: your site talks to YOUR server, your server talks to GA4. Ad blockers can't see the second hop. Privacy regs treat it as first-party (your domain owns the endpoint). Cost? $5–10/month on Google Cloud Run. Data loss? Near-zero. Performance? Faster than client-side because you're not shipping 40KB of GA JavaScript to every visitor.
The architecture is dead simple: visitor lands on your site → browser fires a fetch to your custom domain (analytics.yoursite.com) → Cloud Run server forwards to GA4 → GA4 sees the hit as first-party traffic. No third-party domains, no trackers list, no blockers.
How It Works — Custom Domain + Cloud Run + Measurement Protocol
// Client-side: one tiny fetch, no GA library loaded
fetch('https://analytics.yoursite.com/collect', {
method: 'POST',
body: JSON.stringify({ event: 'purchase', value: 99 })
});
// Server-side (Cloud Run): forward to GA4
// No third-party JS, just a proxy endpoint
fetch('https://www.google-analytics.com/mp/collect', {
method: 'POST',
body: measurementProtocol(clientEvent),
headers: { 'api-secret': process.env.GA_API_SECRET }
});
The browser never touches Google's servers directly. Your server owns the analytics.yoursite.com domain and proxies to GA4 using the Measurement Protocol API. From the ad blocker's perspective, you're just talking to your own infrastructure. From the privacy regulator's view, you own the data. GA4 still gets the events and builds your audience segments. Everyone wins.
Setup: One CNAME, One Cloud Run Function, One GTM Template
Step 1: DNS. Add a CNAME: analytics.yoursite.com → your Cloud Run function URL (e.g., gtm-proxy-xyz.cloudfunctions.net).
Step 2: Cloud Run function. Deploy a tiny Node function that receives the POST, extracts the measurement ID and API secret from env, and forwards to GA4. The function is roughly 20 lines of code and costs nothing until you hit 2M requests/month.
Step 3: Client-side tag. Instead of Google Analytics' 40KB script, load a 200-byte script that fires POST requests to your custom domain. That's it. No global window.dataLayer, no gtag() boilerplate, just event payloads.
Velocity X bundles a working GTM template and a starter Cloud Run function in the docs. Use it.
The Economics
Cloud Run is metered by CPU-seconds. A simple proxy function handling 1M requests/month costs roughly $2–5. Add in Cloud Logging (~$1–2) and you're at $5–10/month total. Compared to paying a SaaS analytics tool $50–500/month, that's free. Compared to watching client-side GA4 lose 40% of your data to blockers and privacy filters, that's ROI day one.
Six FAQs
Does the custom domain have to be a subdomain of my main site?
Yes, technically. If you use a separate domain, it's third-party again and blockers will filter it. analytics.yoursite.com is first-party. That's the whole point.
What if Cloud Run goes down?
Your analytics stop reporting for that window, but your site stays up — it's just an async POST. Set up failover to a secondary endpoint or add local retry queuing in the client script.
Can I still use GTM's web container?
Yes, but you're defeating the purpose. The web container is JavaScript in the browser, so blockers see it. Use the server-side container instead — it runs code on your own infrastructure, not in the browser.
Does this comply with GDPR?
Yes, because it's first-party data and you control the endpoint. You still need consent for event tracking (always, anywhere), but the data path is cleaner and more defensible than third-party GA4.
Can I see real-time data in GA4?
Yes. The Measurement Protocol feeds into GA4's real-time reporting the same way client-side events do. Dashboard lag is usually 1–2 minutes, same as normal.
What events should I track server-side vs. keep client-side?
Page views, purchases, and high-value events go server-side so they survive blockers. Scroll depth and low-priority interactions can stay client-side. Most teams do 80% server-side, 20% client for analytics coverage.
The Bottom Line
Ad blockers and privacy filters hollow out client-side analytics. Server-side GA4 via your own infrastructure keeps first-party data intact and costs $5–10/month. The performance tax is near-zero and compliance is cleaner. If you're shipping analytics for a product, not a marketing site, server-side should be your default. For deeper coverage, see our guide on offloading third-party scripts. Ready to architect a site right? Check Velocity X pricing.