簡體   English   中英

如何在一個頁面中多次顯示Google廣告單元?

[英]How to display google ad unit multiple times in a single page?

我想在一個頁面中多次顯示相同的廣告單元。 只有第一個廣告位在第一次工作。 當我單擊刷新按鈕時,會出現第二個插槽。 我怎樣才能使它工作?

這是我的代碼:

<!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=zh-CN&ref_topic=1651546

通過谷歌adsense TOS一個廣告單元每頁只能顯示一次。

您只需創建3個具有相同參數的廣告單元即可

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM