Skip to content

Commit

Permalink
Prebid core: filter adUnits (by adUnitCodes) before sending them to…
Browse files Browse the repository at this point in the history
… RTD and FPD modules (prebid#9355)
  • Loading branch information
dgirardi authored and JacobKlein26 committed Feb 8, 2023
1 parent 56a4a43 commit 4a3b35b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@ $$PREBID_GLOBAL$$.requestBids = (function() {
events.emit(REQUEST_BIDS);
const cbTimeout = timeout || config.getConfig('bidderTimeout');
logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);
if (adUnitCodes && adUnitCodes.length) {
// if specific adUnitCodes supplied filter adUnits for those codes
adUnits = adUnits.filter(unit => includes(adUnitCodes, unit.code));
} else {
// otherwise derive adUnitCodes from adUnits
adUnitCodes = adUnits && adUnits.map(unit => unit.code);
}
const ortb2Fragments = {
global: mergeDeep({}, config.getAnyConfig('ortb2') || {}, ortb2 || {}),
bidder: Object.fromEntries(Object.entries(config.getBidderConfig()).map(([bidder, cfg]) => [bidder, cfg.ortb2]).filter(([_, ortb2]) => ortb2 != null))
Expand Down Expand Up @@ -661,14 +668,6 @@ export const startAuction = hook('async', function ({ bidsBackHandler, timeout:
const s2sBidders = getS2SBidderSet(config.getConfig('s2sConfig') || []);
adUnits = useMetrics(metrics).measureTime('requestBids.validate', () => checkAdUnitSetup(adUnits));

if (adUnitCodes && adUnitCodes.length) {
// if specific adUnitCodes supplied filter adUnits for those codes
adUnits = adUnits.filter(unit => includes(adUnitCodes, unit.code));
} else {
// otherwise derive adUnitCodes from adUnits
adUnitCodes = adUnits && adUnits.map(unit => unit.code);
}

function auctionDone(bids, timedOut, auctionId) {
if (typeof bidsBackHandler === 'function') {
try {
Expand Down
11 changes: 11 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,16 @@ describe('Unit: Prebid Module', function () {
})
});

it('filtering adUnits by adUnitCodes', () => {
$$PREBID_GLOBAL$$.requestBids({
adUnits: [{code: 'one'}, {code: 'two'}],
adUnitCodes: 'two'
});
sinon.assert.calledWith(startAuctionStub, sinon.match({
adUnits: [{code: 'two'}]
}));
});

it('passing bidder-specific FPD as ortb2Fragments.bidder', () => {
configObj.setBidderConfig({
bidders: ['bidderA', 'bidderC'],
Expand Down Expand Up @@ -1869,6 +1879,7 @@ describe('Unit: Prebid Module', function () {
mediaTypes: {banner: {sizes: [[300, 250]]}},
bids: [{bidder: 'bd'}]
}],
adUnitCodes: ['au'],
ortb2Fragments
});
sinon.assert.calledWith(newAuctionStub, sinon.match({
Expand Down

0 comments on commit 4a3b35b

Please sign in to comment.