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

Prebid Server Bid Adapter: Include adUnitCode in PBS Adapter Requests #9337

Merged
merged 5 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions libraries/pbsExtensions/processors/adUnitCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {auctionManager} from '../../../src/auctionManager.js';
import {deepSetValue} from '../../../src/utils.js';

export function setImpAdUnitCode(imp, bidRequest, context, { adUnit, index = auctionManager.index } = {}) {
adUnit = adUnit || index.getAdUnit(bidRequest);
Copy link
Collaborator

@dgirardi dgirardi Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be adUnitCode = bidRequest.adUnitCode || context.adUnit?.code; or, even better, if you update this logic to

    proxyBidRequests.push({
      ...adUnit,
     adUnitCode: adUnit.code

then in here you can just do adUnitCode = bidRequest.adUnitCode.

Why? normally bidRequests have an adUnitCode property which is all you need; but in the case of the PBS adapter specifically, there is no 1-to-1 correspondence between an imp and a bidRequest; so the bidRequest parameter here is a "fake" one that should contain only those fields that do not depend on the bidder. The adunit code is one of those fields but I missed it when wrote that logic.

The issue with your approach here is that:

  • the adUnit parameter is never defined - except for your tests, the callers do not know about it;
  • index.getAdUnit will work for client-side adapters that talk to a PBS backend, but not for the PBS adapter, because in that case the bidRequest parameter is not a "real" bid request.

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 @dgirardi for taking the time to walk me through the "why" up above! makes sense in terms of pbs operating differently. Addressed your feedback and refactored things a little bit, can you review again when you have a sec?


if (adUnit) {
deepSetValue(
imp,
`ext.prebid.adunitcode`,
adUnit.code
);
}
}
5 changes: 5 additions & 0 deletions libraries/pbsExtensions/processors/pbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {deepAccess, isPlainObject, isStr, mergeDeep} from '../../../src/utils.js
import {extPrebidMediaType} from './mediaType.js';
import {setRequestExtPrebidAliases} from './aliases.js';
import {setImpBidParams} from './params.js';
import {setImpAdUnitCode} from './adUnitCode.js';
import {setRequestExtPrebid, setRequestExtPrebidChannel} from './requestExtPrebid.js';
import {setBidResponseVideoCache} from './video.js';

Expand All @@ -26,6 +27,10 @@ export const PBS_PROCESSORS = {
// sets bid ext.prebid.bidder.[bidderCode] with bidRequest.params, passed through transformBidParams if necessary
fn: setImpBidParams
},
adUnitCode: {
// sets bid ext.prebid.adunitcode
fn: setImpAdUnitCode
}
},
[BID_RESPONSE]: {
mediaType: {
Expand Down
46 changes: 46 additions & 0 deletions test/spec/ortbConverter/pbsExtensions/adUnitCode_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {setImpAdUnitCode} from '../../../../libraries/pbsExtensions/processors/adUnitCode.js';

describe('pbjs -> ortb adunit code to imp[].ext.prebid.adunitcode', () => {
let index, adUnit, adUnitObj;
beforeEach(() => {
adUnit = '';
adUnitObj = {code: 'mockAdUnit'};
index = {
getAdUnit() {
return adUnitObj;
}
}
});

function setImp(bidRequest, context, deps = {}) {
const imp = {};
setImpAdUnitCode(imp, bidRequest, context, Object.assign({adUnit, index}, deps))
return imp;
}

it('falls back to index.getAdUnit if adUnit is not present to set adunitcode in ext.prebid.adunitcode', () => {
expect(setImp({bidder: 'mockBidder'})).to.eql({
'ext': {
'prebid': {
'adunitcode': 'mockAdUnit'
}
}
})
});

it('overrides index.getAdUnit if adUnit is present to set adunitcode in ext.prebid.adunitcode', () => {
adUnit = {code: 'mockAdUnit2'};
expect(setImp({bidder: 'mockBidder'})).to.eql({
'ext': {
'prebid': {
'adunitcode': 'mockAdUnit2'
}
}
})
});

it('does not set adunitcode in ext.prebid.adunitcode if adUnit is undefined', () => {
adUnitObj = undefined;
expect(setImp({bidder: 'mockBidder'})).to.eql({});
});
});