A previous admin had tried to setup Analytics in the past, and the code was still in there. I created my own Analytics account and want to install it myself. I have a couple of questions.
I have read people say to remove the <script> tags. Can you be more specific?
Here's the code Google gives me:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-1');
</script>
Do I remove everything in bold? The line with the link to googletagmanager confuses me. How do I remove the <script> tags from that? How should it look if I'm not removing it completely?
Question 2: The old code that was in there, as well as an example posted on this site with a similar question earlier this year, is completely different than the one Google is giving me. It looks like this:
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXXX-1', 'auto');
ga('send', 'pageview');
Which one is right? I don't see that old code anywhere. Did Google change it up?
I have read people say to remove the <script> tags. Can you be more specific?
Here's the code Google gives me:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-1');
</script>
Do I remove everything in bold? The line with the link to googletagmanager confuses me. How do I remove the <script> tags from that? How should it look if I'm not removing it completely?
Question 2: The old code that was in there, as well as an example posted on this site with a similar question earlier this year, is completely different than the one Google is giving me. It looks like this:
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXXX-1', 'auto');
ga('send', 'pageview');
Which one is right? I don't see that old code anywhere. Did Google change it up?
Comment