Skip to content

Commit

Permalink
Adf Bid Adapter: use common ortb2 data (prebid#12582)
Browse files Browse the repository at this point in the history
* use common ortb2 data from bidderRequest

* set iab categories on bid response
  • Loading branch information
braizhas authored Dec 18, 2024
1 parent cc3e707 commit 8162df6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 98 deletions.
56 changes: 24 additions & 32 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const spec = {
let app, site;

const commonFpd = bidderRequest.ortb2 || {};
let { user } = commonFpd;
let user = commonFpd.user || {};

if (typeof getConfig('app') === 'object') {
app = getConfig('app') || {};
Expand All @@ -51,21 +51,35 @@ export const spec = {
}
}

const device = getConfig('device') || {};
let device = getConfig('device') || {};
if (commonFpd.device) {
mergeDeep(device, commonFpd.device);
}
device.w = device.w || window.innerWidth;
device.h = device.h || window.innerHeight;
device.ua = device.ua || navigator.userAgent;

let source = commonFpd.source || {};
source.fd = 1;

let regs = commonFpd.regs || {};

const adxDomain = setOnAny(validBidRequests, 'params.adxDomain') || 'adx.adform.net';

const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net';
const tid = bidderRequest.ortb2?.source?.tid;
const test = setOnAny(validBidRequests, 'params.test');
const currency = getCurrencyFromBidderRequest(bidderRequest);
const cur = currency && [ currency ];
const eids = setOnAny(validBidRequests, 'userIdAsEids');
const schain = setOnAny(validBidRequests, 'schain');
const dsa = commonFpd.regs?.ext?.dsa;

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

if (schain) {
deepSetValue(source, 'ext.schain', schain);
}

const imp = validBidRequests.map((bid, id) => {
bid.netRevenue = pt;
Expand Down Expand Up @@ -151,42 +165,18 @@ export const spec = {
app,
user,
device,
source: { tid, fd: 1 },
source,
ext: { pt },
cur,
imp
imp,
regs
};

if (test) {
request.is_debug = !!test;
request.test = 1;
}

if (config.getConfig('coppa')) {
deepSetValue(request, 'regs.coppa', 1);
}

if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) {
deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1);
}

if (bidderRequest.uspConsent) {
deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

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

if (schain) {
deepSetValue(request, 'source.ext.schain', schain);
}

if (dsa) {
deepSetValue(request, 'regs.ext.dsa', dsa);
}

return {
method: 'POST',
url: 'https://' + adxDomain + '/adx/openrtb',
Expand Down Expand Up @@ -224,7 +214,9 @@ export const spec = {
meta: {
mediaType,
advertiserDomains: bidResponse.adomain,
dsa
dsa,
primaryCatId: bidResponse.cat?.[0],
secondaryCatIds: bidResponse.cat?.slice(1)
}
};

Expand Down
117 changes: 51 additions & 66 deletions test/spec/modules/adfBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,68 +82,52 @@ describe('Adf adapter', function () {
});

describe('user privacy', function () {
it('should send GDPR Consent data to adform if gdprApplies', function () {
it('should send GDPR Consent data to adform', function () {
let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }];
let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } };
let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.user.ext.consent, bidderRequest.gdprConsent.consentString);
assert.equal(request.regs.ext.gdpr, bidderRequest.gdprConsent.gdprApplies);
assert.equal(typeof request.regs.ext.gdpr, 'number');
});

it('should send gdpr as number', function () {
let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }];
let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } };
let ortb2 = {
regs: {
ext: {
gdpr: 1
}
},
user: {
ext: {
consent: 'consentDataString'
}
}
};
let bidderRequest = { ortb2, refererInfo: { page: 'page' } };
let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(typeof request.regs.ext.gdpr, 'number');
assert.equal(request.user.ext.consent, 'consentDataString');
assert.equal(request.regs.ext.gdpr, 1);
});

it('should send CCPA Consent data to adform', function () {
let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }];
let bidderRequest = { uspConsent: '1YA-', refererInfo: { page: 'page' } };
let ortb2 = {
regs: {
ext: {
us_privacy: '1YA-'
}
}
};
let bidderRequest = { ortb2, refererInfo: { page: 'page' } };
let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.regs.ext.us_privacy, '1YA-');

bidderRequest = { uspConsent: '1YA-', gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } };
ortb2.regs.ext.gdpr = 1;
ortb2.user = { ext: { consent: 'consentDataString' } };

bidderRequest = { ortb2, refererInfo: { page: 'page' } };
request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.regs.ext.us_privacy, '1YA-');
assert.equal(request.user.ext.consent, 'consentDataString');
assert.equal(request.regs.ext.gdpr, 1);
});

it('should not send GDPR Consent data to adform if gdprApplies is undefined', function () {
let validBidRequests = [{
bidId: 'bidId',
params: { siteId: 'siteId' }
}];
let bidderRequest = { gdprConsent: {gdprApplies: false, consentString: 'consentDataString'}, refererInfo: { page: 'page' } };
let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.user.ext.consent, 'consentDataString');
assert.equal(request.regs.ext.gdpr, 0);

bidderRequest = {gdprConsent: {consentString: 'consentDataString'}, refererInfo: { page: 'page' }};
request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.user, undefined);
assert.equal(request.regs, undefined);
});
it('should send default GDPR Consent data to adform', function () {
let validBidRequests = [{
bidId: 'bidId',
params: { siteId: 'siteId' }
}];
let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data);

assert.equal(request.user, undefined);
assert.equal(request.regs, undefined);
});

it('should transfer DSA info', function () {
let validBidRequests = [ { bidId: 'bidId', params: { siteId: 'siteId' } } ];

Expand Down Expand Up @@ -200,7 +184,7 @@ describe('Adf adapter', function () {
});

it('should have default request structure', function () {
let keys = 'site,device,source,ext,imp'.split(',');
let keys = 'site,user,device,source,ext,imp,regs'.split(',');
let validBidRequests = [{
bidId: 'bidId',
params: { siteId: 'siteId' }
Expand All @@ -225,46 +209,44 @@ describe('Adf adapter', function () {
assert.equal(request.source.fd, 1);
});

it('should not set coppa when coppa is not provided or is set to false', function () {
config.setConfig({
});
it('should send coppa flag', function () {
let ortb2 = { regs: { coppa: 1 } };
let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }];
let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } };
let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.regs.coppa, undefined);
let request = JSON.parse(spec.buildRequests(validBidRequests, { ortb2, refererInfo: { page: 'page' } }).data);

config.setConfig({
coppa: false
});
request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data);

assert.equal(request.regs.coppa, undefined);
assert.equal(request.regs.coppa, 1);
});

it('should set coppa to 1 when coppa is provided with value true', function () {
it('should send info about device', function () {
config.setConfig({
coppa: true
device: { w: 100, h: 100 }
});
let validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }];
let validBidRequests = [{
bidId: 'bidId',
params: { mid: '1000' }
}];
let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data);

assert.equal(request.regs.coppa, 1);
assert.equal(request.device.ua, navigator.userAgent);
assert.equal(request.device.w, 100);
assert.equal(request.device.h, 100);
});

it('should send info about device', function () {
it('should merge ortb2.device info', function () {
config.setConfig({
device: { w: 100, h: 100 }
});
let validBidRequests = [{
bidId: 'bidId',
params: { mid: '1000' }
}];
let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data);
let ortb2 = { device: { ua: 'customUA', w: 200, geo: { lat: 1, lon: 1 } } };
let request = JSON.parse(spec.buildRequests(validBidRequests, { ortb2, refererInfo: { page: 'page' } }).data);

assert.equal(request.device.ua, navigator.userAgent);
assert.equal(request.device.w, 100);
assert.equal(request.device.ua, 'customUA');
assert.equal(request.device.w, 200);
assert.equal(request.device.h, 100);
assert.deepEqual(request.device.geo, { lat: 1, lon: 1 });
});

it('should send app info', function () {
Expand Down Expand Up @@ -1075,7 +1057,8 @@ describe('Adf adapter', function () {
}],
adrender: 1
}
}
},
cat: [ 'IAB1', 'IAB2' ]
}
]
}],
Expand Down Expand Up @@ -1135,6 +1118,8 @@ describe('Adf adapter', function () {
assert.deepEqual(bids[0].currency, serverResponse.body.cur);
assert.deepEqual(bids[0].mediaType, 'native');
assert.deepEqual(bids[0].meta.mediaType, 'native');
assert.deepEqual(bids[0].meta.primaryCatId, 'IAB1');
assert.deepEqual(bids[0].meta.secondaryCatIds, [ 'IAB2' ]);
assert.deepEqual(bids[0].meta.advertiserDomains, [ 'demo.com' ]);
assert.deepEqual(bids[0].meta.dsa, {
behalf: 'some-behalf',
Expand Down

0 comments on commit 8162df6

Please sign in to comment.