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 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
13 changes: 13 additions & 0 deletions libraries/pbsExtensions/processors/adUnitCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {deepSetValue} from '../../../src/utils.js';

export function setImpAdUnitCode(imp, bidRequest) {
const adUnitCode = bidRequest.adUnitCode;

if (adUnitCode) {
deepSetValue(
imp,
`ext.prebid.adunitcode`,
adUnitCode
);
}
}
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
1 change: 1 addition & 0 deletions modules/prebidServerBidAdapter/ortbConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export function buildPBSRequest(s2sBidRequest, bidderRequests, adUnits, requeste
impIds.add(impId)
proxyBidRequests.push({
...adUnit,
adUnitCode: adUnit.code,
...getDefinedParams(actualBidRequests.values().next().value || {}, ['userId', 'userIdAsEids', 'schain']),
pbsData: {impId, actualBidRequests, adUnit}
});
Expand Down
23 changes: 23 additions & 0 deletions test/spec/ortbConverter/pbsExtensions/adUnitCode_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {setImpAdUnitCode} from '../../../../libraries/pbsExtensions/processors/adUnitCode.js';

describe('pbjs -> ortb adunit code to imp[].ext.prebid.adunitcode', () => {
function setImp(bidRequest) {
const imp = {};
setImpAdUnitCode(imp, bidRequest);
return imp;
}

it('it sets adunitcode in ext.prebid.adunitcode when adUnitCode is present', () => {
expect(setImp({bidder: 'mockBidder', adUnitCode: 'mockAdUnit'})).to.eql({
'ext': {
'prebid': {
'adunitcode': 'mockAdUnit'
}
}
})
});

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