Erro script Analytics Google

Asked

Viewed 74 times

0

Hello, I’m having an error in the Google generated Analytics script. Which is exactly this way:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X"></script>

    <script>

      window.dataLayer = window.dataLayer || [];

      function gtag(){dataLayer.push(arguments);}

      gtag('js', new Date());        

      gtag('config', 'UA-XXXXXXX-X');

    </script>

In the browser console appears the following:

Uncaught Syntaxerror: Unexpected token ; (index):12

That line 12 is exactly that:

window.dataLayer = window.dataLayer || [];

I can not understand the reason for this error, since I am copying what Google provided me, pasted at the beginning of the tag <head>as specified by Google.

  • Take a good look, because I’m thinking that the mistake is not in this line, because there is no mistake in it.

  • I also think that’s it, only this script is the first one to hit the head, like there’s nothing before it might be screwing up.

1 answer

0

Try with this Code:


(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-ID-ANALITCS', 'auto');
ga('send', 'pageview');

  • I have tested with this tag, but it gives error too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.