2016-11-24 66 views

回答

0

響應的AdSense廣告(另一種方法)

無論你設置數據的廣告格式爲「自動」或「垂直」或「水平」或豎,谷歌AdSense的算法將仍然決定要提供的廣告。例如,如果你要求一個矩形,你可以得到一箇中矩形或一個大矩形。

您是否希望強制AdSense投放特定尺寸的廣告,同時保持響應速度?您可以考慮自定義尺寸的廣告。這些廣告的大小取決於屏幕,但發佈商可以更好地控制所投放的橫幅大小。

<div id="google-ads-1"></div> 

<script type="text/javascript"> 

    /* Calculate the width of available ad space */ 
    ad = document.getElementById('google-ads-1'); 

    if (ad.getBoundingClientRect().width) { 
     adWidth = ad.getBoundingClientRect().width; // for modern browsers 
    } else { 
     adWidth = ad.offsetWidth; // for old IE 
    } 

    /* Replace ca-pub-XXX with your AdSense Publisher ID */ 
    google_ad_client = "ca-pub-XXX"; 

    /* Replace 1234567890 with the AdSense Ad Slot ID */ 
    google_ad_slot = "1234567890"; 

    /* Do not change anything after this line */ 
    if (adWidth >= 728) 
     google_ad_size = ["728", "90"]; /* Leaderboard 728x90 */ 
    else if (adWidth >= 468) 
     google_ad_size = ["468", "60"]; /* Banner (468 x 60) */ 
    else if (adWidth >= 336) 
     google_ad_size = ["336", "280"]; /* Large Rectangle (336 x 280) */ 
    else if (adWidth >= 300) 
     google_ad_size = ["300", "250"]; /* Medium Rectangle (300 x 250) */ 
    else if (adWidth >= 250) 
     google_ad_size = ["250", "250"]; /* Square (250 x 250) */ 
    else if (adWidth >= 200) 
     google_ad_size = ["200", "200"]; /* Small Square (200 x 200) */ 
    else if (adWidth >= 180) 
     google_ad_size = ["180", "150"]; /* Small Rectangle (180 x 150) */ 
    else 
     google_ad_size = ["125", "125"]; /* Button (125 x 125) */ 

    document.write (
    '<ins class="adsbygoogle" style="display:inline-block;width:' 
     + google_ad_size[0] + 'px;height:' 
     + google_ad_size[1] + 'px" data-ad-client="' 
     + google_ad_client + '" data-ad-slot="' 
     + google_ad_slot + '"></ins>' 
    ); 

    (adsbygoogle = window.adsbygoogle || []).push({}); 

</script> 

<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> 
</script> 

轉到您的AdSense信息中心,並創建新的廣告單元或使用您現有的某個廣告單元。記下您的廣告單元的ID以及AdSense發佈商ID,並將這些值粘貼到第15行和第18行。

接下來,將上面的代碼段複製粘貼到您網頁的任意位置,並根據用戶設備的大小,投放最合適的AdSense廣告。如果您希望在同一個網頁上包含多個響應式AdSense廣告單元,只需使用相同的代碼片段,但將行號爲#1 &#6的DIV ID增加一行即可使其成爲google-ads-1,google-ads-2等等。 我希望這會幫助你。

+0

我想知道,如果我顯示100個AdSense每頁 adsense不會阻止我的帳戶? http://rana.press/news/obama-trump-hold-excellent-white-house-talks –

+0

我明白了。別擔心這一點。沒有任何政策可以阻止你在每頁上放置更多的AdSense。只是不要點擊你的自我。 – knjght0011