Server-Side Google Tag Manager (sGTM) Setup & Stape Architecture Guide
Step-by-step technical guide to deploying Server-Side Google Tag Manager (sGTM) on Stape with a custom first-party subdomain, GA4 client routing, and QA verification.
Syed Yasir
Conversion Tracking & Server-Side Attribution Expert
Table of Contents
Deploying Server-Side Google Tag Manager (sGTM) shifts marketing tag execution out of the visitor’s browser and onto a cloud endpoint running under your own first-party subdomain. When paired with Stape Server-Side Tracking, teams gain first-party cookie resilience, lighter browser payloads, and centralized PII governance without maintaining Kubernetes or raw Cloud Run clusters.
Core Architecture: Web GTM to Server GTM
In a production Server-Side Tracking setup, your browser container no longer talks directly to every ad vendor. Instead:
- Web GTM listens for structured
dataLayerevents and sends a single GA4-formatted HTTP stream tohttps://data.yourdomain.com. - sGTM GA4 Client parses incoming requests into a standardized Event Data object.
- sGTM Transformations strip raw PII before GA4 ingestion while passing SHA-256 hashed parameters to Meta CAPI and Google Ads.
- Server Tags fan out server-to-server requests with strict consent checks.
Step 1: Provision a Custom Subdomain on Stape
Never leave your sGTM container running on a default .stape.io or .run.app URL. Third-party domains forfeit first-party cookie benefits under Safari ITP.
Configure a dedicated subdomain such as data.yourdomain.com with an A or CNAME record provided by Stape, enable Custom Loader, and verify SSL provisioning before sending live traffic.
# Example DNS record for a first-party sGTM endpoint
Type: CNAME
Name: data
Target: your-container.stape.io
Proxy Status: DNS Only (Gray Cloud on Cloudflare so SSL validates cleanly)
Step 2: Point Your Web GA4 Tag to the Server URL
Inside Web GTM, update your Google Tag (G-XXXXXXXXXX) configuration parameter server_container_url so all GA4 events route through your first-party endpoint:
// Web GTM Google Tag Configuration Parameters
{
"server_container_url": "https://data.yourdomain.com",
"send_page_view": true,
"first_party_collection": true
}
Enable Custom Loader in Stape so gtm.js itself is served from your subdomain, reducing script blocking by privacy extensions.
Step 3: Configure Clients, Transformations & Tags in sGTM
Inside your Server GTM container:
- GA4 Client: Claim incoming
/g/collectrequests automatically. - Transformations (Exclude Parameters): Strip sensitive fields (
user_data.email_address,phone_number) from the GA4 Server tag while allowing hashed user data to reach your Meta Conversions API and Google Ads Enhanced Conversions tags. - Cookie Keeper (Optional): Enable Stape’s Cookie Keeper power-up to restore first-party identifiers across Safari sessions.
Step 4: Dual-Container Preview & QA Checklist
Before publishing live:
- Open Server GTM Preview first, then Web GTM Preview.
- Trigger a
page_view,view_item, and testpurchaseorgenerate_lead. - Verify incoming requests appear in Server Preview under
https://data.yourdomain.comwith HTTP200outgoing responses to GA4, Meta, and Google Ads. - Confirm zero PII appears in GA4 DebugView.
Need an engineer to architect or migrate your container cleanly? Explore our Server-Side Tracking Services or book a free tracking audit below.
Free Tracking Audit
Want Me to Audit Your Conversion Tracking Stack?
Book a free tracking audit. I'll review your GTM, GA4, Server-Side Tracking, Meta CAPI, Google Ads Enhanced Conversions, and Consent Mode V2 setup and highlight exactly what to fix.