【问题标题】:tracking embed video events with Youtube API - ytcfg is not defined(…)使用 Youtube API 跟踪嵌入视频事件 - 未定义 ytcfg(...)
【发布时间】:2017-04-04 22:08:00
【问题描述】:

我发现了这个tutorial,关于如何跟踪嵌入 youtube 视频的 GA 事件,并通过它编写了我的脚本:

(function ($) {
  $(document).ready(function () {

    var tag = document.createElement('script');
    tag.src = "http://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  });

  // This code is called by the YouTube API to create the player object
  function onYouTubeIframeAPIReady(event) {
    player = new YT.Player('player', {
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }

  var done = false;

  function onPlayerStateChange(event) {

    // track when user clicks to Play
    if (event.data == YT.PlayerState.PLAYING && done===false) {
      ga('send', 'event', 'Video', 'Prehratie videa', 'GE', 1);
      done = true;
    }
  }

}(jQuery));

在theme_preprocess_page() 中的每一页添加脚本。但是,我收到一个错误:

Uncaught ReferenceError: ytcfg is not defined(…)

Here 你可以读到它是 youtube 方面的一个错误。确实,在我的脚本中一切正常,我可以做些什么来让它工作吗?

【问题讨论】:

    标签: iframe google-analytics youtube-api embed


    【解决方案1】:

    嗯,这是 YouTube 部分的一个错误,现在有一个 existing bug ticket 来解决这个问题。您可以随时查看此错误票以获取有关此问题的更新。

    对于解决方法,我在YouTube Help Forum 中发现使用对象而不是 iframe。如果它适用于您的情况,您可以尝试这个临时解决方案。希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-03-29
      • 2017-04-02
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多