我在一个文件中使用googletag.cmd.push,该文件将按预期加载创意
googletag.cmd.push(function() {
console.log("pushing now from js file with " + AdServerID + " and " + AdUnit);
googletag.defineSlot('/' + AdServerID + '/' + AdUnit, [[728, 90], [800, 250]], 'div-gpt-ad-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
但是将脚本放置在文档中。像这样准备好,然后查看googlefc
$(document).ready(function() {
googletag.cmd.push(function() {
console.log("pushing now from js file with " + AdServerID + " and " + AdUnit);
googletag.defineSlot('/' + AdServerID + '/' + AdUnit, [[728, 90], [800, 250]], 'div-gpt-ad-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
总是给我一个
广告单元未获取。广告单元没有渲染。Ad fetch count: 0
不幸的是,我必须使用准备好的文档,因为首先要确定哪些槽被交付。
一开始我认为这是一个范围的问题,但几个小时后,我的脱发变得很明显…
感谢任何人可以提供的任何指示,胖的
通过禁用初始广告加载(googletag.pubads().disableInitialLoad()
)并刷新文档上的a插槽来实现:
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad(); // important
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
/** Document ready jQuery **/
$(function () {
googletag.cmd.push(function() {
var units = [];
units.push(googletag.defineSlot(/** .... your ads slots definition */);
googletag.pubads().refresh(units);
});
});