Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: make sure adUnitCodes are unique in auction events #12127

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
muuki88 marked this conversation as resolved.
Show resolved Hide resolved
}
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