javascript - 您如何在 localhost 中呈现 Google 广告单元?

标签 javascript html localhost mamp adsense

根据研究,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 中测试广告单元?

最佳答案

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

  • 使用 占位符 ,最Google Adsense Forum Entry 建议的方式。
    e. G。这里:https://productforums.google.com/forum/#!msg/adsense/RLeUEq6na-w/i93-TFVRiHUJ
    (我自己试过了,对解决方案很满意)
  • 使用你自己的 (开发)域 此处解释:https://medium.com/@jeffersonlicet/testing-ads-on-localhost-300215b415d6 (我无法自己尝试,因为我没有域)

  • 如果您打开了开发者控制台,您会看到出现 403 错误。此处进一步解释了此错误的原因:https://www.shoutmeloud.com/adsense-403-forbidden-error.html .简而言之: Adsense 爬虫拒绝本地主机 .这就是为什么你有一个空白而不是广告。
    但如果有第三种方式,我也会很高兴听到它。

    关于javascript - 您如何在 localhost 中呈现 Google 广告单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54043177/

    相关文章:

    python - 本地主机上的 Google App Engine GQL 查询

    javascript - 如何在自定义函数中使用 jQuery promise/deferred?

    javascript - 带有 YouTube 视频的轮播 slider

    HTML 'td' 宽度和高度

    javascript - 使用 $this 和 .find 在另一个 div 中查找一个 div

    javascript - 如何在 html5 中构建表单时显示警告标志?

    python - 使用 if 条件比较使用 python 的密码

    jquery - 使用 IP 而不是 localhost 时,IE8 jquery 调用无法正确返回

    javascript - 解析RSS命名空间媒体:Thumbnail (js/jQuery)

    javascript - Rails Controller 中的 Ajax 功能实现