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

PBS adapter: do not set bidder schain in source.ext.schain #11467

Merged
merged 1 commit into from
May 29, 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
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