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 ...