2

我试图找出检查有多少用户观看嵌入式 youtube 视频的最简单方法。以下工作正常吗?

$('.video').click(function(){
  _gaq.push(['_trackPageview', 'Video Views', 'Play', 'The Perfect Belgian Serve']);

    });

.video 是赋予 iframe 标签的类。

刚找到这个插件:

<div class="ytvid">ylLzyHk54Z0</div>
<script src="//code.jquery.com/jquery-1.7.2.js"></script>
<script src="jquery.ytiframetracker.js"></script>
<script>
  jQuery(function ($) {
    $.ytiframetracker({
      track: function (action, label, value) { // track callback
        console.log('custom tracking', action, label, value);
      }
    });
  });
</script>

https://code.google.com/p/jquery-ytiframetracker/wiki/Examples

有人能解释一下有什么行动、标签和价值吗?

4

3 回答 3

2

您可以使用 YouTube Analytics API,而不是依赖 Google Analytics 和自定义事件/跟踪:http: //developers.google.com/youtube/analytics

不过,这假设有问题的视频属于您自己的帐户,因为您不能对任意帐户中的视频使用 YouTube 分析。

于 2012-11-20T17:15:45.383 回答
1

我相信该插件使用事件跟踪,您会在这里找到大量信息:https ://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#Anatomy

于 2012-11-20T11:56:18.003 回答
0

只需在您的 html 中添加代码,然后将 Enter your GA Tracking ID 替换为您的跟踪 ID

<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
		ga('create', 'Enter your GA Tracking ID', 'auto', {'allowLinker': true});
		ga('require', 'linker');
		ga('linker:autoLink', ['instamojo.com'] );
		ga('send', 'pageview');

	
	
	 var tag = document.createElement('script');
  tag.id = 'iframe-demo';
  tag.src = 'https://www.youtube.com/iframe_api';
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  var player;
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('youTubePlayer', {
		events: {
          'onReady': onPlayerReady,
          'onStateChange': onPlayerStateChange
        }
    });
  }
  function onPlayerReady(event) {
	
  }
  function changeBorderColor(playerStatus) {
	   
    var color;
    if (playerStatus == -1) {
      color = "#37474F"; 
    } else if (playerStatus == 0) {
      color = "#FFFF00"; 
    } else if (playerStatus == 1) {
		
      color = "#33691E"; 
	  ga('send', 'event', 'Videos', 'play-videoname', 'videoname');  
	
	  
    } else if (playerStatus == 2) {
	
      color = "#DD2C00"; 
	   ga('send', 'event', 'Videos', 'Pause-videoname', 'videoname');  
	
    } else if (playerStatus == 3) { 
      color = "#AA00FF"; 
    } else if (playerStatus == 5) {
      color = "#FF6DOO"; 
    }
    if (color) {
      document.getElementById('youTubePlayer').style.borderColor = color;
    }
  }
  function onPlayerStateChange(event) {
    changeBorderColor(event.data);
  }
  
	</script>

于 2016-07-14T11:23:58.003 回答