我想使用Google Analytics(而不使用API脚本格式)跟踪视频播放,而是跟踪嵌入式<iframe>
。这个选项是否可以?可以在嵌入式YouTube URL中启用JSAPI,因此每当视频单击时,它会跟踪状态更改?
当前使用这种格式跟踪Google Analytics(分析)中的玩家状态更改。
<div id="player"></div>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'fYmrMt01S1U',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
/// event.target.playVideo();
}
function onPlayerStateChange(event) {
if (event.data ==YT.PlayerState.PLAYING)
{_gaq.push(['_trackEvent', 'Videos', 'Play',
player.getVideoUrl() ]); }
if (event.data ==YT.PlayerState.PAUSED)
{_gaq.push(['_trackEvent', 'Videos', 'Paused',
player.getVideoUrl() ]); }
if (event.data ==YT.PlayerState.ENDED)
{_gaq.push(['_trackEvent', 'Videos', 'Watch to End',
player.getVideoUrl() ]); } }
// ]]>
</script>
这篇文章对如何在GA中跟踪iFrame嵌入YouTube视频有很好的描述我现在已经用它来效果了几次。