Gomezer
Gomezer

Reputation: 5

google analytics tracking code does not look traditional nor asynchronous

Tracking on GA is working well as far as I can tell, but I have some doubts because filters are not working when I set them up.

I've noticed that my tracking code is different than the normal traditional and Asynchronous code...

i.e: Traditional:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
 <script type="text/javascript"> 
try{var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}

Asynchronous: `

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

`

My Code:

    <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','//www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-XXXXXX-X', 'XXXXXXX.com');
      ga('send', 'pageview');

   </script>

I've tried searching for this on google, to no avail (maybe I didn't search long enough).

I'd like to know if this is normal or I messed up somewhere in the setup process...

Thanks in advance!

Upvotes: 0

Views: 2009

Answers (1)

hunter
hunter

Reputation: 63522

It is the newer configuration for Google Analytics

https://developers.google.com/analytics/devguides/collection/analyticsjs/

The analytics.js JavaScript snippet is a new way to measure how users interact with your website. It is similar to the previous tracking code, ga.js, but offers more flexibility for developers to customize their implementations.

Upvotes: 2

Related Questions