Code Library
Production-correct snippets. De-identified. Module-mapped to the Advanced GTM & Server-Side Tracking course.
GA4 base config through GTM (consent-gated)
Configure a GA4 tag in GTM that fires only when analytics_storage is granted. The correct implementation of GA4 with Consent Mode v2.
Consent Mode v2 default-deny baseline
Inject a default-deny consent baseline before GTM loads. Covers all regions globally plus an explicit EEA/UK region list.
Consent Mode v2 update on banner consent
Fire gtag consent update when a visitor accepts or rejects cookies. Covers both the granted and denied paths.
GA4 Measurement Protocol: server-side event from a Next.js route handler
Send a GA4 event directly from a Next.js route handler using the Measurement Protocol. Sessions stitch correctly when client_id is read from the _ga cookie.
Self-hosted server-side GTM on a VPS with Docker + Caddy
Deploy the Google server-side GTM tagging container on a VPS using Docker and Caddy as the reverse proxy. The advanced reference for client work, not the architecture this site uses.
Enhanced Conversions: user-provided data + SHA-256 normalised hashing
Implement Google Ads Enhanced Conversions by hashing user-provided data (email, phone, name) with SHA-256 before sending to Google.
Meta CAPI and browser Pixel deduplication via shared event_id
Prevent double-counting Meta conversions when you run both the browser Pixel and CAPI. The event_id must be identical on both sides.
Meta CAPI: server-side conversion from a Next.js route handler
Send a Meta Conversions API event from a Next.js route handler. Includes SHA-256 hashing of user data and the event_id for browser-Pixel deduplication.
Cross-domain linker configuration
Configure GA4 cross-domain measurement so sessions are not broken when visitors move between domains or subdomains.
GA4 ecommerce purchase dataLayer (generic)
The complete GA4 purchase event dataLayer push. Production-correct schema with all required and recommended parameters.
Shopify purchase dataLayer via Customer Events
Fire the GA4 purchase event from Shopify's Customer Events API (web pixels). Works with the new checkout extensibility without requiring checkout.liquid access.