为什么Google AdSense无法与Reactjs一起显示?

问题描述

我正在尝试在我的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文件<head>标签添加了以下脚本

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

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

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

谢谢

解决方法

当您说ad is not showing up时-您看到应在空白处显示广告的空白矩形吗?您还会在“网络”标签中看到googleads.g.doubleclick.net/pagead/ads?个请求吗?如果是这样-多少?如果看到2,则发出广告请求,这可能是AdSense没有找到好的广告,这很正常。您还可以尝试将data-adtest="on"添加到<ins>标签中,这可能有助于强制广告。