1

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?

2 Answers 2

2

_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)

Sign up to request clarification or add additional context in comments.

Comments

1

As per the documentation,

  1. category: animation
  2. action: started
  3. opt_label: time_to_open (label for the action)
  4. opt_value: 15000 (Int value)
  5. opt_noninteraction: false

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);
   }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.