Problem wicth google Analytics snippet
Hi for using goole Ads i must include this code:
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-XXXXXXXX');
</script>
I added follow code in the Marketing script section:
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('async', true);
script.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXX');
document.body.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-XXXXXXXX');
But when i loaded the page, the browser console say: Uncaught ReferenceError: gtag is not defined
what am i doing wrong here ? how can i test if the javascript is really loaded ?