// Define dataLayer and the gtag function. window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} // Default consent to denied console.log("enter consent denied"); gtag('consent', 'default', { 'ad_storage': 'denied', 'analytics_storage': 'denied', 'wait_for_update': 500 }); window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-Q1RKPMMYLG', { 'cookie_domain': 'auto', }); window.addEventListener('consentValues', function (event) { gtag('consent', 'update', { 'ad_storage': event.detail.Statistics, 'analytics_storage': event.detail.Statistics, }); // console.log('consent update' + JSON.stringify(event.detail)); }); // Custom script for GA - see https://github.com/salesforce-experiencecloud/privileged-script-third-party-libraries/blob/master/googleAnalytics/trackPageViews.html window.addEventListener( 'pushstate', function (e) { // console.log('enter pushStage' + 'target' + e.target.document.URL); //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-Q1RKPMMYLG', { cookie_domain: 'auto', page_location: e.target.document.URL, // to send the pageview with the new SPA changed URL }); }, false );