为什么DFP / GAM setTargeting选项无法与prebid一起使用?

问题描述 投票:0回答:1

当我们使用用于定位具有键/值对的广告的DFP选项时,我们发现当Prebid也在运行时它不起作用。 Prebid似乎覆盖了setTargeting选项。这似乎是一个常见的问题,但我找不到任何有关它的信息。

如果我禁用prebid,setTargeting工作正常。

我也尝试将setTargeting放在pbjs.que.push函数中,就在pbjs.setTargetingForGPTAsync()之后;但这没有帮助。

我已将代码配对,仅包含基本设置,以显示我们如何配置内容。

<script src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script type="text/javascript" src="https://ads.bninews.com/corporate/prebid/latest/prebid.js"></script>
<script type="text/javascript" src="https://ads.bninews.com/corporate/prebid/latest/prebid_config.js?20180913"></script>

<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>

<script>
googletag.cmd.push(function() {
  googletag.defineSlot('/XXX/slot-300x250-1', [[300, 250]], 'div-gpt-ad-bigblock-1').addService(googletag.pubads());
  googletag.pubads().setTargeting("pageurl", "/home/");
  googletag.pubads().enableSingleRequest();
  googletag.pubads().disableInitialLoad();
  googletag.enableServices();
});
</script>

<!-- Prebid Boilerplate Section START -->
<script>
  pbjs.que.push(function() {
    pbjs.addAdUnits(adUnits);
    pbjs.requestBids({
      bidsBackHandler: initAdserver,
      timeout: PREBID_TIMEOUT
    });
  });
  function initAdserver() {
    if (pbjs.initAdserverSet) return;
    pbjs.initAdserverSet = true;
    googletag.cmd.push(function() {
      pbjs.que.push(function() {
        pbjs.setTargetingForGPTAsync();
        googletag.pubads().refresh();
      });
    });
  }
  // in case PBJS doesn't load
  setTimeout(function() {
    initAdserver();
  }, FAILSAFE_TIMEOUT);
</script>
<!-- Prebid Boilerplate Section END -->
google-dfp prebid.js prebid
1个回答
1
投票

这绝对是错误的事件序列。我甚至不认为pbjs.setTargetingForGPTAsync()是完全需要的,但你需要等待prebid返回googletag.pubads()之前的出价.setTargeting(“pageurl”,“/ home /”);

你可以使用一个可以包含在prebid中的Promise来解决这个问题,并等待承诺在内部进行解析,例如:

var prebidPromiseResponse = new Promise( function(resolve){ 

pbjs.que.push(function() {
    pbjs.addAdUnits(adUnits);
    pbjs.requestBids({
      bidsBackHandler: function(bids){
       if (pbjs.initAdserverSet) return;
       pbjs.initAdserverSet = true;
       googletag.cmd.push(function() {
        pbjs.que.push(function() {
           resolve(bids);
        });
      });
      },
      timeout: PREBID_TIMEOUT
    });
  });
})

然后是谷歌标签

googletag.cmd.push(function() {
  googletag.defineSlot('/XXX/slot-300x250-1', [[300, 250]], 'div-gpt-ad-bigblock-1').addService(googletag.pubads());
  prebidPromiseResponse.then(function(bids){
  googletag.pubads().setTargeting("pageurl", "/home/");
  googletag.pubads().enableSingleRequest();
  googletag.pubads().disableInitialLoad();
  googletag.enableServices();
});
});
© www.soinside.com 2019 - 2024. All rights reserved.