ReactJS 和 Adsense 响应式广告

标签 reactjs adsense

我在 ReactJS 中与 Adsense 广告斗争了几个小时:

这是我的代码:

export default class AdJobDetail extends React.Component {
    componentDidMount() {
        (window.adsbygoogle = window.adsbygoogle || []).push({});
    }

    render() {
        return (
            <div className={style.container}>
                <ins className='adsbygoogle'
                    style={{ display: 'display:block' }}
                    data-ad-client="ca-pub-6591684000448474"
                    data-ad-slot="6458345829"
                    data-ad-format="auto" />
            </div>
        );
    }
}

(广告客户端和广告位已更改)。

这是我使用的样式:
.container {
margin-top: 20px;
border: 1px solid $light-grey;
width: 200px;
height: 200px;
}

.ins {
width: 100%;
height: 100%;
}

我不断得到:

adsbygoogle.push() error: no slot size for available width=0



我的问题是:
  • 对我来说,宽度大于 0,为什么会出现此错误?
  • 会不会是脚本没有正确挂载?但我有非响应式广告,它们运行良好...
  • 最佳答案

    您可能需要使用绝对宽度单位(例如 px )而不是相对宽度单位,例如百分比。

    关于ReactJS 和 Adsense 响应式广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45715353/

    相关文章:

    javascript - React Hooks - 无法获取更新的状态值

    reactjs - 如何将模式应用于 Material ui 输入?

    php - Adsense 似乎无法识别 PHP 生成的内容

    ads - Google Adsense 广告未在 Rails 应用程序中显示

    jquery - 如何仅在高度超过 2400 像素的页面上显示 AdSense?

    javascript - 使用 react 测试库检查文本出现在元素内部

    javascript - 如何在 react js中单击按钮或图标单击打开日期选择器

    reactjs - redux 从状态获取项目或从服务器获取

    flutter - 如何在flutter web中插入Adsense展示广告

    apache-flex - 是否可以在 Flex3 网站上使用 Google Adsense?