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 specifc options #3394

5 changes: 4 additions & 1 deletion modules/prebidServerBidAdapter/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const S2S_VENDORS = {
enabled: true,
endpoint: '//prebid-server.rubiconproject.com/openrtb2/auction',
syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync',
timeout: 500
timeout: 500,
adapterOptions: {
rubicon: { singleRequest: false }
idettman marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
34 changes: 32 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,39 @@ const DEFAULT_S2S_NETREVENUE = true;

let _s2sConfig;

/**
* @typedef {Object} AdapterOptions
* @summary s2sConfig parameter that adds arguments to resulting OpenRTB payload that goes to Prebid Server
* @example
* // example of multiple bidder configuration
* pbjs.setConfig({
* s2sConfig: {
* adapterOptions: {
* rubicon: {singleRequest: false}
* appnexus: {key: "value"}
* }
* }
* });
*/

/**
* @typedef {Object} S2SDefaultConfig
* @property {boolean} enabled
* @property {number} timeout
* @property {number} maxBids
* @property {string} adapter
* @property {AdapterOptions} adapterOptions
*/

/**
* @type {S2SDefaultConfig}
*/
const s2sDefaultConfig = {
enabled: false,
timeout: 1000,
maxBids: 1,
adapter: 'prebidServer'
adapter: 'prebidServer',
adapterOptions: {}
};

config.setDefaults({
Expand All @@ -43,6 +71,8 @@ config.setDefaults({
* @property {boolean} [cacheMarkup] whether to cache the adm result
* @property {string} [adapter] adapter code to use for S2S
* @property {string} [syncEndpoint] endpoint URL for syncing cookies
* @property {string} [cookieSetUrl] url for cookie set library, if passed then cookieSet is enabled
* @property {AdapterOptions} [adapterOptions] adds arguments to resulting OpenRTB payload to Prebid Server
*/
function setS2sConfig(options) {
if (options.defaultVendor) {
Expand Down Expand Up @@ -415,7 +445,7 @@ const OPEN_RTB_PROTOCOL = {
if (adapter && adapter.getSpec().transformBidParams) {
bid.params = adapter.getSpec().transformBidParams(bid.params, isOpenRtb());
}
acc[bid.bidder] = bid.params;
acc[bid.bidder] = (_s2sConfig.adapterOptions && _s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, _s2sConfig.adapterOptions[bid.bidder]) : bid.params;
return acc;
}, {});

Expand Down
107 changes: 107 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,28 @@ describe('S2S Adapter', function () {
value: ['buzz']
}]);
});

it('adds s2sConfig adapterOptions to request for ORTB', () => {
idettman marked this conversation as resolved.
Show resolved Hide resolved
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction',
adapterOptions: {
appnexus: {
key: 'value'
}
}
});
const _config = {
s2sConfig: s2sConfig,
device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' },
app: { bundle: 'com.test.app' },
};

config.setConfig(_config);
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
const requestBid = JSON.parse(requests[0].requestBody);
expect(requestBid.imp[0].ext.appnexus).to.haveOwnProperty('key');
expect(requestBid.imp[0].ext.appnexus.key).to.be.equal('value')
});
});

describe('response handler', function () {
Expand Down Expand Up @@ -1096,5 +1118,90 @@ describe('S2S Adapter', function () {
expect(vendorConfig).to.have.property('syncEndpoint', '//prebid-server.rubiconproject.com/cookie_sync');
expect(vendorConfig).to.have.property('timeout', 750);
});

it('should return proper defaults', () => {
expect(config.getConfig('s2sConfig')).to.deep.equal({
'accountId': 'abc',
'adapter': 'prebidServer',
'adapterOptions': {
'rubicon': {
'singleRequest': false
}
},
'bidders': ['rubicon'],
'cookieSet': false,
'defaultVendor': 'rubicon',
'enabled': true,
'endpoint': '//prebid-server.rubiconproject.com/auction',
'syncEndpoint': '//prebid-server.rubiconproject.com/cookie_sync',
'timeout': 750
})
});

it('should return default adapterOptions if not set', () => {
config.setConfig({
s2sConfig: {
accountId: 'abc',
bidders: ['rubicon'],
defaultVendor: 'rubicon',
timeout: 750
}
});
expect(config.getConfig('s2sConfig')).to.deep.equal({
enabled: true,
timeout: 750,
adapter: 'prebidServer',
adapterOptions: {
rubicon: {
singleRequest: false
}
},
accountId: 'abc',
bidders: ['rubicon'],
defaultVendor: 'rubicon',
cookieSet: false,
endpoint: '//prebid-server.rubiconproject.com/auction',
syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync'
})
});

it('should overwrite default adapterOptions if set', () => {
config.setConfig({
s2sConfig: {
adapterOptions: {
rubicon: {
singleRequest: true
}
}
}
});
const configResult = config.getConfig('s2sConfig');
expect(configResult).to.deep.equal({
adapterOptions: {
rubicon: {
singleRequest: true
}
}
})
});

it('should set adapterOptions that do not exist as default', () => {
config.setConfig({
s2sConfig: {
adapterOptions: {
rubicon: {
singleRequest: true,
foo: 'bar'
}
}
}
});
expect(config.getConfig('s2sConfig').adapterOptions).to.deep.equal({
rubicon: {
singleRequest: true,
foo: 'bar'
}
})
});
});
});