We add the GA code to an JS file and call it from there. Here's what we've got in the <head>
tag:
<script src="/public/tail/tail.js"></script>
Here's what we've currently got in the .js file:
// Global site tag (gtag.js) - Google Analytics
dynamicLoadJs('https://www.googletagmanager.com/gtag/js?id=UA-74793602-1','async');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-849140015');
gtag('config', 'UA-74793602-1', { 'anonymize_ip': true });
However, there's obviously a problem as after a few days, I'm not getting stats through!
Any ideas what I need to change?
dynamicLoadJs
" and "async
" lead me to believe that you may be callinggtag
before the file is loaded. Are you seeing errors in console?