How-To Guides
Skip the theory. Every recipe on this page is a self-contained problem and solution pair: here is what to push to the dataLayer, here is how to configure GTM, and here is how to verify it works.
Recipes assume you have GTM installed and a basic understanding of tags, triggers, and variables. If you need those foundations first, start with How GTM Works.
Interaction Tracking
Section titled “Interaction Tracking” Track Button Clicks CSS selectors, data attributes, and the dataLayer approach.
Track Form Submissions Native forms, AJAX forms, and multi-step forms.
Track PDF Downloads File extension regex, link click triggers, GA4 events.
Track Video Engagement YouTube, Vimeo, and HTML5 video player tracking.
Track Scroll Milestones 25%, 50%, 75%, and 90% scroll depth events.
Track Internal Search URL parameter reading and zero-results tracking.
Track Copy & Paste Clipboard API events and content identification.
Track Tab Visibility Page Visibility API for engagement measurement.
Track Exit Intent Mouse exit detection and tab-switch signals.
Track Element Visibility Intersection Observer for impressions and viewability.
Track Rage Clicks Detect frustrated rapid clicks on the same element.
Track Print Actions window.onbeforeprint and matchMedia print events.
Track Clipboard Content What users copy and from which content sections.
Track Anchor Clicks Table-of-contents jump links and same-page anchors.
Track Infinite Scroll Content consumption in feed and infinite scroll layouts.
Track Accordion & Tabs Toggle components and expanded content tracking.
Track 404 Errors 404 page visits with the requested URL captured.
Track Web Vitals Send LCP, INP, and CLS to GA4 via GTM.
Advertising & Conversion
Section titled “Advertising & Conversion” Dynamic Remarketing GA4 ecommerce dataLayer for Google Ads remarketing.
Enhanced Conversions User-provided data, hashing, and tag configuration.
Enhanced Conversions Setup Complete step-by-step Enhanced Conversions walkthrough.
Offline Conversion Import GCLID capture, backend storage, and upload via Measurement Protocol.
Duplicate Transaction Prevention Cookie and localStorage guards against double-counting purchases.
Cross-Domain & Advanced Setup
Section titled “Cross-Domain & Advanced Setup” Cross-Domain Tracking Google Tag configuration, domain lists, and referral exclusion.
Subdomain Tracking Why cross-domain is not needed, and how cookies work across subdomains.
iFrame Tracking postMessage bridge for same-origin and cross-origin iframes.
Single-Page App Tracking Virtual pageviews, dataLayer cleanup, and framework-specific code.
User-ID Implementation Server-side ID generation, GTM config, and cross-device benefits.
A/B Test Tracking Variant assignment to dataLayer, custom dimensions, user properties.
A/B Testing Without Tools Implement simple A/B tests entirely through GTM.
Fetch External Data in GTM Call external APIs from Custom HTML to enrich events.
Server-Side Shopify Tracking End-to-end sGTM setup via Stape for Shopify stores.
Privacy & Consent
Section titled “Privacy & Consent” PII Detection & Removal Regex scrubbing to strip email, phone, and SSN before events fire.
Consent Mode with Cookiebot Step-by-step Consent Mode v2 integration for Cookiebot users.
Consent Mode with CookieYes Consent Mode v2 integration for CookieYes users.
Reference
Section titled “Reference” GTM Regex Cheatsheet 30+ patterns for URL matching, file types, PII detection, and more.