Google Analytics script error

0

Hello, I'm having an error in the Google-generated script in Analytics. 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 the following appears:

  

Uncaught SyntaxError: Unexpected token; (index): 12

This line 12 is exactly this:

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

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

    
asked by anonymous 01.12.2018 / 12:29

1 answer

0

Try 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');

    
01.12.2018 / 13:00