Skip to content

Commit

Permalink
PBS Bid Adapter: allow setting site params (prebid#4973)
Browse files Browse the repository at this point in the history
* add site config value to oRTB request

* update to copy site.page and site.publisher.id if not defined in config site object
  • Loading branch information
Isaac A. Dettman authored and iggyfisk committed Jun 22, 2020
1 parent 204c4f3 commit 85cb83f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
12 changes: 9 additions & 3 deletions modules/prebidServerBidAdapter/index.js
Expand Up @@ -269,11 +269,17 @@ function _appendSiteAppDevice(request, pageUrl) {
request.app.publisher = {id: _s2sConfig.accountId}
} else {
request.site = {};
if (typeof config.getConfig('site') === 'object') {
if (utils.isPlainObject(config.getConfig('site'))) {
request.site = config.getConfig('site');
}
utils.deepSetValue(request.site, 'publisher.id', _s2sConfig.accountId);
request.site.page = pageUrl;
// set publisher.id if not already defined
if (!utils.deepAccess(request.site, 'publisher.id')) {
utils.deepSetValue(request.site, 'publisher.id', _s2sConfig.accountId);
}
// set site.page if not already defined
if (!request.site.page) {
request.site.page = pageUrl;
}
}
if (typeof config.getConfig('device') === 'object') {
request.device = config.getConfig('device');
Expand Down
55 changes: 54 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Expand Up @@ -925,7 +925,7 @@ describe('S2S Adapter', function () {
expect(requestBid.site.content.language).to.exist.and.to.be.a('string');
expect(requestBid.site).to.deep.equal({
publisher: {
id: '1',
id: '1234',
domain: 'test.com'
},
content: {
Expand Down Expand Up @@ -1095,6 +1095,59 @@ describe('S2S Adapter', function () {
expect(requestBid.imp[0].ext.appnexus.key).to.be.equal('value')
});

describe('config site value is added to the oRTB request', function () {
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction',
adapterOptions: {
appnexus: {
key: 'value'
}
}
});
const device = {
ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
ip: '75.97.0.47'
};

it('and overrides publisher and page', function () {
config.setConfig({
s2sConfig: s2sConfig,
site: {
domain: 'nytimes.com',
page: 'http://www.nytimes.com',
publisher: { id: '2' }
},
device: device
});
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
const requestBid = JSON.parse(server.requests[0].requestBody);

expect(requestBid.site).to.exist.and.to.be.a('object');
expect(requestBid.site.domain).to.equal('nytimes.com');
expect(requestBid.site.page).to.equal('http://www.nytimes.com');
expect(requestBid.site.publisher).to.exist.and.to.be.a('object');
expect(requestBid.site.publisher.id).to.equal('2');
});

it('and merges domain and page with the config site value', function () {
config.setConfig({
s2sConfig: s2sConfig,
site: {
foo: 'bar'
},
device: device
});
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(server.requests[0].requestBody);
expect(requestBid.site).to.exist.and.to.be.a('object');
expect(requestBid.site.foo).to.equal('bar');
expect(requestBid.site.page).to.equal('http://mytestpage.com');
expect(requestBid.site.publisher).to.exist.and.to.be.a('object');
expect(requestBid.site.publisher.id).to.equal('1');
});
});

it('when userId is defined on bids, it\'s properties should be copied to user.ext.tpid properties', function () {
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
Expand Down

0 comments on commit 85cb83f

Please sign in to comment.