0

When we use the DFP option used to target ads with a Key/Value pair we noticed it does not work when Prebid is also running. It appears that Prebid is overriding the setTargeting option. It would seem to be a common issue, but I cannot find any information about it.

If I disable prebid, the setTargeting works fine.

I've also tried placing the setTargeting inside the pbjs.que.push function, just after pbjs.setTargetingForGPTAsync(); but that did not help.

I've paired down the code to include just the basic setup to show how we have things configured.

<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 -->
  • Is there a page available where I can observe this behavior? – James Ives Feb 10 '19 at 17:04
  • Sure thing. I have a test ad set up to target the 4th ad slot in the right-hand sidebar of this page. https://www.vicksburgpost.com/2016/02/20/24th-event-highlights-international-cultures/ It should only show a grey box. However, currently another ad is showing. I can remove the key:value pair and it shows fine, and I can also turn off Prebid and it will show up fine.. – Steven Crawford Feb 11 '19 at 17:49

1 Answers1

1

It's definitely the sequence of events that is wrong. I don't even think pbjs.setTargetingForGPTAsync() is needed at all, but you do need to wait for prebid to return with the bids before googletag.pubads().setTargeting("pageurl", "/home/");

You can solve this with a Promise that would be wrapped around prebid, and wait for the promise to resolve inside so something like:

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
    });
  });
})

And then google tag

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();
});
});
Wpicode
  • 41
  • 3
  • I'm not sure if I've handled it properly, but I've reconfigured my test page to do something similar to what you outline. Though I did have to add "googletag.pubads().refresh();" inside the promise.then function. I'm seeing the targeted ad (the last bigblock ad in the sidebar, it's just grey). However, when I run pbjs.getAllPrebidWinningBids() in the console, it's not returning any winning bids. Here's that test page again: https://www.vicksburgpost.com/2016/02/20/24th-event-highlights-international-cultures/ – Steven Crawford Feb 15 '19 at 16:20