Prebid.js
Prebid.js copied to clipboard
Question: Recommended loading pattern
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?
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.