How to Implement Server-Side Tracking with Google Tag Manager
Step-by-step guide to setting up server-side tracking with GTM. Recover lost conversion data, bypass ad blockers, and improve GA4 accuracy.
A GTM server container receives measurement events and controls how they are forwarded to analytics and advertising platforms. It adds a place to validate, transform, and filter events, while browser collection and consent choices still affect which events reach it.
What Server-Side Tracking Does
In a standard client-side setup, a JavaScript tag on your site sends data directly from the user's browser to Google Analytics, Meta, or any other platform. Every browser extension, privacy setting, or network restriction can interrupt that request.
With server-side tracking, your site sends a single event to your own server container. That container then forwards the event to every downstream platform — GA4, Meta CAPI, Google Ads — from the server environment. Browser restrictions can still affect the initial collection request.
The core infrastructure is a GTM server container hosted on a subdomain of your own domain, such as analytics.yourdomain.com. A custom subdomain can support first-party event routing, but cookie treatment and lifetime depend on browser policy and configuration. Server-side tagging does not guarantee a longer cookie lifetime or bypass user choices.
How to Implement Server-Side Tracking with GTM
Step 1: Create a GTM Server Container
In Google Tag Manager, create a new container and select Server as the container type. This generates a separate container from your web container — they work together but are configured independently.
You will receive a container snippet and a server URL that you will point to your hosting environment.
Step 2: Deploy the Server Container to a Cloud Host
GTM server containers need to run on a server. Google Cloud Run is the most common choice because Google pre-configures the deployment, but you can use any cloud provider that supports containers.
Deploy the container and configure it to run on a subdomain of your site:
- Set up a CNAME DNS record pointing
analytics.yourdomain.comto your cloud host - Configure SSL for the subdomain
- Verify the server URL in GTM points to your subdomain
Step 3: Update Your Web Container to Forward Events
Your existing web container tags need to be updated to send events to your server container instead of directly to GA4 or ad platforms.
Replace your standard GA4 Configuration tag with a GA4 tag that points to your server container URL. The web container sends a measurement protocol hit to your server, and the server container handles the forwarding.
Key configuration:
- Set the transport URL in your GA4 web tag to your server container URL
- Pass
client_idandsession_idas event parameters so the server container can reconstruct session context
Step 4: Configure Server-Side Tags
In the server container, create tags for each downstream destination:
- GA4 tag pointing to your GA4 Measurement ID
- Meta Conversions API tag for sending server events to Meta
- Google Ads conversion tag if you are tracking paid conversions
Each tag in the server container reads from the incoming event data and reformats it for the target platform.
Step 5: Add Consent Logic
Server-side tracking still requires consent compliance. Before sending events server-side, check that the user has consented. Use GTM's consent mode variables, or pass a consent flag as a custom parameter from your web container.
Do not send server-side events for users who have opted out — the server container does not enforce this automatically.
Step 6: Test Before Going Live
Use GTM's preview mode for both your web and server containers simultaneously. Check:
- Events appear in the server container preview
- The server container is forwarding to GA4 (visible in GA4 DebugView)
- Session attribution matches what your web container previously recorded
- No duplicate events are being sent (this is a common misconfiguration)
What to Watch Out For
Double-counting. If you migrate to server-side but leave your old web tags sending directly to GA4, you will count every event twice. Disable or remove the client-side GA4 tags once the server-side path is confirmed working.
Clock skew on events. GA4 rejects events with timestamps that are too far in the past. If your server container queues events, make sure they are forwarded promptly.
Cost of the server. A server container handling significant traffic needs appropriate compute resources. Cloud Run's autoscaling handles spikes well, but budget for it — it is not free at scale.