通过Google Analytics跟踪YouTube视频流量是否更简单?在整个网站中部署多个视频,创建无边框或相当自定义的浏览器似乎是一项繁琐的工作。
答案 0 :(得分:0)
YouTube有一个公开的分析API,可用于检查视频的使用情况。
答案 1 :(得分:0)
您可以使用以下代码来跟踪视频。
<script>
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '289',
width: '428',
videoId: 'VIDEO ID',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// The API will call this function when the video player is ready. Uncomment the below code to start video when ready
function onPlayerReady(event) {
// event.target.playVideo();
}
function onPlayerStateChange(event) {
var lastAction="";
switch (event.data){
case YT.PlayerState.PLAYING:
if (lastAction != 'paused'){
_gaq.push(['_trackEvent','video', 'Playing', getPercentage()]);
}
else{
lastAction = '';
}
break;
case YT.PlayerState.ENDED:
_gaq.push(['_trackEvent','video', 'Completed',getPercentage()]);
break;
case YT.PlayerState.PAUSED:
if (lastAction != 'paused'){
_gaq.push(['_trackEvent','video', 'Paused', getPercentage()]);
lastAction= "paused";
}
break;
}
}
function getPercentage()
{
var pecentage =((player.getCurrentTime()/player.getDuration())*100).toFixed();
if(pecentage > 0 && pecentage <= 25){
return "0-25%";}
else if(pecentage > 25 && pecentage <= 50){
return "25-50%";}
else if(pecentage > 50 && pecentage <= 75){
return "50-75%";}
else if(pecentage > 75){
return "75-100%";}
}
function stopVideo() {
_gaq.push(['_trackEvent','video', 'Stopped', player.getDuration()]);
player.stopVideo();
}
</script>
答案 2 :(得分:-1)
如果您可以选择在Youtube之外托管视频,那绝对是一种更好的方式。例如,http://wistia.com/可为您的用户在视频之前和之后提供显着改进的分析和更清晰,更受控制的体验。