Skip to content

Instantly share code, notes, and snippets.

@gpolaert
Created October 14, 2019 09:42
Show Gist options
  • Select an option

  • Save gpolaert/b24f8926d730df34934284507f86a38a to your computer and use it in GitHub Desktop.

Select an option

Save gpolaert/b24f8926d730df34934284507f86a38a to your computer and use it in GitHub Desktop.
pbjs.requestBids({
// Handle bid responses
bidsBackHandler: () => {
// Iterate over all winning bids
const winningAds = pbjs.getHighestCpmBids();
// Iterate over all ad units
const ads = winningAds.map(winningAd => {
const adUnit = winningAd.adUnitCode;
// Check custom deals
const responses = pbjs.getBidResponsesForAdUnitCode(adUnit);
// Replace 'functionToRetrieveDeals' by your own logic
const deal = functionToRetrieveDeals(responses);
// Decide if what do you want keep (deal or winning)
if (deal) {
return deal;
} else {
return winningAd;
}
});
// Render your ads as usual
ads.forEach(ad => {
document.write('<h1>' + adUnit + '@' + ad.bidderCode + '</h1>');
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
pbjs.renderAd(iframe.contentWindow.document, ad.adId);
});
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment