簡體   English   中英

如何使用preg_match自動將常規Google AdSense廣告轉換為自適應廣告?

[英]How to convert a regular Google AdSense Ad in a responsive ad automatically using preg_match?

  • WordPress主題選項面板。
  • 用戶在其中輸入其非響應式AdSense代碼的textarea字段。

我需要,如果用戶輸入非響應式adsense代碼,則該代碼將按如下所示轉換為響應式代碼:

非響應性代碼:

<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來完成這項工作,但是怎么做呢?

謝謝。

你做不到(據我所知)。

該(非響應式)單元配置存儲在Google服務器上:

{
  "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=zh_CN

制作自適應廣告單元
https://support.google.com/adsense/answer/3543893?hl=zh_CN

暫無
暫無

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

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