-
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
Conversation
added a couple of tests for this issue just now |
Just a reminder to review whenever one of you have time. Thanks! @robertrmartinez @ChrisHuie or @musikele |
// get reference to pbs config schain bidder names (if any exist) | ||
let pbsSchainBidderNamesArr = []; | ||
if (request.ext.prebid.schains) { | ||
for (let i = 0; i < request.ext.prebid.schains.length; i++) { |
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.
request.ext.prebid.schains.flatMap(s => s.bidders)
let pbjsSchainValuesArr = []; | ||
|
||
// iterate over pbjs bidder specific schains (if any exist) | ||
for (let i = 0; i < bidRequests.length; i++) { |
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 don't think it's correct to update
s2sConfig
, this should updaterequest
. the first may work if you make sure it's not shared across different requests, but why go down that route? conceptually this is part of the request, not cross-request configuration. - I'm not sure this works as intended if two equivalent schain objects happen to be serialized to two different json strings, e.g.
{ "ver":"1.0", "complete": 1, ...}
vs{"complete": 1, "ver": "1.0", ...}"
- what should be the equivalence test? - I suspect this is more complicated than it needs to be - would something like this work?
// `key(schain_1)` === `key(schain_2)` IIF schain_1 is equivalent to schain_2
const schains = Object.fromEntries(
request.ext.prebid?.schains || []).map(({bidders, schain}) => [key(schain), {bidders: new Set(bidders), schain}]
)
request.ext.prebid.schains = Object.values(
bidRequests
.map((req) => [req.bidder, req.bids[0].schain])
.reduce((chains, [bidder, chain]) => {
const chainKey = key(chain);
if (!chains.hasOwnProperty(chainKey)) chains[chainKey] = {bidders: new Set(), schain: chain};
chains[chainKey].bidders.add(bidder);
return chains;
}, schains)
).map(({bidders, schain}) => ({bidders: Array.from(bidders), schain}))
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.
Thanks for the review @dgirardi. Good point, I agree that it would make more sense to update the request itself instead. I went back and modified my PR, I like the route you took with your suggestion above and integrated it into my PR. Let me know if you think any other changes should be made or if the logic seems good.
bidRequests | ||
.map((req) => [req.bidderCode, req.bids[0].schain]) | ||
.reduce((chains, [bidder, chain]) => { | ||
const chainKey = JSON.stringify(chain); |
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 if schain1
and schain2
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 with bidder A
, but bidder B
has the same schain object (as configured on s2sConfig.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>}]
logInfo(`bidder-specific schain for ${bidder} skipped due to existing entry`); | ||
} else { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the bidders.add(bidder)
needs to be detented out of if (!chains.hasOwnProperty(chainKey))
; otherwise, if multiple bidders have chains that serialize to the same key, you are losing the association for every one of them except the first.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted the logic for this and also added a test case
.reduce((chains, [bidder, chain]) => { | ||
const chainKey = JSON.stringify(chain); | ||
if (chainKey && !chains.hasOwnProperty(chainKey)) { | ||
if (pbsSchainBidderNamesArr.indexOf(bidder) !== -1) { |
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.
the pbsSchainBidderNamesArr
check also appears in the wrong place to me, as a consequence of the above. it should guard the bidders.add
call.
hey @dgirardi, just pushed some updates can you review when you have time? |
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.
Looks good to me
).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 comment
The 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 source.ext.schain
with the first schain it finds. Does that make sense? is it just ignored server side?
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.
hmm, looks as though source.ext.schain
only gets added if an schain was configured using pbjs.setBidderConfig
and the bidder the schain was configured for is the same as what is set under defaultVendor
configured in the s2sConfig
..
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 comment
The 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?
* implementation for issue 8561 * removed eslint disable comment * added tests * removed unecessary comments * addressed feedback * reverted a few changes that were used for dev on my local * addressed feedback and refactored code * reverted changes to the prebidServer_example file Co-authored-by: Jason Quaccia <[email protected]>
* implementation for issue 8561 * removed eslint disable comment * added tests * removed unecessary comments * addressed feedback * reverted a few changes that were used for dev on my local * addressed feedback and refactored code * reverted changes to the prebidServer_example file Co-authored-by: Jason Quaccia <[email protected]>
* implementation for issue 8561 * removed eslint disable comment * added tests * removed unecessary comments * addressed feedback * reverted a few changes that were used for dev on my local * addressed feedback and refactored code * reverted changes to the prebidServer_example file Co-authored-by: Jason Quaccia <[email protected]>
Type of change
Description of change
Added support for bidder-specific schains within the PBS adapter module
Other information
#8561