// gtag basic snippet code do not change window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); // the gtag config function to configure the measurement/property ID on the gtag tracker with other avilable settings i.e cookieDomain auto that sets the _ga cookie on the Top Level Domain of the page. // the configuration function sends a default pageview hit to Google Analytics Meaurement/Property ID i.e UA-XXXXXXXXX-X. gtag('config', 'G-N14821CVG2', { 'cookie_domain': 'auto', }); window.addEventListener('pushstate', function (e) { // the gtag config function to re-configure the measurement/property ID on the gtag tracker with other available settings i.e cookieDomain auto that sets the _ga cookie on the Top Level Domain of the page. // the configuration constructor sends a default pageview hit with the SPA journey change pageview to Google Analytics Meaurement/Property ID i.e UA-XXXXXXXXX-X. gtag('config', 'G-N14821CVG2', { 'cookie_domain': 'auto', 'page_location': e.target.document.URL// to send the pageview with the new SPA changed URL }); }, false); // ga_event listener - forwards LWC-dispatched ecommerce events (CRMPTNR-3054) to GA4. // Clears the prior ecommerce object first so item arrays don't bleed between events. // QA can append ?ga_debug=1 to the URL to tag these events for GA4 DebugView, // without needing console access. Restricted to the QA sandbox hostname so it can // never activate for real production traffic. window.addEventListener('ga_event', function (e) { dataLayer.push({ ecommerce: null }); var gaParams = e.detail.params || {}; var isQaSandbox = window.location.hostname.indexOf('--qa.sandbox') !== -1; if (isQaSandbox && window.location.search.indexOf('ga_debug=1') !== -1) { gaParams = Object.assign({}, gaParams, { debug_mode: true }); } gtag('event', e.detail.name, gaParams); });