【问题标题】:Google Auto-ads on React.js application?React.js 应用程序上的 Google 自动广告?
【发布时间】:2019-02-12 19:10:17
【问题描述】:

我有一个在 React.js 上运行的网站前端。

我在 index.html 的 head 标签中添加了下面这行代码。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

以下代码向我显示错误,“'adsbygoogle' is not defined no-undef”

componentDidMount () {
        (adsbygoogle = window.adsbygoogle || []).push({
              google_ad_client: "ca-pub-9142841210062390",
              enable_page_level_ads: true
         });
}

如何让广告显示在我的 React.js Web 应用程序上?

这适用于 Google 自动广告,而不是广告单元。

【问题讨论】:

  • @HardikModha Modha 正如我所指定的,将代码放在 componentDidMount() 中会导致我的问题。该帖子的解决方案对我没有帮助。我问的是自动广告,而不是广告单元。
  • 这个错误看起来像一个 eslint 错误,你可以用 // eslint-disable no-undef 禁用它

标签: reactjs adsense


【解决方案1】:

你必须在 reactjs 应用程序中写“window.adsbygoogle”而不是“adsbygoogle”

componentDidMount () {
    (window.adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-9142841210062390",
          enable_page_level_ads: true
     });
}

【讨论】:

    猜你喜欢
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    相关资源
    最近更新 更多