Skip to content

Commit

Permalink
Smartadserver Bid Adapter : add DSA support (#12141)
Browse files Browse the repository at this point in the history
* add support of dsa

* restore topics

* DSA fix for UT
  • Loading branch information
eszponder authored Aug 21, 2024
1 parent 4d06091 commit 825fc6e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
22 changes: 20 additions & 2 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { deepAccess, deepClone, isArrayOfNums, isFn, isInteger, isPlainObject, logError } from '../src/utils.js';
import {
deepAccess,
deepClone,
isArray,
isArrayOfNums,
isEmpty,
isFn,
isInteger,
isPlainObject,
logError
} from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -204,6 +214,11 @@ export const spec = {
payload.gpid = gpid;
}

const dsa = deepAccess(bid, 'ortb2.regs.ext.dsa');
if (dsa) {
payload.dsa = dsa;
}

if (bidderRequest) {
if (bidderRequest.gdprConsent) {
payload.addtl_consent = bidderRequest.gdprConsent.addtlConsent;
Expand Down Expand Up @@ -285,7 +300,10 @@ export const spec = {
netRevenue: response.isNetCpm,
ttl: response.ttl,
dspPixels: response.dspPixels,
meta: { advertiserDomains: response.adomain ? response.adomain : [] }
meta: {
...isArray(response.adomain) && !isEmpty(response.adomain) ? { advertiserDomains: response.adomain } : {},
...!isEmpty(response.dsa) ? { dsa: response.dsa } : {}
}
};

if (bidRequest.mediaType === VIDEO) {
Expand Down
58 changes: 58 additions & 0 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,32 @@ describe('Smart bid adapter tests', function () {
});
});

it('Verify metadata', function () {
const adomain = ['advertiser-domain.com'];
const dsa = {
dsarequired: 1,
pubrender: 0,
datatopub: 1,
transparency: [{
domain: 'smartadserver.com',
dsaparams: [1, 2]
}]
};
const request = spec.buildRequests(DEFAULT_PARAMS);
const bids = spec.interpretResponse({
body: {
...BID_RESPONSE.body,
adomain,
dsa,
}
}, request[0]);

expect(bids[0].cpm).to.equal(12);
expect(bids[0]).to.have.property('meta');
expect(bids[0].meta).to.have.property('advertiserDomains').and.to.deep.equal(adomain);
expect(bids[0].meta).to.have.property('dsa').and.to.deep.equal(dsa);
});

describe('gdpr tests', function () {
afterEach(function () {
config.setConfig({ ortb2: undefined });
Expand Down Expand Up @@ -1512,6 +1538,38 @@ describe('Smart bid adapter tests', function () {
});
});

describe('Digital Services Act (DSA)', function () {
it('should include dsa if ortb2.regs.ext.dsa available', function () {
const dsa = {
dsarequired: 1,
pubrender: 0,
datatopub: 1,
transparency: [
{
domain: 'ok.domain.com',
dsaparams: [1, 2]
},
{
domain: 'ko.domain.com',
dsaparams: [1, '3']
}
]
};

const bidRequests = deepClone(DEFAULT_PARAMS_WO_OPTIONAL);
bidRequests[0].ortb2 = {
regs: {
ext: { dsa }
}
};

const request = spec.buildRequests(bidRequests);
const requestContent = JSON.parse(request[0].data);

expect(requestContent).to.have.property('dsa').and.to.deep.equal(dsa);
});
});

describe('#getValuableProperty method', function () {
it('should return an object when calling with a number value', () => {
const obj = spec.getValuableProperty('prop', 3);
Expand Down

0 comments on commit 825fc6e

Please sign in to comment.