我正在尝试对我们网站上的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'});
});
});
});
&#13;
<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>
&#13;
我试图得到它所以当timeupdate百分比达到0.25时它将触发事件并且就是这样,但是它会立即开始射击并且每次更新timeupdate呼叫都会触发,这意味着我们将跟踪负载Google Analytics中的事件
任何帮助将不胜感激。感谢
答案 0 :(得分:1)
在if语句中,您缺少另一个等号。应该是:
if (data.percent == 0.25)