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

Add oRTB cur to PrebidServer Adapter #3951

Merged
merged 3 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ const OPEN_RTB_PROTOCOL = {
request.ext.prebid = Object.assign(request.ext.prebid, _s2sConfig.extPrebid);
}

/**
* @type {(string[]|string|undefined)} - OpenRTB property 'cur', currencies available for bids
*/
const adServerCur = config.getConfig('currency.adServerCurrency');
if (adServerCur && typeof adServerCur === 'string') {
// if the value is a string, wrap it with an array
request.cur = [adServerCur];
} else if (Array.isArray(adServerCur) && adServerCur.length) {
// if it's an array, copy the first element
request.cur = adServerCur.slice(0, 1);
}

_appendSiteAppDevice(request);

const digiTrust = _getDigiTrustQueryParams(bidRequests && bidRequests[0]);
Expand Down
46 changes: 44 additions & 2 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,51 @@ describe('S2S Adapter', function () {
expect(Array.isArray(requestBid.user.ext.eids)).to.be.true;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'adserver.org')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'adserver.org')[0].uids[0].id).is.equal('abc123');
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')).is.not.empty; ;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')[0].uids[0].id).is.equal('1234');
})
});

it('when config \'currency.adServerCurrency\' value is an array: ORTB has property \'cur\' value set to a single item array', function () {
let s2sConfig = utils.deepClone(CONFIG);
s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
config.setConfig({
currency: {adServerCurrency: ['USD', 'GB', 'UK', 'AU']},
s2sConfig: s2sConfig
});

const bidRequests = utils.deepClone(BID_REQUESTS);
adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax);

const parsedRequestBody = JSON.parse(requests[0].requestBody);
expect(parsedRequestBody.cur).to.deep.equal(['USD']);
});

it('when config \'currency.adServerCurrency\' value is a string: ORTB has property \'cur\' value set to a single item array', function () {
let s2sConfig = utils.deepClone(CONFIG);
s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
config.setConfig({
currency: {adServerCurrency: 'NZ'},
s2sConfig: s2sConfig
});

const bidRequests = utils.deepClone(BID_REQUESTS);
adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax);

const parsedRequestBody = JSON.parse(requests[1].requestBody);
expect(parsedRequestBody.cur).to.deep.equal(['NZ']);
});

it('when config \'currency.adServerCurrency\' is unset: ORTB should not define a \'cur\' property', function () {
let s2sConfig = utils.deepClone(CONFIG);
s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
config.setConfig({s2sConfig: s2sConfig});

const bidRequests = utils.deepClone(BID_REQUESTS);
adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax);

const parsedRequestBody = JSON.parse(requests[0].requestBody);
expect(typeof parsedRequestBody.cur).to.equal('undefined');
});

it('always add ext.prebid.targeting.includebidderkeys: false for ORTB', function () {
const s2sConfig = Object.assign({}, CONFIG, {
Expand Down