New Google Analytics Asynchronous Code Improves Page Load Times

Google Analytics have just released their latest generation of their tracking code.  The new asynchronous tracking code uses a script that uses a “separate lane” to handle part of the processing of your webpage.  This script can process at the same time as other scripts, improving the accuracy of stats of webpages like this one that emply a lot of scripts and use a lot of rich media content, and promises faster page loading times as well.  I can’t wait to see my stats tomorrow to see if there are any big changes!

The new google analytics tracking snippet offers the following benefits:

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

More information can be found in the google analytics help section.  The actual google analytics asynchronous code that needs adding is here:
<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' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();

</script>
To use this on your pages, copy the code snippet above, replacing UA-XXXXX-X with your web property ID.