// 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', '{id}', { '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', '{id}', { 'cookie_domain': 'auto', 'page_location': e.target.document.URL// to send the pageview with the new SPA changed URL }); }, false);