Posts

Showing posts from July, 2026

Session Duration Timer in GTM

Session Duration Timer in Google Tag Manager — A Complete Recipe Using Sandboxed JS Measure seconds spent on your site per session — or across all sessions — with no CSP SHA-256 hashes, no external libraries, and a single importable container JSON. Published · Tags: GTM, Google Analytics 4, Session Duration, Cookies, dataLayer, Custom Template, JavaScript Most GTM engagement-time solutions either lean on GA4's built-in engagement time (which you can't trigger mid-session) or inject inline <script> tags that break under a strict Content Security Policy. This recipe solves both problems. It uses a GTM Sandboxed JavaScript custom template — the Session or User Seconds Duration tag — to run a per-second callLater loop that writes the running count to a first-party cookie and pushes a named dataLayer event at every tick. The result is importable in one JSON file, zero SHA-256 exemptions required. ⬇ Download the GTM Container JSON from Google Drive What's ...

GTM Form Engagement & Abandonment

Image
Form Engagement Waterfall in GTM — Visibility, Field, Submit, and Response GTM Form Engagement Waterfall: Visibility, Field, Submit & Response Four Google Analytics 4 events, one shared event name, and a single contact_step_label parameter — enough to build a true form-abandonment funnel from nothing but Google Tag Manager triggers. Published · Tags: GTM, Google Analytics 4, Form Tracking, Form Abandonment, Element Visibility, dataLayer, Funnel Exploration, GA4 Standing on the shoulders of giants. This recipe is a direct continuation of two earlier posts on this blog. The field-engagement stage below is built entirely on the generic document.addEventListener pattern that Simo Ahava first published in 2013 and that I adapted for GA4 in Listen to Any Browser Event in GTM . The element-identification logic — the coalesce chains that walk up the DOM to find a usable class, id, or label — comes straight from GTM Universal Click – No JavaScript . Neither of those posts touc...