Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

Question: Recommended loading pattern

Open rachelrj opened this issue 9 years ago • 1 comments

In some examples, the below pattern is used for sending the DFP AdServerRequest:

  googletag.cmd.push(function() {
    pbjs.que.push(function() {
      pbjs.setTargetingForGPTAsync();
    });
    googletag.pubads().refresh();
  });

And in other examples, this pattern is used for sending the DFP AdServerRequest:

  googletag.cmd.push(function() {
    pbjs.que.push(function() {
      pbjs.setTargetingForGPTAsync();
      googletag.pubads().refresh();
    });
  });

Is there an explanation or reason for using one versus the other?

rachelrj avatar Jun 08 '17 23:06 rachelrj

You should use the second one, with the call to googletag.pubads().refresh() also wrapped in the pbjs.que. This will prevent a race condition where GPT is loaded but Prebid isn't yet, and ensure that targeting is set before the call to the ad server is made.

protonate avatar Jun 09 '17 18:06 protonate