I am trying to implement the google event tracking api into a html5 player, but for some reason it doesn't want to work.. Here is what i am doing:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-myid-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com//u/ga_debug.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
if (typeof _gaq != undefined){
_gaq.push(['_trackEvent', 'krusty-player', eventName, 'demo', 1]);
}
i copied the code from the google documentation page, so i guess it has to be right. From the Developer Console i don't see any HTTP request happening when the code runs, but when i do :
console.log(_gaq.push(['_trackEvent', 'krusty-player', eventName]));
i get a counter that goes up +1 for every time this part is called. No errors here..
i also tried using:
_trackEvent('krusty-player', eventName);
This returns error "_trackEvent is not defined"
Any idea what is going on?