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