0

当我们使用 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 -->
4

1 回答 1

1

这绝对是错误的事件顺序。我什至认为根本不需要 pbjs.setTargetingForGPTAsync() ,但是您确实需要在 googletag.pubads().setTargeting("pageurl", "/home/"); 之前等待 prebid 返回出价。

你可以用一个包裹在 prebid 周围的 Promise 来解决这个问题,然后等待 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();
});
});
于 2019-02-12T14:58:39.197 回答