Google Analytics goes asynchronous !

From this month, Google provide a new Google Analytics script that works in an asynchronous way.

This has several advantages :

  • The time to load the script has less impact on the page loading time.
  • Best data recovery and so more saved visits. The visits terminated before the script loading doesn't happens anymore. Because, due to the asynchronous way of loading, we can add the analytics code in the head of the page.
  • Less tracking errors.

Voici le nouveau code à insérer dans vos pages :

  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);
  })();

We have to note that this code use the async parameter of HTML 5 and that functionality is not supported by all the browsers. If you use that script in a non HTML-5 Browser, the script will be executed exactly as the old Analytics script in an synchronous way.

That's a good news for the fans of performances.

Source : Google Analytics Launches Asynchronous Tracking

Related articles

  • 10 most useful Google Tools
  • Java 7 : New I/O features (Asynchronous operations, multicasting, random access) with JSR 203 (NIO.2)
  • Tip : The bookmarks bar disappears on Google Chrome !
  • Improve performance of your web site with Page Speed
  • Top 15 Best Wordpress Plugins
  • Asynchronous Message Passing in JR
  • Comments

    Comments powered by Disqus