// gtag basic snippet code do not change
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '', {
'cookie_domain': 'auto',
});
document.onreadystatechange = function () {
if (document.readyState === 'complete') {
// function call to track the new contents post SPA journey
buttonAndLinkClick();
}
}
function buttonAndLinkClick() {
document.querySelector('.button_class').addEventListener('click', (e) => {
// gtag function call to send event hit to Google Analytics along with the variables
gtag('event', 'CTA Button', {
'event_category': 'link_button_click',
'event_label': 'Submit button clicked'
});
});
// query selector to capture the anchor element i.e with class download_link
document.querySelector('.download_link').addEventListener('click', (e) => {
//gtag function call to send event hit to Google Analytics along with the variables
gtag('event', 'Link Button', {
'event_category': 'link_button_click',
'event_label': 'Download link clicked'
});
});
}
// 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', '', {
'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);
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-T5BK3BFF');