Skip to content

Commit

Permalink
Core: make sure adUnitCodes are unique in auction events (#12127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Aug 16, 2024
1 parent faceb40 commit 1409a4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,17 @@ pbjsInstance.requestBids = (function() {
events.emit(REQUEST_BIDS);
const cbTimeout = timeout || config.getConfig('bidderTimeout');
logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);
if (adUnitCodes != null && !Array.isArray(adUnitCodes)) {
adUnitCodes = [adUnitCodes];
}
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);
}
adUnitCodes = adUnitCodes.filter(uniques);
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
19 changes: 18 additions & 1 deletion test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,24 @@ describe('Unit: Prebid Module', function () {
adUnitCodes: 'two'
});
sinon.assert.calledWith(startAuctionStub, sinon.match({
adUnits: [{code: 'two'}]
adUnits: [{code: 'two'}],
adUnitCodes: ['two']
}));
});

it('does not repeat ad unit codes on twin ad units', () => {
$$PREBID_GLOBAL$$.requestBids({
adUnits: [{code: 'au1'}, {code: 'au2'}, {code: 'au1'}, {code: 'au2'}],
});
sinon.assert.calledWith(startAuctionStub, sinon.match({
adUnitCodes: ['au1', 'au2']
}));
});

it('filters out repeated ad unit codes from input', () => {
$$PREBID_GLOBAL$$.requestBids({adUnitCodes: ['au1', 'au1', 'au2']});
sinon.assert.calledWith(startAuctionStub, sinon.match({
adUnitCodes: ['au1', 'au2']
}));
});

Expand Down

0 comments on commit 1409a4a

Please sign in to comment.