Google Analytics Code Updated – Asynchronous Tracking Overview

Posted by Raghavan 3 February, 2010

Google Analytics has introduced its latest tracking version termed as “Asynchronous Tracking Code”. Unlike a traditional installation, asynchronous tracking optimizes how browsers load ga.js so its impact on user experience is minimized. It allows you to add the snippet in the top of section section itself which will not delay the down the loading of the details in the page. The following snippet is the revised version of the existing code,

<script type=”text/javascript”>

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’;
(document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(ga);
})();

</script>

The first part of the asynchronous tracking code snippet assigns the _gaq variable to a JavaScript array. The second half of the snippet provides the logic that loads the tracking code in parallel with other scripts on the page. You can find the detailed info on Google Code Blog on Asynchronous Tracking.

Installation Procedure:

To make sure that your webpages use the asynchronous tracking code version follow the below process,

  • Remove the existing version of the tracking code and any customizations.
  • Insert the tracking code in the top of the <body> section
  • Replace the UA in the _setAccount to your ID.

You can add the customizations for the asynchronous tracking following the process in the usage guide and migration examples.

The advantages of Asynchornous Tracking include,

  • Speeding up overall page load time
  • Collecting more visitor data from short visits to your content- or script-heavy pages
  • Eliminating improper sequence operations between tracking user clicks and loading the tracking code
  • Enhanced data collection and accuracy.
  • Elimination of tracking errors from dependencies when the JavaScript hasn’t fully loaded.

The new version is still in Beta but this will really help you to improve the speed of your website. If you have already implemented this version of analytics or have any info on the same please share your thoughts in the comments section.

Categories : Google Tags : ,

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments
April 22, 2010

You talk about Google asynchronous tracking code. You yourself have not implemented the code… advice when you implement first.

Posted by Munaz
May 19, 2010

Hey, I'm aware of it. I have already implemented in the sites that I work and have analyzed to an extent and came up with this post. I haven't implemented in this site coz I don't have time to work on. Nothing else

Posted by raghavan8in
Leave a comment

(required)

(required)