我正在尝试在Youtube IFrame API中使用基本的onPlayerStateChange事件来跟踪Google Analytics中的开始/停止/结束。该代码在10月份工作,但现在视频将无法显示。 GA跟踪代码是相同的,我在Wordpress和Drupal中得到相同的结果。它是否改变了API?
<script>
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '461',
width: '560',
videoId: 'u1zgFlCw8Aw',
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', ‘AnyEvent’ ]); }
if (event.data ==YT.PlayerState.ENDED)
{_gaq.push(['_trackEvent', 'Videos', 'Watch to End', ‘AnyEvent’]); } }
</script>
<div id="player"></div>
答案 0 :(得分:1)
那些围绕'AnyEvent'的单引号,对吧?这不是有效的JavaScript。