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

Dailymotion Bid Adaptor: add gpp support and get coppa from request #14

Merged
merged 1 commit into from
Apr 18, 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
12 changes: 9 additions & 3 deletions modules/dailymotionBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO } from '../src/mediaTypes.js';
import { deepAccess } from '../src/utils.js';
Expand Down Expand Up @@ -47,7 +46,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return ((typeof bid !== 'undefined') && (typeof bid?.params?.apiKey === 'string') && (bid.params.apiKey.length > 10));
return typeof bid?.params?.apiKey === 'string' && bid.params.apiKey.length > 10;
},

/**
Expand All @@ -72,11 +71,18 @@ export const spec = {
page: bidderRequest?.refererInfo?.page || '',
},
uspConsent: bidderRequest?.uspConsent || '',
gppConsent: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this follows validated way of getting gpp values (example: https://github.com/prebid/Prebid.js/pull/11239/files)

gppString: deepAccess(bidderRequest, 'gppConsent.gppString')
|| deepAccess(bidderRequest, 'ortb2.regs.gpp', ''),
applicableSections: deepAccess(bidderRequest, 'gppConsent.applicableSections')
|| deepAccess(bidderRequest, 'ortb2.regs.gpp_sid', []),
},
},
config: {
api_key: bid.params.apiKey
},
coppa: config.getConfig('coppa'),
// Cast boolean in any case (value should be 0 or 1) to ensure type
coppa: !!deepAccess(bidderRequest, 'ortb2.regs.coppa'),
request: {
adUnitCode: bid.adUnitCode || '',
auctionId: bid.auctionId || '',
Expand Down
115 changes: 110 additions & 5 deletions test/spec/modules/dailymotionBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ describe('dailymotionBidAdapterTests', () => {

// Validate request generation
it('validates buildRequests', () => {
config.setConfig({ coppa: true });

const bidRequestData = [{
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidId: 123456,
Expand Down Expand Up @@ -70,6 +68,15 @@ describe('dailymotionBidAdapterTests', () => {
consentString: 'xxx',
gdprApplies: true,
},
gppConsent: {
gppString: 'xxx',
applicableSections: [5],
},
ortb2: {
regs: {
coppa: 1,
},
},
};

const [request] = config.runWithBidder(
Expand All @@ -81,7 +88,12 @@ describe('dailymotionBidAdapterTests', () => {

expect(request.url).to.equal('https://pb.dmxleo.com');

expect(reqData.bidder_request).to.eql(bidderRequestData);
expect(reqData.bidder_request).to.eql({
refererInfo: bidderRequestData.refererInfo,
uspConsent: bidderRequestData.uspConsent,
gdprConsent: bidderRequestData.gdprConsent,
gppConsent: bidderRequestData.gppConsent,
});
expect(reqData.config.api_key).to.eql(bidRequestData[0].params.apiKey);
expect(reqData.coppa).to.be.true;
expect(reqData.request.auctionId).to.eql(bidRequestData[0].auctionId);
Expand All @@ -104,15 +116,104 @@ describe('dailymotionBidAdapterTests', () => {
});
});

it('validates buildRequests with fallback values on ortb2 for gpp', () => {
const bidRequestData = [{
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidId: 123456,
adUnitCode: 'preroll',
mediaTypes: {
video: {
playerSize: [[1280, 720]],
api: [2, 7],
description: 'this is a test video',
duration: 300,
iabcat2: ['6', '17'],
lang: 'ENG',
startdelay: 0,
},
},
sizes: [[1920, 1080]],
params: {
apiKey: 'test_api_key',
video: {
duration: 556,
id: '54321',
lang: 'FR',
private: false,
tags: 'tag_1,tag_2,tag_3',
title: 'test video',
topics: 'topic_1, topic_2',
xid: 'x123456',
},
},
}];

const bidderRequestData = {
refererInfo: {
page: 'https://publisher.com',
},
uspConsent: '1YN-',
gdprConsent: {
apiVersion: 2,
consentString: 'xxx',
gdprApplies: true,
},
ortb2: {
regs: {
gpp: 'xxx',
gpp_sid: [5],
coppa: 0,
},
},
};

const [request] = config.runWithBidder(
'dailymotion',
() => spec.buildRequests(bidRequestData, bidderRequestData),
);

const { data: reqData } = request;

expect(request.url).to.equal('https://pb.dmxleo.com');

expect(reqData.bidder_request).to.eql({
refererInfo: bidderRequestData.refererInfo,
uspConsent: bidderRequestData.uspConsent,
gdprConsent: bidderRequestData.gdprConsent,
gppConsent: {
gppString: bidderRequestData.ortb2.regs.gpp,
applicableSections: bidderRequestData.ortb2.regs.gpp_sid,
},
});
expect(reqData.config.api_key).to.eql(bidRequestData[0].params.apiKey);
expect(reqData.coppa).to.be.false;
expect(reqData.request.auctionId).to.eql(bidRequestData[0].auctionId);
expect(reqData.request.bidId).to.eql(bidRequestData[0].bidId);
expect(reqData.request.mediaTypes.video.api).to.eql(bidRequestData[0].mediaTypes.video.api);
expect(reqData.request.mediaTypes.video.playerSize).to.eql(bidRequestData[0].mediaTypes.video.playerSize);
expect(reqData.request.mediaTypes.video.startDelay).to.eql(bidRequestData[0].mediaTypes.video.startdelay);
expect(reqData.video_metadata).to.eql({
description: bidRequestData[0].mediaTypes.video.description,
iabcat2: bidRequestData[0].mediaTypes.video.iabcat2,
id: bidRequestData[0].params.video.id,
lang: bidRequestData[0].params.video.lang,
private: bidRequestData[0].params.video.private,
tags: bidRequestData[0].params.video.tags,
title: bidRequestData[0].params.video.title,
topics: bidRequestData[0].params.video.topics,
xid: bidRequestData[0].params.video.xid,
// Overriden through bidder params
duration: bidRequestData[0].params.video.duration,
});
});

it('validates buildRequests - with default values on empty bid & bidder request', () => {
const bidRequestDataWithApi = [{
params: {
apiKey: 'test_api_key',
},
}];

config.setConfig({ coppa: false });

const [request] = config.runWithBidder(
'dailymotion',
() => spec.buildRequests(bidRequestDataWithApi, {}),
Expand All @@ -135,6 +236,10 @@ describe('dailymotionBidAdapterTests', () => {
page: '',
},
uspConsent: '',
gppConsent: {
gppString: '',
applicableSections: [],
},
});

expect(reqData.request).to.eql({
Expand Down