我在一个页面中有一个广告和一个链接,如下所示:
<!DOCTYPE html>
<head profile="http://www.w3.org/1999/xhtml/vocab">
<title>DPT - Asynchronous + Single Rest Architecture</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.pubads().enableAsyncRendering();
googletag.defineSlot('/1001256/Home_Top_Leaderboard_728x90', [728, 90], 'div-gpt-ad-1342320102476-72').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<div id="div-gpt-ad-1342320102476-72" style="width:728px; height:90px;">
<script type="text/javascript">
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1342320102476-72'); });
</script>
</div>
<a id="refresh" href="#">Refresh ad</a>
<script type='text/javascript'>
(function ($) {
$('#refresh').click(function() {
googletag.cmd.push(googletag.pubads().refresh());
return false;
});
})(jQuery);
</script>
</body>
</html>
当我第一次点击这个链接时,广告就会刷新。其他时候什么都不会发生。即使只是在Firebug等中调用refresh()方法,在第一次之后也不会做任何事情。
上面的内容有什么问题?
发布于 2014-05-16 23:30:54
根据https://support.google.com/dfp_premium/answer/4578089的说法,刷新函数接受adSlots数组的参数:
googletag.pubads().refresh([gptAdSlots[0], gptAdSlots[1]]);
这会改变你的行为吗?
如果做不到这一点,我建议您通过向查询字符串添加google_console
或googfc
参数(有关详细信息,请参阅https://support.google.com/dfp_sb/answer/181070?hl=en )并检查错误来启用Google Publisher控制台
发布于 2015-01-14 07:00:53
这就是问题的根源。
googletag.pubads().enableSingleRequest();
停止使用singlerequest模式,您可以毫无问题地调用googletag.pubads().refresh()。找不到任何文档来解释这一点。
发布于 2017-04-28 16:43:32
试试看:
googletag.pubads().refresh(null, {changeCorrelator: false});
来自https://developers.google.com/doubleclick-gpt/reference
获取并显示页面上特定或所有位置的新广告。仅适用于异步渲染模式。为了在所有浏览器中都能正常运行,在调用refresh之前必须先调用以显示广告时段。如果省略了对display的调用,则刷新可能会出现意外行为。如果需要,可以使用disableInitialLoad方法来停止display获取广告。
和:
与此刷新呼叫关联的
配置选项。changeCorrelator指定是否要为获取广告生成新的相关器。我们的广告服务器短暂地维护这个相关器的值(当前为30秒,但可能会发生变化),这样,具有相同相关器的请求在一起接收时将被视为单个页面视图。默认情况下,每次刷新都会生成一个新的相关器。
我希望它至少能帮上一点忙。
https://stackoverflow.com/questions/12170327
复制相似问题