Skip to content

Commit

Permalink
PBS adapter: do not set bidder schain in source.ext.schain (#11467)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 29, 2024
1 parent 2fef9c2 commit 45a77ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
11 changes: 1 addition & 10 deletions modules/prebidServerBidAdapter/ortbConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ const PBS_CONVERTER = ortbConverter({
context.actualBidderRequests.forEach(req => orig(ortbRequest, req, context));
},
sourceExtSchain(orig, ortbRequest, proxyBidderRequest, context) {
// pass schains in ext.prebid.schains, with the most commonly used one in source.ext.schain
let mainChain;

// pass schains in ext.prebid.schains
let chains = (deepAccess(ortbRequest, 'ext.prebid.schains') || []);
const chainBidders = new Set(chains.flatMap((item) => item.bidders));

Expand All @@ -218,17 +216,10 @@ const PBS_CONVERTER = ortbConverter({
chains[key] = {bidders: new Set(), schain};
}
bidders.forEach((bidder) => chains[key].bidders.add(bidder));
if (mainChain == null || chains[key].bidders.size > mainChain.bidders.size) {
mainChain = chains[key]
}
return chains;
}, {})
).map(({bidders, schain}) => ({bidders: Array.from(bidders), schain}));

if (mainChain != null) {
deepSetValue(ortbRequest, 'source.ext.schain', mainChain.schain);
}

if (chains.length) {
deepSetValue(ortbRequest, 'ext.prebid.schains', chains);
}
Expand Down
35 changes: 20 additions & 15 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2377,23 +2377,28 @@ describe('S2S Adapter', function () {
]);
});

it('should "promote" the most reused bidder schain to source.ext.schain', () => {
const bidderReqs = [
{...deepClone(BID_REQUESTS[0]), bidderCode: 'A'},
{...deepClone(BID_REQUESTS[0]), bidderCode: 'B'},
{...deepClone(BID_REQUESTS[0]), bidderCode: 'C'}
];
const chain1 = {chain: 1};
const chain2 = {chain: 2};
Object.entries({
'set': {},
'override': {source: {ext: {schain: 'pub-provided'}}}
}).forEach(([t, fpd]) => {
it(`should not ${t} source.ext.schain`, () => {
const bidderReqs = [
{...deepClone(BID_REQUESTS[0]), bidderCode: 'A'},
{...deepClone(BID_REQUESTS[0]), bidderCode: 'B'},
{...deepClone(BID_REQUESTS[0]), bidderCode: 'C'}
];
const chain1 = {chain: 1};
const chain2 = {chain: 2};

bidderReqs[0].bids[0].schain = chain1;
bidderReqs[1].bids[0].schain = chain2;
bidderReqs[2].bids[0].schain = chain2;
bidderReqs[0].bids[0].schain = chain1;
bidderReqs[1].bids[0].schain = chain2;
bidderReqs[2].bids[0].schain = chain2;

adapter.callBids(REQUEST, bidderReqs, addBidResponse, done, ajax);
const req = JSON.parse(server.requests[0].requestBody);
expect(req.source.ext.schain).to.eql(chain2);
});
adapter.callBids({...REQUEST, ortb2Fragments: {global: fpd}}, bidderReqs, addBidResponse, done, ajax);
const req = JSON.parse(server.requests[0].requestBody);
expect(req.source?.ext?.schain).to.eql(fpd?.source?.ext?.schain);
})
})

it('passes multibid array in request', function () {
const bidRequests = utils.deepClone(BID_REQUESTS);
Expand Down

0 comments on commit 45a77ef

Please sign in to comment.