Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Google Analytics Event Tracking broken? › Reply To: Google Analytics Event Tracking broken?
October 20, 2022 at 8:48 am
#39723
Keymaster
Oh I see the problem now, the gtag tracking code is not loaded properly. The actual gtag.js is not queued. I see you have this in your site header:
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-141577790-1');
..however this does not do anything at all, besides generating an empty gtag function. The proper integration should be:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-141577790-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-141577790-1');
</script>
You only have the second script part implemented, which is not sufficent. If you are concerned about the google pagespeed scores, then we are using a custom made implementation of this, which has 0 impact on the web vitals score, it is super fast an asynchronous:
<script>
window.dataLayer = window.dataLayer || [];
if (navigator.userAgent.indexOf("Chrome-Lighthouse") === -1) {
let _gscript = document.createElement('script'),
_gtcode = 'UA-141577790-1';
_gscript.src = 'https://www.googletagmanager.com/gtag/js?id='+_gtcode;
document.body.appendChild(_gscript);
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', _gtcode);
}
</script>