[removed] Increment count by 5 for a variable inside a setInterval() function

后端 未结 4 794
北海茫月
北海茫月 2021-01-27 09:02

I\'m trying to use Google Analytics events to track time spent on site more accurately (without relying on delta time between visits to another page on site). I\'m using s

相关标签:
4条回答
  • 2021-01-27 09:12

    Is this what your looking for?

    var count = 0;
    setInterval(function(){
      count = count + 5;
      // increment "count" by 5 each time setInterval is run
      ga('send', 'event', 'time', 'tracking', 'seconds', count);
    }, 5000);
    
    0 讨论(0)
  • 2021-01-27 09:12

    Not sure if I gather this correctly, but we can do this like: var count = 0,interval=5000; setInterval(function(){ // increment "count" by 5 each time setInterval is run ga('send', 'event', 'time', 'tracking', 'seconds', count+interval); }, interval);

    In clear interval you can set count = 0 again.

    0 讨论(0)
  • 2021-01-27 09:19
      var count = 0;
      setInterval(function(){
        // increment "count" by 5 each time setInterval is run
        count+=5; //is this what you need?
        ga('send', 'event', 'time', 'tracking', 'seconds', count);
      }, 5000);
    
    0 讨论(0)
  • 2021-01-27 09:32

    How about this?

    var count = 0;
    setInterval(function(){
        count+=5;
        // increment "count" by 5 each time setInterval is run
        ga('send', 'event', 'time', 'tracking', 'seconds', count);
    }, 5000);
    
    0 讨论(0)
提交回复
热议问题