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

IX Bid Adapter: support DSA fields #11069

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
isEmpty,
isFn,
isInteger,
isNumber,
isStr,
isPlainObject,
logError,
logWarn,
mergeDeep,
Expand Down Expand Up @@ -520,6 +523,9 @@ function parseBid(rawBid, currency, bidRequest) {
if (rawBid.adomain && rawBid.adomain.length > 0) {
bid.meta.advertiserDomains = rawBid.adomain;
}
if (rawBid.ext?.dsa) {
bid.meta.dsa = rawBid.ext.dsa
}
return bid;
}

Expand Down Expand Up @@ -1212,6 +1218,7 @@ function addFPD(bidderRequest, r, fpd, site, user) {
}
}

// regulations from ortb2
if (fpd.hasOwnProperty('regs') && !bidderRequest.gppConsent) {
if (fpd.regs.hasOwnProperty('gpp') && typeof fpd.regs.gpp == 'string') {
deepSetValue(r, 'regs.gpp', fpd.regs.gpp)
Expand All @@ -1220,6 +1227,30 @@ function addFPD(bidderRequest, r, fpd, site, user) {
if (fpd.regs.hasOwnProperty('gpp_sid') && Array.isArray(fpd.regs.gpp_sid)) {
deepSetValue(r, 'regs.gpp_sid', fpd.regs.gpp_sid)
}

if (fpd.regs.ext?.dsa) {
const pubDsaObj = fpd.regs.ext.dsa;
const dsaObj = {};
['dsarequired', 'pubrender', 'datatopub'].forEach((dsaKey) => {
if (isNumber(pubDsaObj[dsaKey])) {
dsaObj[dsaKey] = pubDsaObj[dsaKey];
}
});

if (isArray(pubDsaObj.transparency)) {
const tpData = [];
pubDsaObj.transparency.forEach((tpObj) => {
if (isPlainObject(tpObj) && isStr(tpObj.domain) && tpObj.domain != '' && isArray(tpObj.dsaparams) && tpObj.dsaparams.every((v) => isNumber(v))) {
tpData.push(tpObj);
}
});
if (tpData.length > 0) {
dsaObj.transparency = tpData;
}
}

if (!isEmpty(dsaObj)) deepSetValue(r, 'regs.ext.dsa', dsaObj);
}
}

return r;
Expand Down
141 changes: 140 additions & 1 deletion test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,45 @@ describe('IndexexchangeAdapter', function () {
]
};

const DEFAULT_BANNER_BID_RESPONSE_WITH_DSA = {
cur: 'USD',
id: '11a22b33c44d',
seatbid: [
{
bid: [
{
crid: '12345',
adomain: ['www.abc.com'],
adid: '14851455',
impid: '1a2b3c4d',
cid: '3051266',
price: 100,
w: 300,
h: 250,
id: '1',
ext: {
dspid: 50,
pricelevel: '_100',
advbrandid: 303325,
advbrand: 'OECTA',
dsa: {
behalf: 'Advertiser',
paid: 'Advertiser',
transparency: [{
domain: 'dsp1domain.com',
dsaparams: [1, 2]
}],
'adrender': 1
}
},
adm: '<a target="_blank" href="https://www.indexexchange.com"></a>'
}
],
seat: '3970'
}
]
};

const DEFAULT_BANNER_BID_RESPONSE_WITHOUT_ADOMAIN = {
cur: 'USD',
id: '11a22b33c44d',
Expand Down Expand Up @@ -1903,6 +1942,72 @@ describe('IndexexchangeAdapter', function () {
expect(r.user.testProperty).to.be.undefined;
});

it('should set dsa field when defined', function () {
const dsa = {
dsarequired: 3,
pubrender: 0,
datatopub: 2,
transparency: [{
domain: 'domain.com',
dsaparams: [1]
}]
}
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {
ext: {
dsa: deepClone(dsa)
}
}
}})[0];
const r = extractPayload(request);

expect(r.regs.ext.dsa.dsarequired).to.equal(dsa.dsarequired);
expect(r.regs.ext.dsa.pubrender).to.equal(dsa.pubrender);
expect(r.regs.ext.dsa.datatopub).to.equal(dsa.datatopub);
expect(r.regs.ext.dsa.transparency).to.be.an('array');
expect(r.regs.ext.dsa.transparency).to.have.deep.members(dsa.transparency);
});
it('should not set dsa fields when fields arent appropriately defined', function () {
const dsa = {
dsarequired: '3',
pubrender: '0',
datatopub: '2',
transparency: 20
}
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {
ext: {
dsa: deepClone(dsa)
}
}
}})[0];
const r = extractPayload(request);

expect(r.regs).to.be.undefined;
});
it('should not set dsa transparency when fields arent appropriately defined', function () {
const dsa = {
transparency: [{
domain: 3,
dsaparams: [1]
},
{
domain: 'domain.com',
dsaparams: 'params'
},
{
domain: 'domain.com',
dsaparams: ['1']
}]
}
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {
ext: {
dsa: deepClone(dsa)
}
}
}})[0];
const r = extractPayload(request);

expect(r.regs).to.be.undefined;
});
it('should set gpp and gpp_sid field when defined', function () {
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {gpp: 'gpp', gpp_sid: [1]}} })[0];
const r = extractPayload(request);
Expand All @@ -1911,7 +2016,7 @@ describe('IndexexchangeAdapter', function () {
expect(r.regs.gpp_sid).to.be.an('array');
expect(r.regs.gpp_sid).to.include(1);
});
it('should not set gpp and gpp_sid field when not defined', function () {
it('should not set gpp, gpp_sid and dsa field when not defined', function () {
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {}} })[0];
const r = extractPayload(request);

Expand Down Expand Up @@ -3529,6 +3634,40 @@ describe('IndexexchangeAdapter', function () {
expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('should get correct bid response for banner ad with dsa signals', function () {
const expectedParse = [
{
requestId: '1a2b3c4d',
cpm: 1,
creativeId: '12345',
width: 300,
height: 250,
mediaType: 'banner',
ad: '<a target="_blank" href="https://www.indexexchange.com"></a>',
currency: 'USD',
ttl: 300,
netRevenue: true,
meta: {
networkId: 50,
brandId: 303325,
brandName: 'OECTA',
advertiserDomains: ['www.abc.com'],
dsa: {
behalf: 'Advertiser',
paid: 'Advertiser',
transparency: [{
domain: 'dsp1domain.com',
dsaparams: [1, 2]
}],
'adrender': 1
}
}
}
];
const result = spec.interpretResponse({ body: DEFAULT_BANNER_BID_RESPONSE_WITH_DSA }, bannerBidderRequest);
expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('should get correct bid response for banner ad with missing adomain', function () {
const expectedParse = [
{
Expand Down