
Google Analytics unblocks the Web w/ Async support - alexandros
http://ajaxian.com/archives/google-analytics-unblocks-the-web-w-async-support?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ajaxian+%28Ajaxian+Blog%29&utm_content=Google+Reader
======
charlesmarshall
googles actual post about it: [http://googlecode.blogspot.com/2009/12/google-
analytics-laun...](http://googlecode.blogspot.com/2009/12/google-analytics-
launches-asynchronous.html)

------
IgorPartola
I think the NBGA API much nicer: [http://925html.com/code/non-blocking-google-
analytics-integr...](http://925html.com/code/non-blocking-google-analytics-
integration/)

I usually use an adaptation of this, to take out the extra code that supports
prototype and YUI (my choice is jQuery). This thing is super easy to use:

jQuery(document).ready(function() { ga().config({ id:'UA-xxxxxxx-x'
}).track(); });

It queues up any track calls and pushes them onto GA as soon as it loads.

~~~
enomar
That's fine if you only need _trackPageview. The Google solution provides more
capabilities though. Also, be careful of using 3rd party solution. They don't
always work correctly. The jQuery plugin for GA used to cache-bust every
request to ga.js, which definitely slows down your page.

------
Xavi
They've also moved away from document.write. Now we can use google analytics
on pages served as XHTML without resorting to these types of hacks:
[http://www.the-xavi.com/articles/operation-is-not-
supported-...](http://www.the-xavi.com/articles/operation-is-not-supported-
code-9)

------
scotth
I notice something like this in the snippet:

(function() { ... })();

What's that all about?

~~~
mcav
That executes the code in a local scope, so that any variables defined within
that block don't leak outside of its namespace.

~~~
scotth
Thanks!

------
jgrahamc
This is a good move, but I think jsHub's approach of separating the page meta-
data and the JavaScript that reads it is better.

[http://jshub.org/blog/2009/10/17/universal_tag_or_universal_...](http://jshub.org/blog/2009/10/17/universal_tag_or_universal_data/)

------
andrewljohnson
Jeez, finally...

