Skip to content

Commit

Permalink
adform and adformOpenRTB bid adapters: Added support for userId modul…
Browse files Browse the repository at this point in the history
…es (#5425)

* adformBidAdapter - added userId module support

* adformOpenRTBBidAdapter - added userId module support
  • Loading branch information
braizhas authored Jul 6, 2020
1 parent 9d4f8ff commit 7a36ee6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
var i, l, j, k, bid, _key, _value, reqParams, netRevenue, gdprObject;
const currency = config.getConfig('currency.adServerCurrency');
const eids = getEncodedEIDs(utils.deepAccess(validBidRequests, '0.userIdAsEids'));

var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ];
Expand Down Expand Up @@ -64,6 +65,10 @@ export const spec = {
request.push('us_privacy=' + bidderRequest.uspConsent);
}

if (eids) {
request.push('eids=' + eids);
}

for (i = 1, l = globalParams.length; i < l; i++) {
_key = globalParams[i][0];
_value = globalParams[i][1];
Expand Down Expand Up @@ -91,6 +96,28 @@ export const spec = {

return encodeURIComponent(btoa(url.join('').slice(0, -1)));
}

function getEncodedEIDs(eids) {
if (utils.isArray(eids) && eids.length > 0) {
const parsed = parseEIDs(eids);
return encodeURIComponent(btoa(JSON.stringify(parsed)));
}
}

function parseEIDs(eids) {
return eids.reduce((result, eid) => {
const source = eid.source;
result[source] = result[source] || {};

eid.uids.forEach(value => {
const id = value.id + '';
result[source][id] = result[source][id] || [];
result[source][id].push(value.atype);
});

return result;
}, {});
}
},
interpretResponse: function (serverResponse, bidRequest) {
const VALID_RESPONSES = {
Expand Down
5 changes: 5 additions & 0 deletions modules/adformOpenRTBBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const spec = {
const siteId = setOnAny(validBidRequests, 'params.siteId');
const currency = config.getConfig('currency.adServerCurrency');
const cur = currency && [ currency ];
const eids = setOnAny(validBidRequests, 'userIdAsEids');

const imp = validBidRequests.map((bid, id) => {
bid.netRevenue = pt;
Expand Down Expand Up @@ -133,6 +134,10 @@ export const spec = {
utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

if (eids) {
utils.deepSetValue(request, 'user.ext.eids', eids);
}

return {
method: 'POST',
url: 'https://' + adxDomain + '/adx/openrtb',
Expand Down
20 changes: 20 additions & 0 deletions test/spec/modules/adformBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {assert, expect} from 'chai';
import {spec} from 'modules/adformBidAdapter.js';
import { BANNER, VIDEO } from 'src/mediaTypes.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';

describe('Adform adapter', function () {
let serverResponse, bidRequest, bidResponses;
Expand Down Expand Up @@ -129,6 +130,25 @@ describe('Adform adapter', function () {
assert.equal(parsedUrl.query.pt, 'gross');
});

it('should pass extended ids', function () {
bids[0].userIdAsEids = createEidsArray({
tdid: 'TTD_ID_FROM_USER_ID_MODULE',
pubcid: 'pubCommonId_FROM_USER_ID_MODULE'
});
let request = spec.buildRequests(bids);
let eids = parseUrl(request.url).query.eids;

assert.equal(eids, 'eyJhZHNlcnZlci5vcmciOnsiVFREX0lEX0ZST01fVVNFUl9JRF9NT0RVTEUiOlsxXX0sInB1YmNpZC5vcmciOnsicHViQ29tbW9uSWRfRlJPTV9VU0VSX0lEX01PRFVMRSI6WzFdfX0%3D');
assert.deepEqual(JSON.parse(atob(decodeURIComponent(eids))), {
'adserver.org': {
'TTD_ID_FROM_USER_ID_MODULE': [1]
},
'pubcid.org': {
'pubCommonId_FROM_USER_ID_MODULE': [1]
}
});
});

describe('user privacy', function () {
it('should send GDPR Consent data to adform if gdprApplies', function () {
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});
Expand Down
18 changes: 18 additions & 0 deletions test/spec/modules/adformOpenRTBBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {assert, expect} from 'chai';
import {spec} from 'modules/adformOpenRTBBidAdapter.js';
import { NATIVE } from 'src/mediaTypes.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';

describe('AdformOpenRTB adapter', function () {
let serverResponse, bidRequest, bidResponses;
Expand Down Expand Up @@ -166,6 +167,23 @@ describe('AdformOpenRTB adapter', function () {
});
});

it('should pass extended ids', function () {
let validBidRequests = [{
bidId: 'bidId',
params: {},
userIdAsEids: createEidsArray({
tdid: 'TTD_ID_FROM_USER_ID_MODULE',
pubcid: 'pubCommonId_FROM_USER_ID_MODULE'
})
}];

let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data);
assert.deepEqual(request.user.ext.eids, [
{ source: 'adserver.org', uids: [ { id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: { rtiPartner: 'TDID' } } ] },
{ source: 'pubcid.org', uids: [ { id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1 } ] }
]);
});

it('should send currency if defined', function () {
config.setConfig({ currency: { adServerCurrency: 'EUR' } });
let validBidRequests = [{ params: {} }];
Expand Down

0 comments on commit 7a36ee6

Please sign in to comment.