问题描述
我正在测试YouTube iframe API,以跟踪YouTube嵌入式视频上的分析事件。 特别是我正在尝试在播放视频时获取搜索事件。
这是控件触发代码的一部分:
/* currentTime Conversion */
time = Math.round(player.getCurrentTime());
let minutes = Math.floor(time / 60);
let seconds = time - minutes * 60;
seconds = seconds < 10 ? '0' + seconds : seconds;
minutes = minutes < 10 ? '0' + minutes : minutes;
this.time = minutes + ':' + seconds;
// VIDEO IS PLAYING
} else if (playerStatus == 1) {
// Check for Seek Action
var lastTime = -1;
var interval = 1000;
var checkPlayerTime = function () {
if (lastTime != -1) {
if(player.getPlayerState() == YT.PlayerState.PLAYING ) {
//expecting 1 second interval,with 500 ms margin
if (Math.abs(player.getCurrentTime() - lastTime - 1 ) > 0.5) {
//Percentage calc
var percentage = player.getCurrentTime()/player.getDuration()*100;
roundedPercentage = Math.round(percentage);
var seek = 'SEEK - ' + roundedPercentage + '% (' + time + ')';
console.log(seek);
trackEvent('video_time_percentage',seek,videoInfo['video title'] + '_' + videoInfo['video id']);
}
}
}
lastTime = player.getCurrentTime();
setTimeout(checkPlayerTime,interval); // repeat function call in 1 second
}
setTimeout(checkPlayerTime,interval); // initial call delayed
var play = 'PLAY - ' + roundedPercentage + '% (' + time + ')';
console.log(play);
trackEvent('video_time_percentage',play,videoInfo['video title'] + '_' + videoInfo['video id']);
}
问题在于,console.log(seek)
(和数据跟踪事件)对于任何查找操作都会重复多次(请参见附件屏幕),从而在Analytics(分析)面板中返回错误的数据。
我在做什么错了,我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)