Reputation: 633
i am trying to set an Analytics Event in jQuery like this
jQuery(document).ready(function() {
var time_to_open=15000;
if(readCookie('cookie')!='set'){
setTimeout(function() {
jQuery('#my_animation').animate({left: 0}, 1000);
createCookie('cookie', 'set', 1);
_gaq.push(['_trackEvent', 'animation', 'started', time_to_open]);
},time_to_open);
}
});
this should track how often an animation was shown. But it is not working. Are _trackEvent only targeting click events? Or what i am doing wrong?
Upvotes: 1
Views: 104
Reputation: 1516
As per the documentation,
Here is the sample:
jQuery(document).ready(function() {
var time_to_open = 15000;
if(readCookie('cookie') != 'set') {
var t = window.setTimeout(function() {
jQuery('#my_animation').animate({left: 0}, 1000);
createCookie('cookie', 'set', 1);
_gaq.push(['_trackEvent', 'animation', 'started', 'time_to_open', time_to_open, false]);
}, time_to_open);
}
});
Upvotes: 1
Reputation: 7177
_trackEvent
can silently fail if the opt_label parameter is not a string. Either convert time_to_open
to a string, or pass it as the opt_value
parameter.
_gaq.push(['_trackEvent', 'animation', 'started', undefined, time_to_open]);
(Google Analytics _trackEvent docs)
Upvotes: 2