【问题标题】:How to convert a regular Google AdSense Ad in a responsive ad automatically using preg_match?如何使用 preg_match 自动转换响应式广告中的常规 Google AdSense 广告?
【发布时间】:2014-10-11 17:28:10
【问题描述】:
  • WordPress 主题选项面板。
  • 用户输入其非响应式 AdSense 代码的文本区域字段。

如果用户输入非响应式 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 完成,但如何?

谢谢。

【问题讨论】:

  • .adsbygoogle添加css规则怎么样?

标签: javascript php preg-match adsense


【解决方案1】:

你不能这样做(据我所知)。

该(无响应)单元配置存储在 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=en

创建自适应广告单元
https://support.google.com/adsense/answer/3543893?hl=en

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2013-09-10
    • 2018-01-24
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    相关资源
    最近更新 更多