【问题标题】:Set max height of Adsense responsive ad unit设置 Adsense 自适应广告单元的最大高度
【发布时间】:2021-10-23 00:01:11
【问题描述】:

我的网站右侧栏中有 2 个 (300x250) Adsense 广告单元

我已将网站设为自适应,并将这些广告单元替换为 Adsense 自适应广告单元。

我现在遇到的问题是 Adsense 现在提供 2 x (300x600) 广告单元。 Adsense TOS 规定您每页只能投放 1 个 (300x600) 广告单元

最大宽度显然被 adsense 响应式广告单元占用了。

但是当我尝试将父 div 的最大高度设置为 250 像素以限制每页 300x600 广告的数量时,最大高度会被忽略,而 adsense 仍然显示 300x600

有其他人遇到过这个问题吗?如果有,您是如何设置自适应广告单元的最大高度的?

提前致谢,

凯斯

【问题讨论】:

    标签: css responsive-design adsense


    【解决方案1】:

    您可以将data-ad-format="auto" 更改为data-ad-format="rectangle"。 (请参阅高级功能 > Horizontal shape example。)

    我认为你应该在父 div 上定义 height (max-height)。

    广告高度(自动)由adsbygoogle.js(即智能尺寸)确定,如果您想控制广告高度,您需要使用data-ad-format( “矩形”、“垂直”、“水平”或您的 preferred combination,例如“矩形、水平”)。

    或者(不推荐)您可以“降级”广告代码(通过删除data-ad-format 属性),然后使用@@ 指定确切 尺寸987654335@ 查询。 (见Exact size example。)


    编辑 - Google 更新了“About responsive ad units”页面上的“技术注意事项”部分。

    在某些情况下,您需要采取额外措施 使自适应广告单元正常工作:

    ...

    父容器的高度固定或有限。不应将响应式广告放置在具有固定或有限高度的容器内, 因为它们在某些设备或浏览器上可能更高。如果你需要 限制自适应广告的高度,您需要修改 代码并使用 CSS 媒体查询来设置父级的高度 容器。了解如何modify your responsive ad unit

    【讨论】:

    • 很高兴我找到了这个。我正在考虑做一些疯狂的 Javascript 尺寸检测来提供不同的广告单元,因为我无法忍受看到那些方形广告。谢谢!
    • data-ad-format 仅影响桌面分辨率 support.google.com/adsense/answer/9183460
    • 注意。您必须为父 div 设置高度以保留空间并避免布局移位。否则你的 CLS 分数会变红,我说的是核心生命体征。
    【解决方案2】:

    我刚刚设法解决了这个问题 - 您可以为数据广告格式设置一个逗号分隔的列表。

    data-ad-format="rectangle, horizontal"
    

    如果您已将媒体查询设置为特定尺寸,这会将移动广告设置为水平,而将桌面设置为矩形。

    谢谢, 韦西维格

    【讨论】:

      【解决方案3】:

      2020 年 10 月为我工作:

      <ins class="adsbygoogle"
           style="display:inline-block;min-width:320px;max-width:970px;width:100%;height:50px"
           data-ad-client="ca-pub-xxx"
           data-ad-format="fluid"
           data-ad-slot="xxx"></ins>
      

      【讨论】:

        【解决方案4】:

        2020 年 1 月为我工作:

        1 - 禁用“移动设备自动调整大小”

        2 - 从默认值定义一个“非响应”广告(固定)

        3 - 添加您的代码并更改它的大小,为什么要使用 css。 以我为例:

        &lt;ins class="adsbygoogle" style="display:inline-block;width:100%;height:100px" data-ad-client="****" data-ad-slot="****"&gt;&lt;/ins&gt;

        使用此代码,我的广告始终占用 100% 的宽度和最大 100 像素的高度。我认为您可以添加“最小宽度”和“最大宽度”值。

        3 种情况可能会导致您在您不知情的情况下调整广告尺寸:

        1 - 如果广告是“自适应广告”

        2 - 如果“优化移动广告尺寸”参数被激活

        3 - 如果全局“自动广告”通过“优化现有广告单元?”激活设置为开启。

        【讨论】:

        • "max 100px of height" 是什么意思?这很可能总是 100px 的高度,不是吗?
        • @cbdeveloper :是的,我认为,您也可以尝试使用:“height : auto”和“max-height:100px”。
        【解决方案5】:

        要完成此操作,首先将广告容器或广告代码设置为居中。通过使用此标签:&lt;center&gt;Adsense code here&lt;/center&gt;。然后像我在下面的示例中那样设置最大高度或宽度和最小高度或宽度。


        <center>
          <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
          </script>
          <!--responsive ad -->
          <ins class="adsbygoogle" style="display:block;max-width:specify your maximum width here; max-height: set o your maximum height here; and do the same for min-height:here;min-width:here;"
              data-ad-client="ca-pub-0019"
              data-ad-slot="530000000000"
              data-ad-format="auto"></ins>
          <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
          </script>
        </center>`
        

        【讨论】:

        • 我相信 max-height 不能正常工作;他们的自适应广告可以具有未指定的高度,也可以具有固定的高度,但不能具有未指定的最大高度。与宽度不同,最大宽度可以正常工作。如果您不需要固定高度但只想保持某种近似形状,则影响高度的最佳方法是通过数据广告格式。
        【解决方案6】:

        我会选择这个:

                    style="display:inline-block;min-width:200px;max-width:300px;width:100%;height:250px"
                    data-ad-format="horizontal"></ins>
        

        谷歌自己推荐这种方式,它真的很适合我:

        https://support.google.com/adsense/answer/9467650?hl=en-GB

        【讨论】:

          【解决方案7】:

          截至 2020 年 1 月,显示的 ins 上的 max-height 似乎没有错误(如果您在父容器上执行此操作,则存在错误),所以这似乎有效(我在生产中使用它) :

          <ins class="adsbygoogle"
               style="display:block; max-height: 336px"
               data-ad-client="ca-pub-XXXXXX"
               data-ad-slot="YYYYYY"
               data-ad-format="auto"></ins>
          

          编辑:这在 2019 年 8 月正式成为可能,请参阅 https://support.google.com/adsense/answer/9467650?hl=en

          【讨论】:

          • 使用 data-full-width-responsive="true" google 不遵守高度限制。
          【解决方案8】:

          Google AdSense 支持页面中针对自适应广告提供的以下代码

          <style>
          .example_responsive_1 { width: 320px; height: 100px; }
          @media(min-width: 500px) { .example_responsive_1 { width: 468px; height: 60px; } }
          @media(min-width: 800px) { .example_responsive_1 { width: 728px; height: 90px; } }
          </style>
          <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXX11XXX9" crossorigin="anonymous"></script>
          <!-- example_responsive_1 -->
          <ins class="adsbygoogle example_responsive_1"
               style="display:inline-block"
               data-ad-client="ca-pub-XXXXXXX11XXX9"
               data-ad-slot="8XXXXX1"></ins>
          <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
          </script>
          

          更多详情可以参考这里(https://support.google.com/adsense/answer/9183363?hl=en

          【讨论】:

            【解决方案9】:

            &lt;style&gt;.example_responsive_1 { width: 320px; height: 100px; }@media(min-width: 500px) { .example_responsive_1 { width: 468px; height: 60px; } }@media(min-width: 800px) { .example_responsive_1 { width: 728px; height: 90px; } }&lt;/style&gt;&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"&gt;&lt;/script&gt;&lt;!-- example_responsive_1 --&gt;&lt;ins class="adsbygoogle example_responsive_1" style="display:inline-block" data-ad-client="ca-pub-XXXXXXX11XXX9" data-ad-slot="8XXXXX1"&gt;&lt;/ins&gt;&lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({}); &lt;/script&gt;

            试试这个

            【讨论】:

              猜你喜欢
              • 2016-01-08
              • 2015-07-13
              • 1970-01-01
              • 1970-01-01
              • 2015-03-26
              • 1970-01-01
              • 2018-09-21
              • 2023-03-23
              • 1970-01-01
              相关资源
              最近更新 更多