Skip to content

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.

By Gordon Geraghty·MIT Licence·Updated: 24 September 2026·ADVANCED
01 Prerequisites & Architecture
Stage 01 Architecture

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.

Difficulty:Advanced Architecture
Time:25–35 mins
Required Access & Permissions:
GTM Server Container AdminGCP Cloud Run / App Engine EditorMeta Events Manager AdminCustom Domain DNS Access
STEP 01Web GTM / dataLayer
Client Web TagFirst-party event dispatch to sGTM subdomain
STEP 02Google Cloud Run
sGTM Cloud ProxyITP cookie preservation & IP masking
STEP 03Transformation Client
PII NormalizationSHA-256 hashing & deduplication key match
STEP 04Graph API & Measurement Protocol
GA4 & Meta CAPIServer-to-server dual endpoint delivery
02 Interactive Configurator

Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline) Configurator

Worked Example · Deterministic Calculation

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

ParameterValueContext & Provenance
Server Container Domainhttps://sgtm.gordongeraghty.com First-Party HostDedicated first-party server routing domain
GA4 Measurement IDG-XXXXXXXXXX GA4 StreamGoogle Analytics 4 target data stream ID
Meta Pixel ID123456789012345 Meta PixelMeta ad account target pixel identifier
Cookie Lifetime Days730 Days LifetimeFirst-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 triggers

3 Computed Output Metrics

Built Server Tags2 Tags (GA4 + CAPI)Pipeline TagsConsolidated server pipeline eliminating client-side duplicate tracking scripts
Ad-Blocker ResilienceFirst-Party SSLData Loss DefenseRouting hits through custom subdomain bypasses browser-level DNS/URL blocking lists
Computed MetricResultInterpretation & Threshold
Built Server Tags2 Tags (GA4 + CAPI) Pipeline TagsConsolidated server pipeline eliminating client-side duplicate tracking scripts
Ad-Blocker ResilienceFirst-Party SSL Data Loss DefenseRouting hits through custom subdomain bypasses browser-level DNS/URL blocking lists
Export FormatGTM Server Container JSON Container FileProduction-ready JSON file for direct import into Google Tag Manager Admin

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.

INSTRUMENT BOUNDARIES

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 Ready

Generate 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

Tokens are never included in shared links or exports — paste yours after import.

GTM Server Container JSON

Recipe Manifest
Tags: 2Variables: 5Clients: 1Target: SERVER
{
  "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.

Export & Deployment Actions1-click clipboard transfer, shareable URL hash, and local file downloads.

Built by Gordon Geraghty, Head of Performance MediaZero Data Sent to Server
03 Deployment & Export

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

DataLayer Normalised Purchase Event SpecdataLayer-purchase-spec.jsjavascript

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

JSONServer-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline)v1.0.0
Download sgtm-meta-capi-recipe.json ↓

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.

04 QA & Verification Guide

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

✓
Verify HTTP Ingress Status 200/204

Ensure all hits to https://sgtm.yourdomain.com/g/collect return HTTP 200 or 204 with Set-Cookie headers.

✓
Confirm event_id Deduplication Key

Verify that identical event_id strings are sent in both browser Meta Pixel and sGTM Meta CAPI payloads.

✓
Validate SHA-256 Hashing of Customer Data

Ensure email and phone fields are normalized (lowercase, trimmed, E.164) and hex SHA-256 hashed before dispatch.

✓
Check First-Party Cookie TTL (ITP Defense)

Inspect Set-Cookie headers for _ga and _fbp to confirm expiration exceeds Safari 24-hour CNAME cloaking caps.

Terminal Diagnostic & Debug Commands

Test sGTM Health Endpointbash

Returns HTTP 200 "ok" when Cloud Run sGTM container is healthy and responding to traffic.

curl -I https://sgtm.example.com/healthy
Inspect Server-Side Set-Cookie Headersbash

Inspects 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

Issue: Meta Events Manager Warning: "Missing or Mismatched event_id"

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.

Issue: CORS Blocked on Custom sGTM Subdomain

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.

Issue: BigQuery Export Lacks Server-Enriched Parameters

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 Licence

This resource is free, open and un-gated under the MIT Open Source Licence. You are encouraged to use, integrate and cite it with attribution:

Geraghty, G. (2026). Server-Side GTM Container Recipe Pack (Meta CAPI & GA4 Dual Pipeline). Gordon Geraghty Resources Hub. https://gordongeraghty.com/resources/gtm-analytics/sgtm-container-recipe-pack
BibTeX Format
@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.