如何为同一页面上的多个广告展示位置设置 DFP GPT 广告位?

问题描述

我是 Google Ad Manager (DFP) 的新手,在设置 DFP 广告资源的结构和在页面上实施时几乎不需要帮助。考虑到我的网站是一个小型新闻网站,我的网站有 5 个部分 - 世界/商业/政治/娱乐/体育。并且每个版块至少有 3-5 个广告版位,其中包括一些尺寸相同的版位,即体育版块有两个 300x250 版位,而政治版块有三个 728x90 版位。

我采用的方法是在 DFP 中创建五个广告位,如下所示 -

/12345678/website.com/world /12345678/website.com/sports /12345678/website.com/business /12345678/website.com/entertainment /12345678/website.com/politics

现在我面临的更大挑战是确定,我应该打电话

googletag
      .defineslot('/12345678/website.com/sports',[[300,250],[728,90],[300,250]],'div-gpt-sports12345')
      .addService(googletag.pubads());

我的页面正文会被编码为 -

<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
  window.googletag = window.googletag || {cmd: []};
  googletag.cmd.push(function() {
    googletag.defineslot('/21871128741/teststack','div-mrec1').addService(googletag.pubads());
    googletag.defineslot('/21871128741/teststack','div-mrec2').addService(googletag.pubads());
    googletag.defineslot('/21871128741/teststack',[[728,90]],'div-lb728x90_1').addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>


<!-- /21871128741/teststack/300x250 -->
<div id='div-mrec1' style='width: 300px; height: 250px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-mrec1'); });
  </script>
</div>


<!-- /21871128741/teststack/300x250 -->
<div id='div-mrec2' style='width: 300px; height: 250px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-mrec2'); });
  </script>
</div>

<!-- /21871128741/teststack/300x250 -->
<div id='div-lb728x90_1' style='width: 728px; height: 90px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-lb728x90_1'); });
  </script>
</div>

我还尝试了另一个版本,即使用其独特的子广告单元调用 gpt 广告位。

<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
  window.googletag = window.googletag || {cmd: []};
  googletag.cmd.push(function() {
    googletag.defineslot('/21871128741/teststack/mrec1','div-mrec1').addService(googletag.pubads());
    googletag.defineslot('/21871128741/teststack/mrec2','div-mrec2').addService(googletag.pubads());
    googletag.defineslot('/21871128741/teststack/lb728x90_1','div-lb728x90_1').addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>


<!-- /21871128741/teststack/300x250 -->
<div id='div-mrec1' style='width: 300px; height: 250px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-mrec1'); });
  </script>
</div>


<!-- /21871128741/teststack/300x250 -->
<div id='div-mrec2' style='width: 300px; height: 250px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-mrec2'); });
  </script>
</div>

<!-- /21871128741/teststack/300x250 -->
<div id='div-lb728x90_1' style='width: 728px; height: 90px;'>
  <script>
    googletag.cmd.push(function() { googletag.display('div-lb728x90_1'); });
  </script>
</div>

解决方法

根据您的需要,您必须为同一页面定义多个插槽:

  • 横幅 = [728,90]
  • mpu1 = [300,250]
  • mpu2 = [300,250]

每个定义的插槽都链接到一个 div ID(详细信息 here):

googletag.Slot googletag.defineSlot(adUnitPath,size,opt_div) 

哪里:

  • adUnitPath /string/ :包含网络代码和单元代码的完整广告单元路径。
  • size /array/ : 此槽中允许调用的尺寸的宽度和高度
  • opt_div /string/ :将包含此广告单元的 div 的 ID。

在您的代码示例中,您尝试在同一个 DOM 中使用相同的 div ID 3 次,并且您只声明一个广告位...您应该做的更像是:

//banner definition
googletag.defineSlot('/12345678/website.com/sports',[[728,90]],'div-banner').addService(googletag.pubads());

//mpu1 definition
googletag.defineSlot('/12345678/website.com/sports',[[300,250]],'div-mpu1').addService(googletag.pubads());

//mpu2 definition
googletag.defineSlot('/12345678/website.com/sports','div-mpu2').addService(googletag.pubads());

在这种情况下,广告服务器将生成 3 个广告调用(每个定义和显示的展示位置一个)。

为确保我们能够包含或排除页面上的某个 mpus,您可以添加键值,例如:

  • 横幅 = [728,250],位置 = 1
  • mpu2 = [300,250],位置 = 2

为此,您必须在每个 mpu 插槽上设置目标(here 了解详细信息):

//mpu1 definition
googletag.defineSlot('/12345678/website.com/sports','div-mpu1').setTargeting('position','1').addService(googletag.pubads());
    
//mpu2 definition
googletag.defineSlot('/12345678/website.com/sports','div-mpu2').setTargeting('position','2').addService(googletag.pubads());