Posts

Showing posts from March, 2026

Using GTM to Decorate Link URLs for Improved Campaign Measurement

Published · Tags: GTM, Google Analytics 4, UTM Parameters, Iframe CRM, Pardot, HubSpot, Cookies, Cross-Domain Measurement, Client ID An iframe-embedded CRM form — the kind Pardot and HubSpot both commonly use — is treated by the browser as a completely separate document from the page that hosts it. That separation breaks campaign attribution the moment a visitor's UTM values and anonymous client ID need to follow them from the parent page into the form. This recipe decorates the iframe's own internal links with that information so the CRM can "see" it. This builds directly on an earlier post, "Write URL query strings 2 cookies," which persists incoming campaign values to first-party cookies. As with the UTM-to-CRM recipe, the underlying inspiration traces back to Julius Fedorovicius' "Transfer UTM Parameters From One Page To Another with GTM." This particular example targets a Pardot or HubSpot iframe lead-generation form specifically. ...

Parse Gtag Ordered dataLayer Array to Find Object by Index

Parse Gtag Ordered dataLayer Array to Find Object by Index — A GTM Variable Recipe Without Custom JavaScript Published · Tags: GTM, dataLayer, gtag, Command Queue Syntax, Sandboxed JavaScript, Custom Template, Meta Pixel, Ecommerce, CSP I was recently asked to send the currency and amount from a purchase event to Meta / Facebook using just GTM and the data already available in the dataLayer. The catch: the purchase event wasn't pushed in the flat, named-key shape GTM's built-in dataLayer variable expects. It was pushed the way gtag() pushes everything — as an ordered, numerically-indexed array. Reading a value out of that array by name doesn't work, because there is no name; there's only position. Why gtag() Pushes Arrays Instead of Objects gtag() is a thin wrapper around dataLayer.push() . When you call gtag('event', 'purchase', {...}) , the function doesn't push a single object shaped like { event: 'purchase', ... } . It pushes ...