views:

40

answers:

1

If I have html like the following on my own site how come it is able to track the event? Is it possible that browser starts loading the http://google.com in the same window before the tracking request is made as it is asynchronous?

<a href="http://google.com" onclick="_gaq.push(['_trackEvent', 'category', 'event']);">click</a>

In case of using the synchronous API the browser obviously waits until the script in the onclick is ran, but I can't wrap my head around this one.

A: 

When you load the google-analytics.com/ga.js-script it replaces the array variable _gaq with an object. That object has a function named push, where all the magic is happening.

If you want to see that code you can do alert(_gaq.push) after ga.js has been loaded.

By the way, if you serve your pages compressed you might want to check out how to include the ga.js script in shortest possible way.

some
So the event tracking is synchronous after all when ga.js is loaded? It doesn't let the onclick handler return until it has got response from ga servers or what?
JtR