如何在一页上使用多个adsense单位? [英] How do you use multiple adsense units on one page?

查看:85
本文介绍了如何在一页上使用多个adsense单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在一个网站上拥有多个adsense单元? Google给出的唯一代码是单位代码。

How do you have multiple adsense units on one website? The only code Google gives are per unit.

<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异步src = // pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script> (adsbygoogle = window.adsbygoogle || [])。push({}); 一次,然后将< ins ...>< / ins> 代码显示在我想要的位置。

What if I want to use multiple adsense units on one website? I only use <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> and (adsbygoogle = window.adsbygoogle || []).push({}); once, and then place the <ins ...></ins> code where I want it to be.

问题是只有第一个adsense单元会被解析和显示。要显示一个以上的adsense单元,您需要做什么?

The problem is that only the first adsense unit is parsed and shown. What do you need to do to be able to display more than one adsense unit?

这就是我的使用方式(仅前):

This is how I use it (only first ins is shown):

<!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({});

To have more then one adsense unit on one page you must add more rows of (adsbygoogle = window.adsbygoogle || []).push({});.

因此,如果您有3个广告单元,则要使用3次。

So if you have 3 ad units, you want to use it 3 times.

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

如果要动态地执行此操作,请使用以下命令:

If you want to do it dynamically, use this:

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

这篇关于如何在一页上使用多个adsense单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆