-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: Support Bidder-Specific Schains #8594
Changes from all commits
b414ba9
d582f8d
631b487
271a409
7ca83b4
b96ecb4
a3ebe09
63dbdcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -861,6 +861,43 @@ Object.assign(ORTB2.prototype, { | |
request.ext.prebid = mergeDeep(request.ext.prebid, s2sConfig.extPrebid); | ||
} | ||
|
||
// get reference to pbs config schain bidder names (if any exist) | ||
const pbsSchainBidderNamesArr = request.ext.prebid?.schains ? request.ext.prebid.schains.flatMap(s => s.bidders) : []; | ||
// create an schains object | ||
const schains = Object.fromEntries( | ||
(request.ext.prebid?.schains || []).map(({bidders, schain}) => [JSON.stringify(schain), {bidders: new Set(bidders), schain}]) | ||
); | ||
|
||
// compare bidder specific schains with pbs specific schains | ||
request.ext.prebid.schains = Object.values( | ||
bidRequests | ||
.map((req) => [req.bidderCode, req.bids[0].schain]) | ||
.reduce((chains, [bidder, chain]) => { | ||
const chainKey = JSON.stringify(chain); | ||
|
||
switch (true) { | ||
// if pbjs bidder name is same as pbs bidder name, pbs bidder name always wins | ||
case chainKey && pbsSchainBidderNamesArr.indexOf(bidder) !== -1: | ||
logInfo(`bidder-specific schain for ${bidder} skipped due to existing entry`); | ||
break; | ||
// if a pbjs schain obj is equal to an schain obj that exists on the pbs side, add the bidder name on the pbs side | ||
case chainKey && chains.hasOwnProperty(chainKey) && pbsSchainBidderNamesArr.indexOf(bidder) === -1: | ||
chains[chainKey].bidders.add(bidder); | ||
break; | ||
// if a pbjs schain obj is not on the pbs side, add a new schain entry on the pbs side | ||
case chainKey && !chains.hasOwnProperty(chainKey): | ||
chains[chainKey] = {bidders: new Set(), schain: chain}; | ||
chains[chainKey].bidders.add(bidder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the This would also be a good test case, if I understand your intent, you want two separate bid requests with identical chains to be "merged" into a single entry in ext.prebid.schains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusted the logic for this and also added a test case |
||
break; | ||
default: | ||
} | ||
|
||
return chains; | ||
}, schains) | ||
).map(({bidders, schain}) => ({bidders: Array.from(bidders), schain})); | ||
// if schains evaluates to an empty array, remove it from the prebid object | ||
if (request.ext.prebid.schains.length === 0) delete request.ext.prebid.schains; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if this is in scope for this, but I noticed something while working on a separate issue: on line 918, the PBS adapter sets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, looks as though logic appears to be something like that, but I am not 100% sure on what the expected logic is supposed to be here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep that out of scope, @dgirardi did you already open another issue for this? |
||
/** | ||
* @type {(string[]|string|undefined)} - OpenRTB property 'cur', currencies available for bids | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming here that as long a bidder is associated only with one chain, it's OK to have duplicates due to different serialization of equivalent schains, e.g.
[{bidders: ['A'], schain1}, {bidders: ['B'], schain2}]
works for the backend even ifschain1
andschain2
are identical.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored things a bit to include the following logic:
if
pbjs.setBidderConfig
is used to create an schain withbidder A
, butbidder B
has the same schain object (as configured ons2sConfig.extPrebid.schains) as
bidder A`.. now the output in the request will be:ext.prebid.schains[{bidders: ['bidder A', 'bidder B'], schain: <the schain obj they were both using>}]