gpt4 book ai didi

javascript - Vimeo API 跟踪

转载 作者:行者123 更新时间:2023-12-03 02:03:24 24 4
gpt4 key购买 nike

我正在尝试对我们网站上的 Vimeo 视频实现一些视频跟踪。我已经完成了 Play/Finished 任务,但我还需要完成 25%、50%、75%。

这是我当前的代码

$(document).ready(function() {
var iframe = document.querySelector('#vimeo_id_0');
var player = new Vimeo.Player(iframe);

//Track videos on Play
player.on('play', function(data){
player.getVideoTitle().then(function(title) {
$('body').append('<div>Play:' + title + '</div>');
});
//ga('send', 'event', { eventCategory: 'Video', eventAction: 'Play', eventLabel: 'Video Play'});
});

//Track videos at percent played
player.on('timeupdate', function(data){
player.getVideoTitle().then(function(title) {
console.log(data.percent);
if(data.percent = 0.25) {
//25% percent
$('body').append('<div>25%' + title + '</div>');
} else if (data.percent = 0.50) {
//50% percent
$('body').append('<div>50%' + title + '</div>');
} else if (data.percent = 0.75) {
//75% percent
$('body').append('<div>75%' + title + '</div>');
}
});
});

//Track videos on End
player.on('ended', function(data){
player.getVideoTitle().then(function(title) {
$('body').append('<div>Ended:' + title + '</div>');
//ga('send', 'event', { eventCategory: 'Video', eventAction: 'Finished', eventLabel: 'Video Finished'});
});
});
});
<script src="https://player.vimeo.com/api/player.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://player.vimeo.com/video/260024854' id="vimeo_id_0" frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>

我试图得到它,所以当 timeupdate 百分比达到 0.25 时,它将触发事件,就是这样,但是它会立即开始触发,并在每次 timeupdate 调用更新时触发,这意味着我们将跟踪事件负载在 Google Analytics 中

如有任何帮助,我们将不胜感激。谢谢

最佳答案

在您的 if 语句中,您缺少另一个等号。应该是:

if (data.percent == 0.25)

关于javascript - Vimeo API 跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49918272/

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