【问题标题】:Why Google AdSense not showing with Reactjs?为什么 Google AdSense 没有与 Reactjs 一起显示?
【发布时间】:2021-02-17 04:33:30
【问题描述】:

我正在尝试在我的 React 网站中使用 Google AdSense 实现一个简单的横幅广告。我使用了 create-react-app。

我创建了一个包装横幅的组件:

import React, { Component } from 'react';

class AdBanner extends Component {

    componentDidMount () {
        (window.adsbygoogle = window.adsbygoogle || []).push({});
        console.log('DID IT!!');
    }

    render () {
        return (
            <ins className="adsbygoogle"
                style={{ display: "block"}}
                data-ad-format="fluid"
                data-ad-layout-key="-fb+5w+4e-db+86"
                data-ad-client="ca-pub-xxxxxxxxxxxxx"
                data-ad-slot="xxxxxxxxxx">
            </ins>
        );
    }
}
export default AdBanner;

我在 index.html 文件的 &lt;head&gt; 标记中添加了以下脚本

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

## 问题## 广告没有以任何方式显示!编译器正常,浏览器在控制台中没有给出任何消息(除了“DID IT!”。我两天前在控制台中创建了广告。

我也尝试过停用 React 严格模式。

谢谢ssss

【问题讨论】:

标签: reactjs adsense


【解决方案1】:

当你说ad is not showing up - 你看到广告应该在哪里了吗?您还在网络选项卡中看到googleads.g.doubleclick.net/pagead/ads? 请求吗?如果是这样 - 有多少?如果您看到 2,则表示已发出广告请求,而可能发生的情况是 AdSense 没有找到好的广告,这是正常的。您也可以尝试将data-adtest="on" 添加到&lt;ins&gt; 标记中,这可能有助于强制投放广告。

【讨论】:

  • 是的,我看到一个空白的矩形。在 net 标签中有两次对 googleads.g.doubleclick.net/pagead/ads 的调用,我添加了 data-adtest="on",但仍然没有 Ad。
  • 嗨@NiccolòSegato,我遇到了同样的问题。你解决过这个问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-15
  • 2019-12-20
  • 2013-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多