Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline)
Production-ready web and server GTM container exports with deduplicated Meta CAPI, Google Enhanced Conversions, and Consent Mode v2 pre-configured.
Dual Pipeline sGTM & Meta CAPI Architecture
Client-side web events stream to a first-party Server-Side GTM proxy on Cloud Run, which normalizes payload schemas and dispatches parallel feeds to GA4 Measurement Protocol and Meta Conversions API.
Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline) Configurator
Server-Side GTM Recipe — Meta CAPI & GA4 Dual Pipeline Container JSON
Production Server-Side Google Tag Manager container architecture routing incoming /g/collect hits to BigQuery and Meta CAPI.
1 Input Parameters & Assumptions
| Parameter | Value | Context & Provenance |
|---|---|---|
| Server Container Domain | https://sgtm.gordongeraghty.com First-Party Host | Dedicated first-party server routing domain |
| GA4 Measurement ID | G-XXXXXXXXXX GA4 Stream | Google Analytics 4 target data stream ID |
| Meta Pixel ID | 123456789012345 Meta Pixel | Meta ad account target pixel identifier |
| Cookie Lifetime Days | 730 Days Lifetime | First-party server cookie duration |
2 Explicit Mathematical Formula
Dual Pipeline Routing: Incoming client hits claimed by GA4 Client Tag -> dispatched simultaneously to GA4 Server Tag & Meta CAPI Tag
Deduplication: Shared event_id parameter passed to both browser pixel and server CAPI hit
Cookie Lifetime Extension: Server-set HttpOnly FPID cookie header (Max-Age: 730 days / 63,072,000s)
Container Export: Structured GTM Server Container JSON with variables, tags, and triggers3 Computed Output Metrics
| Computed Metric | Result | Interpretation & Threshold |
|---|---|---|
| Built Server Tags | 2 Tags (GA4 + CAPI) Pipeline Tags | Consolidated server pipeline eliminating client-side duplicate tracking scripts |
| Ad-Blocker Resilience | First-Party SSL Data Loss Defense | Routing hits through custom subdomain bypasses browser-level DNS/URL blocking lists |
| Export Format | GTM Server Container JSON Container File | Production-ready JSON file for direct import into Google Tag Manager Admin |
Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline) — Scope & Limitations
Explicit operational boundaries and constraints defining target use cases and out-of-scope scenarios.
Built For (Target Use Cases)
- Generating a downloadable GTM Server Container JSON with GA4 Client and Meta Conversions API tags.
- Configuring the server domain, GA4 Measurement ID, Meta Pixel ID, and cookie lifetime before export.
- Producing an importable container export version 2 JSON matching Google Tag Manager's server container format.
Not Built For (Limitations & Out-of-Scope)
- Deploying or hosting the server-side GTM container; this only produces the importable JSON file.
- Validating the Meta CAPI access token or GA4 Measurement ID against the live platforms.
- Configuring tags or triggers beyond the fixed GA4 Client and Meta Conversions API pair.
Operational Assumptions & Defaults
- The Meta CAPI access token is stored and shared in plain text within the copyable permalink.
- Cookie Lifetime Days accepts any typed number; the 1-730 field limits are not enforced in state.
- Assumes exactly one GA4 tag and one Meta CAPI tag per container, with no multi-pixel support.
Server GTM Container Recipe Customizer
sGTM v2 Export ReadyGenerate an importable Google Tag Manager Server container configuration (.json) tailored with your GA4 Measurement IDs, Meta Conversions API credentials, and ITP cookie preserver variables.
Container Variables
GTM Server Container JSON
Recipe Manifest
{
"exportFormatVersion": 2,
"exportTime": "",
"containerVersion": {
"container": {
"publicId": "GTM-SGTM001",
"name": "Server Container (GTM-SGTM001)",
"usageContext": [
"SERVER"
]
},
"variable": [
{
"name": "Server Domain",
"type": "c",
"parameter": [
{
"type": "template",
"key": "value",
"value": "https://sgtm.gordongeraghty.com"
}
]
},
{
"name": "Cookie Lifetime Days",
"type": "c",
"parameter": [
{
"type": "template",
"key": "value",
"value": "730"
}
]
},
{
"name": "GA4 Measurement ID",
"type": "c",
"parameter": [
{
"type": "template",
"key": "value",
"value": "G-GG12345678"
}
]
},
{
"name": "Meta Pixel ID",
"type": "c",
"parameter": [
{
"type": "template",
"key": "value",
"value": "123456789012345"
}
]
},
{
"name": "Meta CAPI Access Token",
"type": "c",
"parameter": [
{
"type": "template",
"key": "value",
"value": "YOUR_TOKEN_HERE"
}
]
}
],
"tag": [
{
"name": "GA4 Client Tag",
"type": "ga4_server",
"parameter": [
{
"type": "template",
"key": "measurementId",
"value": "{{GA4 Measurement ID}}"
},
{
"type": "boolean",
"key": "sendEcommerceData",
"value": "true"
}
]
},
{
"name": "Meta Conversions API Tag",
"type": "meta_capi",
"parameter": [
{
"type": "template",
"key": "pixelId",
"value": "{{Meta Pixel ID}}"
},
{
"type": "template",
"key": "apiAccessToken",
"value": "{{Meta CAPI Access Token}}"
}
]
}
],
"client": [
{
"name": "GA4 Client",
"type": "ga4_client",
"priority": 10,
"parameter": [
{
"type": "template",
"key": "defaultPath",
"value": "/g/collect"
}
]
}
]
}
}Ready for GTM Admin > Import Container. Meta CAPI token redacted — paste yours after import.
Deploy sGTM Container Recipe & Client Tag
Import the customized container JSON export into your GTM Server Container (Admin > Import Container > Overwrite/Merge) and inject the client-side transport tag snippet on your origin site.
Architecture Overview & Deduplication Pipeline
This package provides importable web and server GTM container exports to prevent browser signal loss and match browser pixels with Meta Conversions API (CAPI) events.
Key Technical Inclusions
1. Dual-pipeline event routing with deterministic event_id generation. 2. First-party user_data SHA-256 normalisation (E.164 phone and lowercased email). 3. Consent Mode v2 monitoring reading the gcd and gcs parameters. 4. Pre-built CMP bridges for OneTrust, Cookiebot and Termly.
Implementation Code & Script
Client-side dataLayer push format supporting event_id deduplication and SHA-256 Enhanced Conversions user_data.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'purchase',
event_id: 'order_' + orderId + '_' + Date.now(), // Shared event_id for browser and CAPI dedup
ecommerce: {
transaction_id: orderId,
value: 120.00,
currency: 'AUD',
tax: 10.91,
shipping: 10.00,
items: [
{
item_id: 'SKU_12345',
item_name: 'Performance Running Shoe',
item_category: 'Footwear',
price: 120.00,
quantity: 1
}
]
},
user_data: {
email: 'customer@example.com.au', // Automatically lowercased and trimmed by sGTM variable
phone: '+61412345678', // Formatted in international E.164 standard
address: {
first_name: 'Alex',
last_name: 'Smith',
postal_code: '3121',
country: 'AU'
}
}
});Downloadable Package Assets & Templates
Production-ready Google Tag Manager server container JSON export. Import directly into GTM (Admin > Import Container) to deploy deduplicated Meta CAPI purchase tracking and GA4 server client routing.
QA & Server-Side Verification Guide
Validate incoming HTTP POST requests in sGTM Preview mode, check deduplication in Meta Events Manager, and verify GA4 Realtime streaming.
Pre-Production Verification Checklist
Ensure all hits to https://sgtm.yourdomain.com/g/collect return HTTP 200 or 204 with Set-Cookie headers.
Verify that identical event_id strings are sent in both browser Meta Pixel and sGTM Meta CAPI payloads.
Ensure email and phone fields are normalized (lowercase, trimmed, E.164) and hex SHA-256 hashed before dispatch.
Inspect Set-Cookie headers for _ga and _fbp to confirm expiration exceeds Safari 24-hour CNAME cloaking caps.
Terminal Diagnostic & Debug Commands
Returns HTTP 200 "ok" when Cloud Run sGTM container is healthy and responding to traffic.
curl -I https://sgtm.example.com/healthyInspects response headers to confirm HTTP-only first-party cookie issuance.
curl -v -X POST https://sgtm.example.com/g/collect -d "v=2&tid=G-XXXXX&cid=12345.67890"Failure Remediation & Troubleshooting
Cause: Browser pixel and Server CAPI tags are generating independent timestamps or UUIDs instead of sharing one dataLayer event_id.
Fix: Generate event_id once in window.dataLayer and reference {{Event ID}} variable in both browser and server tags.
Cause: Missing Access-Control-Allow-Origin response header in Cloud Run proxy configuration.
Fix: Configure sGTM Client tag to allow wildcard or explicit origin domains in container client settings.
Cause: Server container omitted ep.* query parameter unnesting during GA4 Measurement Protocol forwarding.
Fix: Enable "Include all incoming event parameters" in GA4 Client configuration in sGTM.
How to cite and attribute this tool
MIT LicenceThis resource is free, open and un-gated under the MIT Open Source Licence. You are encouraged to use, integrate and cite it with attribution:
@misc{geraghty_sgtm_container_recipe_pack,
author = {Geraghty, Gordon},
title = {Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline)},
year = {2026},
url = {https://gordongeraghty.com/resources/gtm-analytics/sgtm-container-recipe-pack},
note = {Head of Performance Media, Empire Amplify}
}Changelog & Version History
v1.0.0Initial production release with Meta CAPI deduplication, E.164 phone normalisation and Consent Mode v2 CMP bridges.
Strategic Takeaway & Operational Guidelines
Server GTM shifts tracking execution from the user's mobile browser to dedicated Cloud Run infrastructure. This cuts page weight by 40KB+ and recovers 15-25% of conversions lost to browser privacy extensions.