我想在一个页面中多次显示相同的广告单元。只有第一个广告位在第一次工作。当我单击刷新按钮时,会出现第二个插槽。我怎样才能使它发挥作用?
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Google Advertisement</title>
<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'>
var slots = {};
googletag.cmd.push(function() {
slots['sky1'] = googletag.defineSlot('4757460/Home-Above-Fold-300x250', [300, 250], 'ad-sky1').addService(googletag.pubads());
slots['sky2'] = googletag.defineSlot('4757460/Home-Above-Fold-300x250', [300, 250], 'ad-sky2').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
refreshAds = function(refresh_slots) {
if (typeof(refresh_slots) == "undefined") {
googletag.pubads().refresh();
} else {
googletag.pubads().refresh(refresh_slots);
}
};
</script>
</head>
<body>
<div>
<button onclick="javascript:refreshAds();
return false;">Refresh All</button>
<button onclick="javascript:refreshAds([slots['sky1']]);
return false;">Refresh Sky 1</button>
<button onclick="javascript:refreshAds([slots['sky2']]);
return false;">Refresh Sky 2</button>
</div>
<div id='ad-sky1' class="ad">
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.display('ad-sky1');
});
</script>
</div>
<div id='ad-sky2' class="ad">
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.display('ad-sky2');
});
</script>
</div>
</body>
</html>
要刷新广告,我已关注https://support.google.com/dfp_sb/answer/3058726?hl=en&ref_topic=1651546
答案 0 :(得分:3)
通过谷歌adsense TOS一个广告单元每页只能显示一次。
您只需创建3个具有相同参数的广告单元
即可