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: Support Bidder-Specific Schains #8594

Merged
merged 8 commits into from
Jul 25, 2022

Conversation

jlquaccia
Copy link
Collaborator

Type of change

  • Bugfix

Description of change

Added support for bidder-specific schains within the PBS adapter module

Other information

#8561

@jlquaccia
Copy link
Collaborator Author

added a couple of tests for this issue just now

@ChrisHuie ChrisHuie self-requested a review July 6, 2022 10:50
@ChrisHuie ChrisHuie self-assigned this Jul 6, 2022
@ChrisHuie ChrisHuie requested a review from musikele July 6, 2022 10:50
@ChrisHuie ChrisHuie assigned musikele and unassigned ChrisHuie Jul 6, 2022
@jlquaccia
Copy link
Collaborator Author

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++) {
Copy link
Collaborator

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++) {
Copy link
Collaborator

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 update request. 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}))

Copy link
Collaborator Author

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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

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) {
Copy link
Collaborator

@dgirardi dgirardi Jul 14, 2022

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.

@jlquaccia
Copy link
Collaborator Author

hey @dgirardi, just pushed some updates can you review when you have time?

Copy link
Collaborator

@robertrmartinez robertrmartinez left a 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;

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

@patmmccann patmmccann merged commit 8d0f10a into prebid:master Jul 25, 2022
ccorbo pushed a commit to ccorbo/Prebid.js that referenced this pull request Jul 27, 2022
* 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]>
JacobKlein26 pushed a commit to nextmillenniummedia/Prebid.js that referenced this pull request Feb 9, 2023
* 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]>
jorgeluisrocha pushed a commit to jwplayer/Prebid.js that referenced this pull request May 23, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pbs adapter: support bidder-specific schains
6 participants