同一页面中具有相同广告尺寸的多个 GPT 广告不起作用 [英] Multiple GPT ads in same page with same ad size not working

查看:27
本文介绍了同一页面中具有相同广告尺寸的多个 GPT 广告不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个 GPT 广告的网页.

如果两个广告的尺寸不同,则广告显示在页面中.

以下代码运行正常

googletag.defineSlot("/123/test", [728, 90], "div-gpt-ad-123456789-0").addService(googletag.pubads()).setTargeting("兴趣", ["体育", "音乐", "电影"]);

第二个广告是

googletag.defineSlot("/123/test", [[468, 60], [728, 90], [300, 250]], "div-gpt-ad-123456789-1").addService(googletag.pubads()).setTargeting("性别", "男性").setTargeting("年龄", "20-30");

但如果广告尺寸相同,则无效

 googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0").addService(googletag.pubads()).setTargeting("兴趣", ["体育", "音乐", "电影"]);

第二个广告是

googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1").addService(googletag.pubads()).setTargeting("性别", "男性").setTargeting("年龄", "20-30");

请帮帮我.

解决方案

我遇到了同样的问题,我找到了解决方案:

<头><script src="http://www.googletagservices.com/tag/js/gpt.js"></script><script type="text/javascript">var gptAdSlots = [];googletag.cmd.push(function() {gptAdSlots[0] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0").addService(googletag.pubads());gptAdSlots[1] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1")..addService(googletag.pubads());googletag.pubads().enableSingleRequest();//禁用初始加载.googletag.pubads().disableInitialLoad();//开始广告抓取googletag.enableServices();});<身体><div id='div-gpt-ad-123456789-0'><script type='text/javascript'>googletag.cmd.push(function() {googletag.display('div-gpt-ad-123456789-0');//刷新广告.googletag.pubads().refresh([gptAdSlots[0]]);});

<div id='div-gpt-ad-123456789-1'><script type='text/javascript'>googletag.cmd.push(function() {googletag.display('div-gpt-ad-123456789-1');//刷新广告.googletag.pubads().refresh([gptAdSlots[1]]);});

I had a page with two GPT ads.

If the two ads are different size the ads are displayed in page.

The following code is working fine

googletag.defineSlot("/123/test", [728, 90], "div-gpt-ad-123456789-0")
.addService(googletag.pubads())
.setTargeting("interests", ["sports", "music", "movies"]);

and second ad is

googletag.defineSlot("/123/test", [[468, 60], [728, 90], [300, 250]], "div-gpt-ad-123456789-1")
    .addService(googletag.pubads())
    .setTargeting("gender", "male")
.setTargeting("age", "20-30");

But if the ads are same size not working

 googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0")
    .addService(googletag.pubads())
    .setTargeting("interests", ["sports", "music", "movies"]);

and second ad is

googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1")
    .addService(googletag.pubads())
    .setTargeting("gender", "male")
.setTargeting("age", "20-30");

Please help me.

解决方案

I had the same issue and I came to the solution:

<html>
<head>
  <script src="http://www.googletagservices.com/tag/js/gpt.js"></script>
  <script type="text/javascript">
    var gptAdSlots = [];
    googletag.cmd.push(function() {

      gptAdSlots[0] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0")
                             .addService(googletag.pubads());

      gptAdSlots[1] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1").
                             .addService(googletag.pubads());

      googletag.pubads().enableSingleRequest();

      // Disable initial load.
      googletag.pubads().disableInitialLoad();

      // Start ad fetching
      googletag.enableServices();
    });
  </script>
</head>
<body>
<div id='div-gpt-ad-123456789-0'>
  <script type='text/javascript'>
    googletag.cmd.push(function() { 
      googletag.display('div-gpt-ad-123456789-0');
      // Refresh ad.
      googletag.pubads().refresh([gptAdSlots[0]]);
    });
  </script>
</div>
<div id='div-gpt-ad-123456789-1'>
  <script type='text/javascript'>
    googletag.cmd.push(function() { 
      googletag.display('div-gpt-ad-123456789-1');
      // Refresh ad.
      googletag.pubads().refresh([gptAdSlots[1]]);
    });
  </script>
</div>
</body>

这篇关于同一页面中具有相同广告尺寸的多个 GPT 广告不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆