reactjs - React.js 应用程序上的 Google 自动广告?
问题描述
我有一个在 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 自动广告,而不是广告单元。
解决方案
您必须在 reactjs 应用程序中编写“window.adsbygoogle”而不是“adsbygoogle”
componentDidMount () {
(window.adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-9142841210062390",
enable_page_level_ads: true
});
}
推荐阅读
- python - 序列化 3 个相互关联的 Django 关系模型
- powershell - 如何使用 PowerShell 在 MS Teams 中添加频道(非交互式)
- react-native - 在 iOS 中为 React Native Expo 放大图像
- javascript - 关于firestore实时监听器数量的概念问题
- c - 为泛型结构和原始类型创建可变参数函数
- mpandroidchart - 饼图中x值的mpandroidchart位置
- google-cloud-platform - 如何恢复谷歌云平台的默认服务帐号?
- python - While循环中的用户输入验证问题
- bash - 在 Bash 中打印字符串中子字符串的索引
- qt - 有没有办法在 qml 中看到 cpp 函数描述作为提示