使用Google Analytics跟踪嵌入的YouTube视频



我试图找出最简单的方法来检查有多少用户观看嵌入的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

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

您可以使用

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

但是,这假设相关视频属于您自己的帐户,因为您无法将YouTube分析用于任意帐户中的视频。

我相信

插件使用事件跟踪,你会在这里找到很多信息:https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#Anatomy<</p>

div class="one_answers">

只需在 html 中添加代码,然后替换 将您的 GA 跟踪 ID 输入您的 GA 跟踪 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>

相关内容

  • 没有找到相关文章

最新更新