gpt4 book ai didi

adsense - 如何在一个页面上使用多个 AdSense 单元?

转载 作者:行者123 更新时间:2023-12-02 23:46:46 27 4
gpt4 key购买 nike

如何在一个网站上拥有多个 AdSense 单元? Google 提供的唯一代码是按单位计算的。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-123456"
data-ad-slot="123456"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

如果我想在一个网站上使用多个 AdSense 单元该怎么办?我只使用 <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>(adsbygoogle = window.adsbygoogle || []).push({}); 一次,然后将 <ins ...></ins> 代码放在我想要的位置。

问题是仅解析并显示第一个 adsense 单元。您需要做什么才能显示多个 AdSense 单元?

这就是我使用它的方式(仅显示第一个ins):

<!doctype html>
<html>
<body>
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-123456"
data-ad-slot="first"></ins>

<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-123456"
data-ad-slot="second"></ins>

<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-123456"
data-ad-slot="third"></ins>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</body>
</html>

最佳答案

要在一页上包含多个 AdSense 单元,您必须添加更多行 (adsbygoogle = window.adsbygoogle || []).push({});

因此,如果您有 3 个广告单元,您希望使用它 3 次。

(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});

如果您想动态执行此操作,请使用:

[].forEach.call(document.querySelectorAll('.adsbygoogle'), function(){
(adsbygoogle = window.adsbygoogle || []).push({});
});

关于adsense - 如何在一个页面上使用多个 AdSense 单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25095912/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com