Asynchronous Google Analytics!

Google Analytics now supports Asyncronous loads, which allow the browser to continue loading content while ga.js is being loaded. Now it’s safe to put the script tag in the <head> for you XHTML STRICT junkies.

Here’s the new code to do so:

1
2
3
4
5
6
7
8
9
10
11
12
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);
})();

WordPress Plugin Update

I love this new code clip so much, I decided to write a WordpPress Plugin for it. Enjoy!

2 FEEDBACKS

  1. [...] Asynchronous Google Analytics [...]

LEAVE A COMMENT

Additional comments powered by BackType