【问题标题】:Vimeo API TrackingVimeo API 跟踪
【发布时间】:2018-04-19 10:04:18
【问题描述】:

我正在尝试对我们网站上的 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 调用更新时触发,这意味着我们将跟踪大量事件在谷歌分析中

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: javascript vimeo vimeo-api vimeo-player


    【解决方案1】:

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

    if (data.percent == 0.25)

    【讨论】:

    • 不止这一个。也许您还可以解释在这种情况下= 运算符会发生什么(条件评估)。
    猜你喜欢
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 2019-06-21
    • 2011-11-07
    • 2010-11-20
    • 1970-01-01
    相关资源
    最近更新 更多