我只想在移动设备上启用 Google AdSense Autoads 以显示锚定广告(宽度<800px),而在大屏幕上我只需要特定的广告元素而不需要 Autoads。
所以我尝试在头部添加这个:
<script sync src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxx" crossorigin="anonymous""></script>
<script>
if (screen.width<800) {
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-xxxx",
enable_page_level_ads: true,
overlays: {
bottom: true,
}
});
}
</script>
在体内:
<style>
@media (max-width:800px) {
.ads-right {
display: none;
}
}
</style>
<div class="ads-right">
<ins class="adsbygoogle" style="display:block;" data-ad-client="ca-pub-xxxxxxx" data-ad-slot="yyyyy" data-ad-format="rectangle" data-full-width-responsive="true"></ins>
<script>
if (screen.width>800) {
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>
</div>
结果是它可以工作,但是在小屏幕(宽度<800px)上,我在控制台中收到此错误,并且锚广告位于顶部,而不是底部:
Uncaught N {message: "adsbygoogle.push() error: Only one 'enable_page_level_ads' allowed per page.", name: 'TagError', pbr: true, stack: "TagError: adsbygoogle.push() error: Only one 'enab…google.js?client=ca-pub-xxxxx:222:259)"}
有什么建议么?