Created
October 14, 2019 09:42
-
-
Save gpolaert/b24f8926d730df34934284507f86a38a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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