News for hackers. Stuff that matters.
Re:Google Analytics unblocks the Web w/ Async support by charlesmarshall on Wednesday December 02, 2009 @08:23AM (#971997)
Re:Google Analytics unblocks the Web w/ Async support by IgorPartola on Wednesday December 02, 2009 @10:36AM (#972210)
I think the NBGA API much nicer: http://925html.com/code/non-blocking-google-analytics-integr...

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.

Re:Google Analytics unblocks the Web w/ Async support by enomar on Wednesday December 02, 2009 @06:39PM (#973304)
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.
Re:Google Analytics unblocks the Web w/ Async support by Xavi on Wednesday December 02, 2009 @09:33AM (#972071)
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-...
Re:Google Analytics unblocks the Web w/ Async support by scotth on Wednesday December 02, 2009 @10:27AM (#972191)
I notice something like this in the snippet:

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

What's that all about?

Re:Google Analytics unblocks the Web w/ Async support by mcav on Wednesday December 02, 2009 @10:29AM (#972198)
That executes the code in a local scope, so that any variables defined within that block don't leak outside of its namespace.
Re:Google Analytics unblocks the Web w/ Async support by scotth on Wednesday December 02, 2009 @10:32AM (#972205)
Thanks!
Re:Google Analytics unblocks the Web w/ Async support by tannerburson on Wednesday December 02, 2009 @02:32PM (#972695)
Define an anonymous function that takes no arguments, and execute it without assigning it to a variable. It's often used in javascript to keep things out of the global scope.
Re:Google Analytics unblocks the Web w/ Async support by scotth on Wednesday December 02, 2009 @02:55PM (#972743)
The first response was perfectly adequate. Let's keep threads clean. Read other responses before responding.
Re:Google Analytics unblocks the Web w/ Async support by rykov on Wednesday December 02, 2009 @02:27PM (#972681)
This works even cooler when you want to minify your code:

MyLongClassName = function() {};

function(_c) { _c.prototype.method1 = ...; _c.prototype.method2 = ...; }(MyLongClassName);

This allows something like YUI compressor to shorten _c local variable for every method definition, rather than store "MyLongClassName" for each one.

Re:Google Analytics unblocks the Web w/ Async support by jgrahamc on Wednesday December 02, 2009 @08:18AM (#971986)
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_...

Re:Google Analytics unblocks the Web w/ Async support by andrewljohnson on Wednesday December 02, 2009 @02:10PM (#972639)
Jeez, finally...