开发者

How google analytics' asynchronous api is able to track clicking links

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(['_trac开发者_如何学JAVAkEvent', '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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜