Analytics Engineering · GTM · Server-Side Tracking
A Practical First GTM Server-Side Tracking Setup for GA4
A guide to routing GA4 events through a server-side Google Tag Manager container.
The Problem
Most analytics implementations start in the browser. A web page loads Google Tag Manager, GTM fires tags, and those tags send data directly to analytics and advertising platforms.
That client-side model is simple, but it has drawbacks. The browser has to load more third-party JavaScript. Data is sent directly from the user’s device to vendors. You have less control over what leaves the browser, how it is shaped, and which endpoints receive it.
Server-side Google Tag Manager introduces a controlled middle layer. Instead of every vendor tag firing directly from the browser, selected requests can be sent first to a server-side GTM container. That container can then validate, modify, enrich, restrict, or forward the data.
The Basic Architecture
A basic GA4 server-side setup has three moving parts:
Website
→ Web GTM container
→ Server GTM endpoint
→ GA4
The web container still exists. It collects the event from the website and sends the request to your server container. The server container receives the request, processes it using a Client, and then forwards it using a server-side Tag.
What You Need
- A Google Tag Manager web container
- A Google Tag Manager server container
- A GA4 property and web data stream
- A tagging server deployment, usually on Google Cloud Run or App Engine
- A custom tagging subdomain such as
gtm.example.com - A consent model appropriate for the site and region
Step 1: Create the Server Container
In Google Tag Manager, create a new container and choose Server as the container type. This is separate from the normal web container used on the website.
The server container is where incoming requests are received and processed. It uses a different model from web GTM. Instead of browser triggers like clicks and page views, it works with HTTP requests received by the tagging server.
Step 2: Deploy the Tagging Server
The server container needs somewhere to run. Google’s standard route is deployment to Google Cloud. For a first learning setup, the default provisioning flow is the easiest starting point.
Once deployed, Google will provide a default tagging server URL. This is useful for testing, but it should not usually be the final production endpoint.
https://gtm-server-example.a.run.app
Step 3: Add a Custom Tagging Subdomain
A production setup should use a first-party tagging subdomain. For example:
https://gtm.example.com
This makes the tagging endpoint part of your own domain structure rather than using the default cloud-generated URL. It is cleaner, more durable, and easier to manage as part of a controlled analytics setup.
Step 4: Route GA4 Requests from Web GTM
In the web GTM container, configure the Google tag or GA4 setup so that events are sent to the server container URL.
server_container_url = https://gtm.example.com
This tells the browser-side tag to send GA4 requests to the server endpoint first, rather than sending them directly to Google Analytics.
Step 5: Use the GA4 Client in Server GTM
In server-side GTM, a Client receives incoming requests and turns them into event data that tags can use.
For a basic GA4 setup, the built-in GA4 Client is the normal starting point. It listens for GA4-style requests and makes the event data available inside the server container.
Step 6: Add a GA4 Tag in the Server Container
Once the GA4 Client is receiving requests, add a GA4 tag in the server container. This forwards the processed event data to Google Analytics 4.
At its simplest, the flow becomes:
Incoming GA4 request
→ Claimed by GA4 Client
→ Converted to event data
→ Picked up by GA4 Tag
→ Sent to GA4
For a first setup, keep the server-side tag simple. Do not start by rewriting every parameter. First prove that page views and core events are flowing correctly.
Step 7: Preview and Debug
Server-side GTM has its own preview mode. This is essential because you need to verify both sides of the implementation:
- The web container is sending requests to the server endpoint
- The server container is receiving and claiming those requests
- The GA4 tag is firing in the server container
- The events are arriving in GA4 DebugView or Realtime
What Server-Side GTM Is Good For
Server-side tagging is useful where you want more control over analytics and marketing data flows.
- Reducing the amount of third-party JavaScript running in the browser
- Validating and normalising event data before it reaches vendors
- Removing or blocking unwanted parameters
- Controlling which vendors receive which events
- Improving governance around outbound tracking requests
- Using a first-party endpoint for selected analytics requests
What It Does Not Automatically Solve
Server-side GTM is sometimes described too casually as a privacy or tracking fix. That is misleading.
It does not automatically make tracking compliant. It does not automatically solve cookie consent. It does not mean all data should be sent server-side. It also introduces cloud hosting, monitoring, debugging and cost considerations.
A Sensible First Implementation
For a learning project, avoid trying to migrate every tag at once. Start with a narrow GA4 proof of concept.
1. Create server GTM container
2. Deploy tagging server
3. Add custom subdomain
4. Send GA4 page_view to server container
5. Receive event using GA4 Client
6. Forward event using GA4 server-side tag
7. Validate in GA4 DebugView
8. Add one custom event
9. Add consent-aware controls
10. Document the data flow
This keeps the build understandable. Once that works, the same pattern can be extended to additional GA4 events, Google Ads, Meta Conversions API, or other vendor endpoints.
Example Data Governance Checklist
Before publishing a server-side setup, document what the server container is doing.
- Which events are received?
- Which parameters are forwarded?
- Which parameters are removed?
- Which vendors receive data?
- Which consent state is required before forwarding?
- Who owns monitoring and maintenance?
Conclusion
Server-side Google Tag Manager is best understood as a controlled routing layer for analytics and marketing data. The browser still collects events, but selected requests are sent to a server container first. From there, data can be validated, cleaned, modified and forwarded with more control.
For a first implementation, the goal should not be complexity. The goal should be a clean GA4 route: web container to server container to GA4, with debugging, consent and documentation in place.
Real-World Example: Sending Meta Conversions API Events
Once a server-side GTM container is receiving events, the same infrastructure can be used to send advertising conversion data to platforms such as Meta.
A common setup is to send a browser event and a server event for the same conversion.
User submits lead form
→ Meta Pixel sends browser event
→ GTM Server sends CAPI event
→ Meta deduplicates both events
→ One conversion recorded
This approach allows Meta to receive both browser-side and server-side signals. The browser event provides direct client context, while the server event provides a more controlled and reliable delivery mechanism.
Why Deduplication Matters
If both the browser and server send the same conversion, Meta must know they represent the same user action.
This is achieved using a shared event_id.
event_name = Lead
event_id = lead_12345
The browser event and the server-side event both use the same event identifier. Meta uses this value to deduplicate the conversion and avoid double counting.
Typical Data Sent to Meta
A server-side Meta event often includes:
- Event name (Lead, Purchase, CompleteRegistration)
- Event timestamp
- Event ID
- Page URL
- Client IP address
- User agent
- Hashed email address (where available and permitted)
- Hashed phone number (where available and permitted)
Meta uses this information to improve event matching and attribution.
Extended Architecture
Website
→ Web GTM Container
├─ GA4 Event
│ ↓
│ GTM Server
│ ↓
│ GA4
└─ Meta Lead Event
↓
GTM Server
↓
Meta Conversions API
This demonstrates one of the main benefits of server-side GTM. A single incoming event can be governed centrally and then routed to multiple destinations using consistent business logic.
Why Organisations Move Advertising Tracking Server-Side
- Greater control over outbound data flows
- Reduced dependency on vendor JavaScript
- Centralised consent enforcement
- Improved event validation and data quality
- Single point of monitoring for analytics and advertising tags