【问题标题】:Cannot add multiple adsense codes to one page无法将多个 AdSense 代码添加到一页
【发布时间】:2012-11-04 02:46:26
【问题描述】:

我正在尝试将 2 个 adsense 代码添加到一页。当我这样做时,只显示一个(第一个定义的)并且页面似乎在无限加载。

这是带有示例槽和客户端 ID 的代码。

<body>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; 
        google_ad_slot = 111111111;
        google_ad_width = 160;
        google_ad_height = 600;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
        google_ad_slot = 222222222;
        google_ad_width = 336;
        google_ad_height = 280;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
</body>

如果我删除这些 adSense 代码之一,它就会起作用。我怎样才能让它同时使用这两个代码?

【问题讨论】:

    标签: javascript adsense


    【解决方案1】:

    首先,不需要两次 show-ad.js 文件。其次,show-ad.js 似乎查看了一些设置的全局变量

        google_ad_client = "ca-pub-xxxxxxxxx"; 
        google_ad_slot = 111111111;
        google_ad_width = 160;
        google_ad_height = 600;
    

    当您第二次定义它们时,第一个值会被分开,而第一个值只会显示,因为第二次加载脚本会干扰第一次。

    【讨论】:

    • 你说得对,问题在于重写两个横幅中都使用的全局变量。我不太确定是否不需要两次 show-ad.js。如果您查看该文件,您会发现调用了一个匿名函数。所以没有办法再次调用它。问题仍然存在。如何让它发挥作用?
    • 我搜了一圈,发现一个页面是禁止多个adsense账号的。我会小心这一点,因为这两个帐户都可以被禁止。
    • 我的问题仅与一个帐户有关。是的,您可以添加多个单位。 “每个页面上最多可以放置三个广告单元和三个链接单元”。见google.com/adsense/policies
    【解决方案2】:

    经过近 2 小时的谷歌搜索,我终于弄明白了。我唯一要做的就是在 google_ad_slot 变量中添加引号(哦,我的...)。所以工作代码如下所示:

    <body>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; 
        google_ad_slot = "111111111"; // see the quotes
        google_ad_width = 160;
        google_ad_height = 600;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
        google_ad_slot = "222222222";
        google_ad_width = 336;
        google_ad_height = 280;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    如果只有一个 adSense 代码,则作为整数的广告位可以正常工作。如果添加另一个,则必须将所有插槽定义为字符串

    干杯!

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多