【问题标题】:Googletag is there a way to know when there is no ads loadedGoogletag 有没有办法知道什么时候没有加载广告
【发布时间】:2021-11-14 21:52:00
【问题描述】:
当没有广告时,我必须在我的页面上展示广告和默认图片。
googletag.defineSlot('/6355419/Travel', [250, 200], 'ad-slot-2')
.addService(googletag.pubads());
有没有办法在代码中不记录广告以显示默认图像?
【问题讨论】:
标签:
google-tag-manager
google-ads-api
google-ad-manager
【解决方案1】:
您可以使用事件侦听器,例如 slotRenderEnded(文档 here)
// This listener is called when a slot has finished rendering.
googletag.pubads().addEventListener('slotRenderEnded',
function(event) {
var slot = event.slot;
var isEmpty = event.isEmpty;
if (isEmpty) {
//add your default image
}
}
);
或者,您可能有兴趣使用googletag.content() 作为详细说明here。