Google Analytics Launches Asynchronous Javascript Tracking for Better Performance and more

By Angsuman Chakraborty, Gaea News Network
Tuesday, December 1, 2009

The key benefits of the new Google Analytics Tracking code are:

  • Faster tracking code load times for your web pages due to improved browser execution
  • Enhanced data collection & accuracy
  • Elimination of tracking errors from dependencies when the JavaScript hasn’t fully loaded

Here is the JavaScript source of the new tracking snippet:

<script type="text/javascript">

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

  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
        'https://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();

</script>

Note: Replace UA-XXXXX-X with your own code, available from your current Google Analytics Javascript snippet.

“With this feature, you can immediately store all necessary tracking
calls even before the Google Analytics tracking code is downloaded! No
more worrying about race conditions or dependency issues on the ga.js”
Google Analytics Blog

I wasn’t aware that the current Google Analytics code had “race condition” issues, were you?

The new tracking code is now in Beta and available to all Google Analytics users. Google Analytics blog recommends the new tracking code in no uncertain terms, “if you want to improve the speed of your website and the increase accuracy of your Analytics data, then we think you’ll love this new option”.

I am thinking of adding it to my sites. How about you?

Questions or Thoughts? Contact me @angsuman on twitter.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :