google dfp pubads().refresh() not working as expected

99封情书 提交于 2019-12-03 11:21:42
dinie

I'm also having the same problem. I haven't got my ads to refresh yet, but I should suggest that you don't need to redeclare your ad slot in changeAd().

Instead of:

googletag.cmd.push(function () {
    googletag.pubads().enableAsyncRendering();
    googletag.defineSlot("/69003153/myad1", [728, 90], "div-1").addService         (googletag.pubads());
    googletag.defineSlot("/69003153/myad2", [300, 250], "div-2").addService    (googletag.pubads());
    googletag.enableServices();
});

Try:

googletag.cmd.push(function () {
    googletag.pubads().enableAsyncRendering();
    slot1 = googletag.defineSlot("/69003153/myad1", [728, 90], "div-1").addService         (googletag.pubads());
    slot2 = googletag.defineSlot("/69003153/myad2", [300, 250], "div-2").addService    (googletag.pubads());
    googletag.enableServices();
});

Declaring them without 'var' preceding them makes the slots global in scope. In your changeAd() function, simply call

googletag.pubads().refresh([slot1]);

I'm not even sure if you need to place that inside googletag.cmd.push()

When I execute it this way, my ads still dont refresh, but running console.log(slot1) shows that the ad slot is alive and kicking...

Can anyone else help further?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!