2014-10-10 58 views
0
  • WordPress主題選項面板。
  • 用戶輸入無響應的AdSense代碼的textarea字段。

我需要,如果用戶輸入一個非響應AdSense代碼,該代碼可以在響應代碼轉換爲:如何使用preg_match自動轉換自適應廣告中的常規Google AdSense廣告?

NON REPONSIVE CODE:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<!-- non responsive ads --> 
<ins class="adsbygoogle" 
    style="display:inline-block;width:728px;height:90px" 
    data-ad-client="ca-pub-12345" 
    data-ad-slot="xxxxxxxxxxxxxx"></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

上面的代碼需要轉換的:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<ins class="adsbygoogle" 
style="display:block" 
data-ad-client="ca-pub-12345" 
data-ad-slot="xxxxxxxxxxxxxx" 
data-ad-format="auto"></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

我猜這項工作可以用preg_match完成,但是怎麼做?

謝謝。

+1

如何爲'.adsbygoogle'添加css規則? – Cerbrus 2014-10-10 13:35:10

+0

有趣。日Thnx – 2014-10-10 13:38:14

回答

0

你不能這樣做(據我所知)。

這(無響應)單元配置存儲在谷歌服務器上:

{ 
    "status": "ACTIVE", 
    "kind": "adsense#adUnit", 
    "code": "xxxxxxxxxxxxxx", 
    "name": "non responsive ads", 
    "savedStyleId": "qwertzuiopšđžasdfghjklyxcvbnmqwerfvbgtzhnmjgbvfredcxsw", 
    "contentAdsSettings": { 
    "type": "TEXT_IMAGE", 
    "backupOption": { 
     "type": "BLANK" 
    }, 
    "size": "SIZE_728_90" 
    }, 
    "id": "ca-pub-12345:xxxxxxxxxxxxxx" 
} 

pagead2.googlesyndication.com會考慮data-ad-slot="xxxxxxxxxxxxxx"廣告請求的請求SIZE_728_90格式,你不能改變的「即時」 - 如果您需要另一個廣告單元size,則需要創建另一個廣告單元。

即使您會這麼做,它看起來像「有效」,但仍然違反了AdSense政策,並且會對您所在網站上涉及的所有AdSense帳戶和廣告投放構成風險。 (因爲「轉換」的代碼會讓你的無效廣告展示的一些百分比,和/或錯誤的請求。)

修改AdSense廣告代碼的
https://support.google.com/adsense/answer/1354736?hl=en

創建自適應廣告單元
https://support.google.com/adsense/answer/3543893?hl=en