如何在一个网站上拥有多个adsense单元?谷歌给出的唯一代码是每单位。
<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>
发布于 2014-08-02 22:49:19
要在一个页面上有多个广告单元,您必须添加更多行的(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({});
});
发布于 2014-08-27 23:32:00
使用jQuery...
$(".adsbygoogle").each(function () { (adsbygoogle = window.adsbygoogle || []).push({}); });
发布于 2018-03-01 02:12:29
只调用一次<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
,在页面底部(就在</body>
之前)。
接下来,单独放置您的广告片段,如下所示:
<!-- Top Banner Ad -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:100px"
data-ad-client="ca-pub-1234567890"
data-ad-slot="4693644638"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<!-- Responsive Ad -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1234567890"
data-ad-slot="3097818646"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
https://stackoverflow.com/questions/25095912
复制相似问题