GPT 广告 - 使用延迟加载时刷新失败
GPT Ads - refresh fails when using lazy load
我正在尝试对 DFP 广告使用新推出的 googletag.PubAdsService.enableLazyLoad
选项。它在初始页面加载期间工作正常,但当我尝试刷新页面上的广告时,出现以下错误:
Exception in queued GPT command TypeError: Cannot read property 'unobserve' of null
at Nt (pubads_impl_242.js:1)
at pubads_impl_242.js:1
at Object._.y (pubads_impl_242.js:1)
at Wt (pubads_impl_242.js:1)
at pubads_impl_242.js:1
at Vt (pubads_impl_242.js:1)
at _.V.$a (pubads_impl_242.js:1)
at Xu (pubads_impl_242.js:1)
at Cv (pubads_impl_242.js:1)
at wv._.h.refresh (pubads_impl_242.js:1)
这是我的代码:
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.slots = googletag.slots || {};
var mapping = googletag.sizeMapping()
.addSize([0, 0], [1000, 1])
.addSize([320, 0], [[320, 50], [300, 50]])
.addSize([1025, 0], [970, 90])
.build();
googletag.slots["push"] = googletag.defineSlot("/1234/sample/", [[970, 90], [320, 50], [300, 50]], "dfp-ad-banner")
.addService(googletag.pubads())
.setTargeting("pos", "banner")
.defineSizeMapping(mapping);
googletag.cmd.push(function() {
googletag.pubads().enableAsyncRendering();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.pubads().enableLazyLoad({fetchMarginPercent: 200,renderMarginPercent: 100,mobileScaling: 2.0});
});
googletag.enableServices();
...
googletag.cmd.push(function() {
googletag.display("dfp-ad-banner");
});
...
googletag.cmd.push(function () {
// add visibility helper classes
googletag.pubads().addEventListener('slotRenderEnded', function (event) {
var adClass = (event.size[0] > 1 && event.size[1] > 1) ? 'ad-visible' : 'ad-invisible';
$('#' + event.slot.getSlotElementId()).addClass(adClass);
});
// load ads
googletag.pubads().refresh(null, {changeCorrelator: false});
});
这是因为目前 collapseEmptyDivs
与 enableLazyLoad
不兼容。我建议删除 collapseEmptyDivs
。
在此处阅读更多相关信息 https://developers.google.com/doubleclick-gpt/reference#googletag.PubAdsService_enableLazyLoad
刷新和销毁的问题现在应该已经解决了。如果您以后 运行 遇到此类问题,请考虑从开发者参考页面发送反馈。
https://developers.google.com/doubleclick-gpt/reference
我正在尝试对 DFP 广告使用新推出的 googletag.PubAdsService.enableLazyLoad
选项。它在初始页面加载期间工作正常,但当我尝试刷新页面上的广告时,出现以下错误:
Exception in queued GPT command TypeError: Cannot read property 'unobserve' of null at Nt (pubads_impl_242.js:1) at pubads_impl_242.js:1 at Object._.y (pubads_impl_242.js:1) at Wt (pubads_impl_242.js:1) at pubads_impl_242.js:1 at Vt (pubads_impl_242.js:1) at _.V.$a (pubads_impl_242.js:1) at Xu (pubads_impl_242.js:1) at Cv (pubads_impl_242.js:1) at wv._.h.refresh (pubads_impl_242.js:1)
这是我的代码:
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.slots = googletag.slots || {};
var mapping = googletag.sizeMapping()
.addSize([0, 0], [1000, 1])
.addSize([320, 0], [[320, 50], [300, 50]])
.addSize([1025, 0], [970, 90])
.build();
googletag.slots["push"] = googletag.defineSlot("/1234/sample/", [[970, 90], [320, 50], [300, 50]], "dfp-ad-banner")
.addService(googletag.pubads())
.setTargeting("pos", "banner")
.defineSizeMapping(mapping);
googletag.cmd.push(function() {
googletag.pubads().enableAsyncRendering();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.pubads().enableLazyLoad({fetchMarginPercent: 200,renderMarginPercent: 100,mobileScaling: 2.0});
});
googletag.enableServices();
...
googletag.cmd.push(function() {
googletag.display("dfp-ad-banner");
});
...
googletag.cmd.push(function () {
// add visibility helper classes
googletag.pubads().addEventListener('slotRenderEnded', function (event) {
var adClass = (event.size[0] > 1 && event.size[1] > 1) ? 'ad-visible' : 'ad-invisible';
$('#' + event.slot.getSlotElementId()).addClass(adClass);
});
// load ads
googletag.pubads().refresh(null, {changeCorrelator: false});
});
这是因为目前 collapseEmptyDivs
与 enableLazyLoad
不兼容。我建议删除 collapseEmptyDivs
。
在此处阅读更多相关信息 https://developers.google.com/doubleclick-gpt/reference#googletag.PubAdsService_enableLazyLoad
刷新和销毁的问题现在应该已经解决了。如果您以后 运行 遇到此类问题,请考虑从开发者参考页面发送反馈。 https://developers.google.com/doubleclick-gpt/reference