0

我目前正在尝试重用我们的 tealium utag.js 创建的变量。

我们使用 tealium 来跟踪我们网页上的各种内容,我只是注意到它跟踪的一些内容使我无法为我的嵌入式 youtube 视频创建控制器,因为 utag.js 包括这些,如所述(here)[ https ://community.tealiumiq.com/t5/iQ-Tag-Management/Tracking-Video-with-Tealium-iQ/ta-p/15049]

// Tealium Tracking Code for YouTube iframe embeds
//
// Read the identifiers on the YouTube iframes. If not present, then add ids
if (jQuery('iframe[src*="youtube.com"]').length > 0) {
 var i = 0, id;
 window.iframe_id = [];
 jQuery('iframe[src*="youtube.com"]').each(function() {
   if (jQuery(this).attr('id')) {
     id = jQuery(this).attr('id');
     window.iframe_id.push(id);
   } else {
     id = 'tealium_youtube' + i;
     jQuery(this).attr('id', id);
     window.iframe_id.push(id);
     i++;
   }
 });
}

// Configure Milestones
//
function setMileStones(i) {
  // Set the intervals here as you want them reported, in % viewed, each number separated by a comma
  // If you do not want mileStones set mileStones[i] = [] ;
  mileStones[i] = [10, 25, 50, 75, 90];
}
var mileStones = [];
for (i = 0; i < window.iframe_id.length; i++) {
  setMileStones(i);
}

// Load the YouTube iframe library
//
var ytapi = document.createElement('script');
ytapi.src="https://ww" + "w.youtube" + ".com/iframe_api";
var scriptref = document.getElementsByTagName('script')[0];
scriptref.parentNode.insertBefore(ytapi, scriptref);

window.players = [];
window.onYouTubeIframeAPIReady = function() {
  // Confirm existing ID or set ID in the iframe for each video on the page
  jQuery('iframe[src*="youtube.com"]').each(function() {
  var id = jQuery(this).attr('id');
  window.players[id] = new YT.Player(id, {
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
      }
    });
  });
};

这个 utag.js 脚本已经作为标题包含在 html 中,那么为什么我不能从控制台使用 window.players[jQuery(this).attr('id')].playVideo() 开始视频?它说它不知道播放器,它是未定义的?这很奇怪,因为这个脚本是 head 的一部分,因此变量应该是“全局的?” 可用的?

4

0 回答 0