Speed Up Google Analytics: Use Async

Wednesday, December 2nd, 2009 | Business

Saw a great post at High Performance Web Sites blog, Google Analytics goes async.  The author is Steve Souders, who works at Google on web performance.  So this is from the horses mouth.

Think about it, why would you care when the Google Analytics code is loaded?  All it does is capture data, as long as Google gets it — it may as well go out at midnight.  The new code enables an “async” request in HTML5.

The official announcement is found at Google Code blog: Google Analytics Launches Asynchronous Tracking, for those of you uncomfortable relying on someone’s blog for new code.

You can see the official guide at: Asynchronous Tracking Usage Guide

The code snippet suggested is (replacing your account number):

[html]
<script type=”text/javascript”>// <![CDATA[
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>
[/html]

The real celebration should be current browsers that actually support certain HTML 5 elements.  I had read somewhere that the HTML 5 timeline extends almost to 2020.

On a side note, Google has pretty much acknowledged that HTML 5 is the future, and NOT Google Gears.  While cool, Google Gears has some bumps ahead that are solved by HTML 5.

Related Posts

Tags: , , , , , , ,

No comments yet.

Leave a comment


Follow Me

Follow seangw on twitter

Email Subscription

Top Commentators

  • No commentators.

Archives

Categories