12 comments

[ 3.8 ms ] story [ 44.1 ms ] thread
I notice something like this in the snippet:

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

What's that all about?

That executes the code in a local scope, so that any variables defined within that block don't leak outside of its namespace.
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.

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.
The first response was perfectly adequate. Let's keep threads clean. Read other responses before responding.
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.

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.