【问题标题】:How to show responsive adsense ads only on mobiles devices如何仅在移动设备上显示自适应 AdSense 广告
【发布时间】:2015-03-26 19:08:53
【问题描述】:

我正在寻找一种正确的实施方法来在移动设备和桌面设备上显示/隐藏我的 adsense 广告。

现在我正在使用这种当前方法,它给我们带来 2 个控制台错误。

目前的方法是:

我们使用 2 个类“mobileShow”和“mobileno”来根据我们想要展示的位置标记广告。

因此,如果我们希望在手机上显示响应式 Adsense 代码,我们会使用 mobileshow;如果我们想在手机上隐藏大矩形广告,我们会使用 mobileno。

我们使用的代码如下:

.mobileShow {display: none;}
.mobileShow {display: inline;}
   @media only screen
   and (min-device-width : 320px)
   and (max-device-width : 480px)

.mobileno{display:none;}
   @media (max-width: 767px)

据我们所知,google adsense 政策允许 display:none 用于实现响应式布局等用途。

我们的问题是我们在 chrome 开发控制台中收到以下错误 2 次:

2 x 未捕获的错误:找不到宽度=0px 和 data-ad-format=auto adsbygoogle.js:41 的容器的响应大小

我们测试了几次我们知道上面的代码有问题。

我们正在寻找一种方法来实现当前的“解决方案”而不会出错。

如果有人帮助我们,我们将非常感激。

【问题讨论】:

  • 如果我没记错的话,Adsense 给了发布商两个选择; responsive and custom and responsive 在移动设备上工作得很好,无需处理自定义(尽管 adsense 允许这样做)。
  • 我们的 Adsense 移动实施以这种方式获得了更好的利润
  • 可能无法找到宽度为 0px 的容器的响应大小意味着您插入的格式不受 Adsense 支持。你的移动测量是什么?
  • 移动测量是什么意思?我通过上面的 css 声明了屏幕的大小。
  • adsense 有一定的广告尺寸(广告尺寸格式 = 测量,抱歉),对吧?和一个习惯和一个响应。我通常使用响应式广告格式来处理这个问题,当我在手机或平板电脑上尝试时一切正常。所以,我不需要自定义。

标签: css mobile desktop adsense


【解决方案1】:

我对完全自动的广告尺寸的结果也不满意,经过拆分测试后,我发现为自适应广告设置特定尺寸更有帮助,而且不会影响性能。

AdSense 提供了一个示例,我只是根据您的数据对其进行了调整。

<style type="text/css">
.adslot_1 { display: none; }
@media (min-width:320px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:480px) { .adslot_1 { display: none; } }
</style>
<ins class="adsbygoogle adslot_1"
    style="display:inline-block;"
    data-ad-client="ca-pub-1234"
    data-ad-slot="5678"></ins>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

【讨论】:

    【解决方案2】:

    这可能对未来的读者很有帮助:

    Cannot find a responsive size for a container of width=0px and data-ad-format=auto 是我在 AdBlock Plus 在当前网站上禁用,但不是在所有地方都禁用时从自适应 AdSense 广告中收到的错误。

    只要我选中“已在所有地方禁用”,AdSense 错误就会停止显示,并且自适应 AdSense 广告会正确显示。

    【讨论】:

      【解决方案3】:

      我认为您的代码可能是正确的,但可能需要稍作改动。 通过改变

      and (min-device-width : 320px)

      and (max-device-width : 480px)

      and (min-width : 320px)
      and (max-width : 480px)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-20
        • 1970-01-01
        • 2021-12-26
        • 1970-01-01
        • 2016-01-08
        • 2015-07-13
        • 1970-01-01
        相关资源
        最近更新 更多