Server-Side Container Architecture
Server-side container architecture is more powerful than client-side but requires deliberate design. This module covers the hosting, the components, and the architecture decisions that determine cost and capability.
What you will learn
- Server-side container architecture in detail
- Cloud hosting: Google Cloud Run, AWS, self-hosted
- Subdomain setup and first-party data flow
- Clients, tags, triggers, variables in the server container
- The GA4 client and the Web Container client
- Custom clients for non-Google events
- Data enrichment in transit
- Filtering, transformation, redaction
- Logging and monitoring
- Cost optimization at scale
- Common architecture mistakes
1. Server-side container architecture
A server-side container is a server (or serverless function) running Google Tag Manager's server logic. It receives HTTP requests from clients, processes them through tags, and sends data to destinations.
2. Cloud hosting
- Google Cloud Run: The reference platform; Google's recommended setup.
- Stape: Managed Cloud Run with simpler UI.
- AWS / Azure: Possible via Docker container.
- Self-hosted: On VPS or on-prem (more setup, more control).
3. Subdomain setup
Best practice: route requests through your own subdomain (analytics.yourdomain.com or similar). Benefits:
- First-party cookie domain.
- Avoids ad-blocker domain blocklists.
- Improves data persistence in Safari.
- Brand control over the request URL.
4. Container objects
- Clients: Listen for incoming requests (GA4 Client, Web Container client, custom clients).
- Triggers: Same concept as web container, server-side.
- Variables: Server-side data references.
- Tags: Send data to destinations.
5. The GA4 and Web Container clients
The GA4 client receives data from gtag.js / GA4 events. The Web Container client receives data from a client-side tag manager. Most production setups use both.
6. Custom clients
Custom clients enable bespoke event collection. Example: a backend system sends purchase events server-to-server; a custom client receives them and forwards to vendors.
7. Data enrichment
Server-side processing can enrich events with: server-side user IDs, customer data from CDP, normalized product data, hashed PII for vendor matching.
8. Filtering and redaction
- Drop events that should not be sent to specific vendors.
- Strip PII before forwarding.
- Apply consent-mode rules server-side.
- Normalize event names across vendors.
9. Logging and monitoring
- Cloud Run logs for debugging.
- Vendor delivery success rates.
- Event volume monitoring.
- Latency monitoring.
- Alerts on data anomalies.
10. Cost optimization
- Cloud Run autoscaling: pay only when handling requests.
- Min-instance tuning.
- Event batching where vendors support it.
- Concurrency settings.
11. Common mistakes
Sources & further reading
- Google sGTM developer docs
- Stape
- Simo Ahava sGTM articles
- MeasureSchool sGTM guides
- Google Cloud Run docs
- Analytics Mania sGTM
- BounceX server-side guides
- Playbook of the Month (Loves Data)
- Bounteous sGTM resources
- DMI server-side
- Books: Yehoshua Coren, Web Analytics 2.0; Avinash Kaushik essays
- MeasureCamp talks (recorded)
Part of the GTM Server-Side series · RGM Training