如何在一个网站上拥有多个 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>
and (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({});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)