Skip to content

Commit

Permalink
Prebid Server: Include adUnitCode in PBS Adapter Requests (prebid#9337)
Browse files Browse the repository at this point in the history
* changes

* added support to pass adunitcode to pbs

* updated comment

* removed console log statements

* addressed feedback
  • Loading branch information
jlquaccia authored and jorgeluisrocha committed May 18, 2023
1 parent f242e63 commit c231734
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
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({});
});
});

0 comments on commit c231734

Please sign in to comment.