// gtag basic snippet code do not change window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-9193592-1', { 'cookie_domain': 'auto', }); window.addEventListener('lwcgtag', function(event){ gtag('event', event.detail.event_action, { event_category:event.detail.event_category, event_label:event.detail.event_label }); }) 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', 'UA-9193592-1', { 'cookie_domain': 'auto', 'page_location': e.target.document.URL// to send the pageview with the new SPA changed URL }); }, false); document.onreadystatechange = function () { if (document.readyState === 'complete') { // function call to track the new contents post SPA journey buttonAndLinkClick(); } } function buttonAndLinkClick() { document.querySelector('.slds-button').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': 'Sign Up button clicked' }); }); document.querySelector('.submitButton').addEventListener('click', (e) => { // gtag function call to send event hit to Google Analytics along with the variables gtag('event', 'CTA Button', { 'event_category': 'Sign Up Submit', 'event_label': 'Sign Up Submit' }); }); document.querySelector('.back-to-top').addEventListener('click', (e) => { // gtag function call to send event hit to Google Analytics along with the variables gtag('event', 'CTA Button', { 'event_category': 'Back To Top', 'event_label': 'Back To Top' }); }); /* 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' }); });*/ }