views:

315

answers:

2

Hi guys, I have added to my html page the standard latest snippet to get google analytics to work:

... ...

var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-15080849-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = 'http://www.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })();

Now looking at the official 'event tracking guide' google says:

add a snippet such as: pageTracker._trackEvent('Videos', 'Play', 'Gone With the Wind');

my question is:

where is pageTracker coming from ? is it a global object in ga.js ? but if it is, why google did not tell me that they run a risk on breaking some script...

I must be missing something any help really appreciated.

+3  A: 

Hi Jeow,

You are using the async version of GA.

So your event tracking code should use that syntax. Instead of pageTracker._trackEvent('Videos', 'Play', 'Gone With the Wind');, you will want something like _gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);

Also, you can see more about the tracking method here (I can't post a second link yet):

code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html

Does this help?

Nevin
+1  A: 

The migration guide for async analytics describes how to do event tracking asynchronously: http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html#EventTracking

pageTracker is the global that most people use when using the traditional GA syntax. You don't need to use it for asynchronous GA. Instead you want:

_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
Brian
Thank you, thank you, thank you. I've been struggling with this all week.
Babak Naffas