【问题标题】:How do you render Google ad units in localhost?您如何在 localhost 中呈现 Google 广告单元?
【发布时间】:2019-05-31 06:36:51
【问题描述】:

根据研究,2014 年有一个先前的问题 (Is Google adsense available for localhost?) 建议添加:

data-adtest="on"

在测试和阅读comments 之后,该解决方案不再有效。在广告单元中:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- responsive_ad -->
    <ins class="adsbygoogle"
        style="display:block"
        data-ad-client="ca-pub-####"
        data-ad-slot="######"
        data-ad-format="auto"
        data-adtest="on"
        data-full-width-responsive="true">
    </ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

在 Chrome、Firefox 和 Safari 中进行测试后,会呈现一个白框。搜索后,我无法在产品论坛或任何网站上找到任何解决方案。如何在 localhost 中测试广告单元?

【问题讨论】:

    标签: javascript html localhost mamp adsense


    【解决方案1】:

    我也尝试了data-adtest="on" 方法,但它对我也不起作用。我发现了两种不同的测试方法:

    如果您打开了开发者控制台,您会看到出现 403 错误。此处进一步解释了此错误的原因:https://www.shoutmeloud.com/adsense-403-forbidden-error.html。简而言之:Adsense Crawlers 拒绝 Localhost。这就是为什么你有一个空白而不是广告。

    但如果有第三种方式,我也很高兴听到它。

    【讨论】:

      【解决方案2】:

      正如另一个答案所暗示的,使用 localhost 以外的主机名很重要。使用0.0.0.0 是一个简单的选择。

      自 2021 年初以来,Google 似乎需要明确同意 TCF v2.0 才能加载任何广告。以下 sn-p 可以包含在应用程序代码或类似Violentmonkey 的内容中:

      window.__tcfapi = (command, parameter, callback) => {
          if (command === 'checkConsent') {
              callback(true);
          }
          if (command === 'addEventListener') {
              callback({eventStatus: 'tcloaded', gdprApplies: false}, true);
          }
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-20
        相关资源
        最近更新 更多