Code Library
Production-correct snippets. De-identified. Module-mapped to the Advanced GTM & Server-Side Tracking course.
Filter by module:AllModule 3 · GA4 Base ConfigModule 5 · Consent Mode v2Module 6 · Server-Side GTMModule 7 · Enhanced ConversionsModule 8 · Meta CAPIModule 9 · Cross-DomainModule 10 · Ecommerce
Filter by topic:Allattributioncaddycmpconsent-mode-v2conversions-apicross-domaincustomer-eventsdatalayerdeduplicationdockerecommerceenhanced-conversionsevent_idga4gdprgoogle-adsgtmmeasurement-protocolmeta-capimeta-pixelnextjsprivacypurchaseself-hostedserver-sidesgtmsha256shopifyvps
Module 3 · GA4 Base Config
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.
ga4gtmconsent-mode-v2
Module 5 · 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-v2gtmprivacygdpr
Module 5 · Consent Mode v2
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.
consent-mode-v2gtmcmpprivacy
Module 7 · Enhanced Conversions
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.
enhanced-conversionsgoogle-adssha256gtm
Module 9 · Cross-Domain
Cross-domain linker configuration
Configure GA4 cross-domain measurement so sessions are not broken when visitors move between domains or subdomains.
ga4cross-domainattributiongtm