Posts

Showing posts from July, 2026

GTM HTML5 Video & Audio Engagement

Published · Tags: GTM, GA4, HTML5 Video, HTML5 Audio, Brightcove, CSP, dataLayer, Event Listeners, Custom Templates, Video Engagement HTML5 <video> & <audio> Engagement Tracking in GA4 via GTM — a 2026 Refresh of a 2016 Brightcove Recipe, Built on David Vallejo's Listener Pattern Track play, pause, progress-percent, and completion for any native HTML5 <video> or <audio> element — Brightcove, self‑hosted MP4, podcasts embedded as <audio> , or anything else that ultimately renders as one of those two tags — using a single Custom HTML listener tag and a native GA4 Event tag. One CSP hash, covers both media types, no per‑vendor JavaScript. Note: This recipe is a 2026 refactor of a video‑tracking container I originally built in 2016 for a client running Brightcove — a container that, remarkably, is still live on their site today. The underlying pattern is not mine: it is a direct implementation of David Vallejo's excellent 2014 "T...

GTM User Session Counter

Persistent User Session Counter in Google Tag Manager — A Complete Recipe Track how many times each visitor has started a new session — no server-side code, no CSP SHA-256 hashes required — and use the count to trigger conversion events, popups, and personalisation logic. Published · Tags: GTM, Google Analytics 4, Cookies, Sessions, Custom Templates, JavaScript, dataLayer Most analytics setups can tell you how many sessions a user has started in total across your property, but very few can answer the question at tag-fire time: "Is this visitor on their first session? Their third? Their tenth?" This recipe wires up a fully sandboxed GTM solution that increments a persistent counter cookie on every new session, pushes the count to the dataLayer as a named event, and extends the cookie's expiry on each return visit — all without a single line of Custom HTML or any SHA-256 CSP policy changes. ⬇ Download the GTM Container JSON from Google Drive Why This Matters ...

GTM postMessage Bridge and Listener

postMessage Bridge for iframes in GTM — Sandboxed, Parameterized, and Client-ID Aware Published · Tags: GTM, Google Analytics 4, postMessage, iframe, Cross-Domain Attribution, Client ID, Sandboxed JavaScript, CSP, Pardot, Lead Generation Note: This GTM container recipe is designed to work on Google Blogger / Blogspot as well as AEM, Sitecore, WordPress, React.js, and other platforms. It bridges dataLayer events across an iframe boundary using window.postMessage() , implemented with GTM Sandboxed JavaScript Custom Templates rather than hand-rolled inline JavaScript wherever possible. The JSON can be downloaded from Google Drive below. ⬇ Download the GTM Container JSON from Google Drive A third-party iframe embedded on your page — a Pardot form, a HubSpot form, a scheduling widget, a payment step — runs its own separate browsing context with its own GTM container and its own dataLayer . Nothing that happens inside that iframe is visible to the parent page's GTM contain...

GTM URL Decoration to Transfer Attribution

Cross-Domain URL Decoration in GTM — Parameterized, Sandboxed, and Built for Down-Funnel Pages Published · Tags: GTM, Google Analytics 4, URL Decoration, UTM Parameters, Cross-Domain Attribution, Client ID, Sandboxed JavaScript, CSP, Lead Generation, iframe Note This GTM container recipe is designed to work on Google Blogger / Blogspot as well as AEM, Sitecore, WordPress, React.js, and other platforms. It decorates outbound links, forms, iframes, images, and scripts pointing at hosts you approve, using GTM Sandboxed JavaScript Custom Templates rather than hand-rolled inline JavaScript wherever possible. The JSON can be downloaded from Google Drive below. ⬇ Download the GTM Container JSON from Google Drive Years ago, Julius Fedorovicius at Analytics Mania published a technique for transferring UTM parameters from one page to another using a Custom HTML tag — solving the classic problem of losing campaign attribution the moment a visitor clicks through to a domain you don...