gpt4 book ai didi

Javascript:将 setInterval() 函数内的变量计数增加 5

转载 作者:行者123 更新时间:2023-11-28 15:46:53 25 4
gpt4 key购买 nike

我正在尝试使用 Google Analytics events更准确地跟踪在网站上花费的时间(不依赖于访问网站上另一个页面之间的时间差)。我正在使用 setInterval() 来连续触发该 GA,甚至每 5 秒一次。如何正确增加与 GA 事件数据一起发送的秒数?

  var count = 0;
setInterval(function(){
// increment "count" by 5 each time setInterval is run
ga('send', 'event', 'time', 'tracking', 'seconds', count);
}, 5000);

最佳答案

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

关于Javascript:将 setInterval() 函数内的变量计数增加 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21942872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com