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

Yieldlab Bid Adapter: Add Digital Services Act (DSA) handling #10981

Merged
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
54 changes: 50 additions & 4 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export const spec = {
* @returns {boolean}
*/
isBidRequestValid(bid) {
if (bid && bid.params && bid.params.adslotId && bid.params.supplyId) {
return true;
}
return false;
return !!(bid && bid.params && bid.params.adslotId && bid.params.supplyId && isTransparencyCountOneOrLess(bid.params));
},

/**
Expand Down Expand Up @@ -83,6 +80,29 @@ export const spec = {
if (floor) {
adslotFloors.push(bid.params.adslotId + ':' + floor);
}
const dsaRequired = bid.params.regs?.ext?.dsa?.required;
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
if (dsaRequired !== undefined) {
query.dsarequired = dsaRequired;
}
const dsaPubRender = bid.params.regs?.ext?.dsa?.pubrender;
if (dsaPubRender !== undefined) {
query.dsapubrender = dsaPubRender;
}
const dsaDataToPub = bid.params.regs?.ext?.dsa?.datatopub;
if (dsaDataToPub !== undefined) {
query.dsadatatopub = dsaDataToPub;
}
const dsaTransparency = bid.params.regs?.ext?.dsa?.transparency;
if (Array.isArray(dsaTransparency) && dsaTransparency.length > 0) {
const dsaDomain = dsaTransparency[0].domain;
if (dsaDomain !== undefined) {
query.dsadomain = dsaDomain;
}
const dsaParams = dsaTransparency[0].params;
if (Array.isArray(dsaParams) && dsaParams.length > 0) {
query.dsaparams = dsaParams.join(',');
}
}
});

if (bidderRequest) {
Expand Down Expand Up @@ -165,6 +185,12 @@ export const spec = {
},
};

const dsa = getDigitalServicesActObjectFromMatchedBid(matchedBid)
if (dsa !== undefined) {
bidResponse.ext = bidResponse.ext || {};
bidResponse.ext.dsa = dsa;
}

if (isVideo(bidRequest, adType)) {
const playersize = getPlayerSize(bidRequest);
if (playersize) {
Expand Down Expand Up @@ -536,4 +562,24 @@ function isImageAssetOfType(type) {
return asset => asset?.img?.type === type;
}

/**
* Determines if the 'transparency' array within the bid parameters has one or fewer elements.
*
* @param {Object} params - Bid parameters containing the nested 'transparency' array.
* @returns {boolean} - Returns true if the 'transparency' field is either undefined, or contains an array with at most one element; returns false otherwise.
*/
function isTransparencyCountOneOrLess(params) {
return (params?.regs?.ext?.dsa?.transparency?.length ?? 0) <= 1;
}

/**
* Retrieves the Digital Services Act (DSA) object from a matched bid.
*
* @param {Object} matchedBid - The server response body to inspect for the DSA information.
* @returns {Object|undefined} A copy of the DSA object if it exists, or undefined if not.
*/
function getDigitalServicesActObjectFromMatchedBid(matchedBid) {
return matchedBid.ext?.dsa ? { ...matchedBid.ext.dsa } : undefined;
}

registerBidder(spec);
150 changes: 150 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,51 @@ const IAB_REQUEST = () => Object.assign(DEFAULT_REQUEST(), {
},
});

const DIGITAL_SERVICES_ACT_REQUEST = () => Object.assign(DEFAULT_REQUEST(), {
params: {
adslotId: '1111',
supplyId: '2222',
targeting: {
key1: 'value1',
key2: 'value2',
notDoubleEncoded: 'value3,value4',
},
customParams: {
extraParam: true,
foo: 'bar',
},
extId: 'abc',
iabContent: {
id: 'foo_id',
episode: '99',
title: 'foo_title,bar_title',
series: 'foo_series',
season: 's1',
artist: 'foo bar',
genre: 'baz',
isrc: 'CC-XXX-YY-NNNNN',
url: 'http://foo_url.de',
cat: ['cat1', 'cat2,ppp', 'cat3|||//'],
context: '7',
keywords: ['k1,', 'k2..'],
live: '0',
},
regs: {
ext: {
dsa: {
required: '1',
pubrender: '2',
datatopub: '3',
transparency: [{
domain: 'test.com',
params: [1, 2, 3]
}]
},
}
},
},
});

const RESPONSE = {
advertiser: 'yieldlab',
curl: 'https://www.yieldlab.de',
Expand Down Expand Up @@ -226,6 +271,20 @@ const PVID_RESPONSE = Object.assign({}, VIDEO_RESPONSE, {
pvid: '43513f11-55a0-4a83-94e5-0ebc08f54a2c',
});

const DIGITAL_SERVICES_ACT_RESPONSE = Object.assign({}, RESPONSE, {
ext: {
dsa: {
required: '1',
pubrender: '2',
datatopub: '3',
transparency: [{
domain: 'test.com',
params: [1, 2, 3]
}]
}
}
});

const REQPARAMS = {
json: true,
ts: 1234567890,
Expand Down Expand Up @@ -262,6 +321,49 @@ describe('yieldlabBidAdapter', () => {
it('should return false when required parameters are missing', () => {
expect(spec.isBidRequestValid({})).to.equal(false);
});

it('should return false if more than one transparency object is found', () => {
const request = {
params: {
adslotId: '1111',
supplyId: '2222',
regs: {
ext: {
dsa: {
transparency: [{
domain: 'test.com',
params: [1, 2, 3]
}, {
domain: 'yieldlab.com',
params: [1, 2, 3]
}]
},
}
},
},
};
expect(spec.isBidRequestValid(request)).to.equal(false);
});

it('should return true if one transparency object is found', () => {
const request = {
params: {
adslotId: '1111',
supplyId: '2222',
regs: {
ext: {
dsa: {
transparency: [{
domain: 'test.com',
params: [1, 2, 3]
}]
},
}
},
},
};
expect(spec.isBidRequestValid(request)).to.equal(true);
});
});

describe('buildRequests', () => {
Expand Down Expand Up @@ -486,6 +588,43 @@ describe('yieldlabBidAdapter', () => {
expect(request.url).to.not.include('sizes');
});
});

describe('Digital Services Act handling', () => {
it('does pass dsarequired parameter', () => {
const dsaRequest = DIGITAL_SERVICES_ACT_REQUEST();

let request = spec.buildRequests([dsaRequest], REQPARAMS);
expect(request.url).to.include('dsarequired=1');
});

it('does pass dsapubrender parameter', () => {
const dsaRequest = DIGITAL_SERVICES_ACT_REQUEST();

let request = spec.buildRequests([dsaRequest], REQPARAMS);
expect(request.url).to.include('dsapubrender=2');
});

it('does pass dsadatatopub parameter', () => {
const dsaRequest = DIGITAL_SERVICES_ACT_REQUEST();

let request = spec.buildRequests([dsaRequest], REQPARAMS);
expect(request.url).to.include('dsadatatopub=3');
});

it('does pass dsadomain parameter', () => {
const dsaRequest = DIGITAL_SERVICES_ACT_REQUEST();

let request = spec.buildRequests([dsaRequest], REQPARAMS);
expect(request.url).to.include('dsadomain=test.com');
});

it('does pass encoded dsaparams parameter', () => {
const dsaRequest = DIGITAL_SERVICES_ACT_REQUEST();

let request = spec.buildRequests([dsaRequest], REQPARAMS);
expect(request.url).to.include('dsaparams=1%2C2%2C3');
});
});
});

describe('interpretResponse', () => {
Expand Down Expand Up @@ -676,6 +815,17 @@ describe('yieldlabBidAdapter', () => {
const result = spec.interpretResponse({body: [VIDEO_RESPONSE]}, {validBidRequests: [VIDEO_REQUEST()], queryParams: REQPARAMS_IAB_CONTENT});
expect(result[0].vastUrl).to.include('&iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0');
});

it('should get digital services act object in matched bid response', () => {
const result = spec.interpretResponse({body: [DIGITAL_SERVICES_ACT_RESPONSE]}, {validBidRequests: [DIGITAL_SERVICES_ACT_REQUEST()], queryParams: REQPARAMS});

expect(result[0].requestId).to.equal('2d925f27f5079f');
expect(result[0].ext.dsa.required).to.equal('1');
expect(result[0].ext.dsa.pubrender).to.equal('2');
expect(result[0].ext.dsa.datatopub).to.equal('3');
expect(result[0].ext.dsa.transparency[0].domain).to.equal('test.com');
expect(result[0].ext.dsa.transparency[0].params).to.deep.equal([1, 2, 3]);
});
});

describe('getUserSyncs', () => {
Expand Down