Analytics
4.6K members online now
4.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Google Analytics tracking code: changes and backward compatibility

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

I have many websites with Google Analytics tracking working with the following code (disregard the UA-ID).

 

    <script type="text/javascript">
        (function(d,e,j,h,f,c,b){d.GoogleAnalyticsObject=f;d[f]=d[f]||function(){
		(d[f].q=d[f].q||[]).push(arguments)},d[f].l=1*new Date();c=e.createElement(j),
		b=e.getElementsByTagName(j)[0];c.async=1;c.src=h;b.parentNode.insertBefore(c,b)})
        (window,document,"script","//www.google-analytics.com/analytics.js","ga");
		
        ga("create","UA-XXXXXXXX-1​","auto");
        ga("require","linkid","linkid.js");
        ga("send","pageview");
    </script>


I then created a new website, and added the code above, modifying the UA-ID above with my new UA-ID.

 

Google Analytics did not work on the new website, whereas it was - and still is! - working on all the other websites.

 

After many hours, checking the PROPERTY SETTINGS -> TRACKING INFO -> TRACKING CODE of my new website, I saw that the code in there was slightly different:

<script>
  (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-XXXXXXXX-1', 'auto');
  ga('send', 'pageview');

</script>

So I added the enhanced link attribution part and became the following.

<script>
  (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-XXXXXXXX-1', 'auto');
  ga('require', 'linkid');
  ga('send', 'pageview');

</script>


With this code, the new website started correctly tracking the Google Analytics  events/visits.

 

I then checked all the other websites where I implemented instead the first piece of code, and noticed that they are tracking correctly Google Analytics events/visits, although also in their property settings the code suggested is the "new" piece of code I used on the new website.

I don't understand then if something was changed on the Google Analytics side, and if this code is backward compatible or not.

If it is, it should also work for my new website (but it does NOT work!).
If it is not, then why does is still work for the other websites?

I spent a lot of time on this issue and hope that someone will help me clarify that, and help others having the same problem.

Thanks a lot!

 

 

Re: Google Analytics tracking code: changes and backward compatibility

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭
UPDATE:
I forgot to mention that checking with the Google Analytics debugger on the new websites with the "old"/first piece of code, everything seemed ok (event send, parameters correct, etc.) in the Chrome console, apart from the following message, which was a WARNING though, not an error.

The tracking Id should only be of the format UA-NNNNNN-N.