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

Adagio bid adapter: support priceFloors module #6867

Merged
merged 1 commit into from
Jun 1, 2021
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
57 changes: 54 additions & 3 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const RENDERER_URL = 'https://script.4dex.io/outstream-player.js';
const MAX_SESS_DURATION = 30 * 60 * 1000;
const ADAGIO_PUBKEY = 'AL16XT44Sfp+8SHVF1UdC7hydPSMVLMhsYknKDdwqq+0ToDSJrP0+Qh0ki9JJI2uYm/6VEYo8TJED9WfMkiJ4vf02CW3RvSWwc35bif2SK1L8Nn/GfFYr/2/GG/Rm0vUsv+vBHky6nuuYls20Og0HDhMgaOlXoQ/cxMuiy5QSktp';
const ADAGIO_PUBKEY_E = 65537;
const CURRENCY = 'USD';
const DEFAULT_FLOOR = 0.1;

// This provide a whitelist and a basic validation
// of OpenRTB 2.5 options used by the Adagio SSP.
Expand Down Expand Up @@ -819,6 +821,48 @@ function _parseNativeBidResponse(bid) {
bid.native = native
}

function _getFloors(bidRequest) {
if (!utils.isFn(bidRequest.getFloor)) {
return false;
}

const floors = [];

const getAndPush = (mediaType, size) => {
const info = bidRequest.getFloor({
currency: CURRENCY,
mediaType,
size: []
});

floors.push(utils.cleanObj({
mt: mediaType,
s: utils.isArray(size) ? `${size[0]}x${size[1]}` : undefined,
f: (!isNaN(info.floor) && info.currency === CURRENCY) ? info.floor : DEFAULT_FLOOR
}));
}

Object.keys(bidRequest.mediaTypes).forEach(mediaType => {
if (SUPPORTED_MEDIA_TYPES.indexOf(mediaType) !== -1) {
const sizeProp = mediaType === VIDEO ? 'playerSize' : 'sizes';

if (bidRequest.mediaTypes[mediaType][sizeProp] && bidRequest.mediaTypes[mediaType][sizeProp].length) {
if (utils.isArray(bidRequest.mediaTypes[mediaType][sizeProp][0])) {
bidRequest.mediaTypes[mediaType][sizeProp].forEach(size => {
getAndPush(mediaType, [size[0], size[1]]);
});
} else {
getAndPush(mediaType, [bidRequest.mediaTypes[mediaType][sizeProp][0], bidRequest.mediaTypes[mediaType][sizeProp][1]]);
}
} else {
getAndPush(mediaType, '*');
}
}
});

return floors;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down Expand Up @@ -914,6 +958,9 @@ export const spec = {
const adUnits = utils._map(validBidRequests, (bidRequest) => {
bidRequest.features = internal.getFeatures(bidRequest, bidderRequest);

// Handle priceFloors module
bidRequest.floors = _getFloors(bidRequest);

if (utils.deepAccess(bidRequest, 'mediaTypes.video')) {
_buildVideoBidRequest(bidRequest);
}
Expand All @@ -923,10 +970,14 @@ export const spec = {

// Group ad units by organizationId
const groupedAdUnits = adUnits.reduce((groupedAdUnits, adUnit) => {
adUnit.params.organizationId = adUnit.params.organizationId.toString();
const adUnitCopy = utils.deepClone(adUnit);
adUnitCopy.params.organizationId = adUnitCopy.params.organizationId.toString();

// remove useless props
delete adUnitCopy.floorData;

groupedAdUnits[adUnit.params.organizationId] = groupedAdUnits[adUnit.params.organizationId] || [];
groupedAdUnits[adUnit.params.organizationId].push(adUnit);
groupedAdUnits[adUnitCopy.params.organizationId] = groupedAdUnits[adUnitCopy.params.organizationId] || [];
groupedAdUnits[adUnitCopy.params.organizationId].push(adUnitCopy);

return groupedAdUnits;
}, {});
Expand Down
71 changes: 71 additions & 0 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,77 @@ describe('Adagio bid adapter', () => {
expect(requests[0].data.user.eids).to.be.empty;
});
});

describe('with priceFloors module', function() {
it('should get and set floor by mediatype and sizes', function() {
const bid01 = new BidRequestBuilder({
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
},
video: {
playerSize: [600, 480]
}
}
}).withParams().build();
const bidderRequest = new BidderRequestBuilder().build();

// delete the computed `sizes` prop as we are based on mediaTypes only.
delete bid01.sizes

bid01.getFloor = () => {
return { floor: 1, currency: 'USD' }
}
const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.adUnits[0].floors.length).to.equal(3);
expect(requests[0].data.adUnits[0].floors[0]).to.deep.equal({f: 1, mt: 'banner', s: '300x250'});
expect(requests[0].data.adUnits[0].floors[1]).to.deep.equal({f: 1, mt: 'banner', s: '300x600'});
expect(requests[0].data.adUnits[0].floors[2]).to.deep.equal({f: 1, mt: 'video', s: '600x480'});
});

it('should get and set floor by mediatype if no size provided (ex native, video)', function() {
const bid01 = new BidRequestBuilder({
mediaTypes: {
video: {
context: 'outstream',
mimes: ['video/mp4']
},
native: {
body: { required: true }
}
}
}).withParams().build();
const bidderRequest = new BidderRequestBuilder().build();
bid01.getFloor = () => {
return { floor: 1, currency: 'USD' }
}
const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.adUnits[0].floors.length).to.equal(2);
expect(requests[0].data.adUnits[0].floors[0]).to.deep.equal({f: 1, mt: 'video'});
expect(requests[0].data.adUnits[0].floors[1]).to.deep.equal({f: 1, mt: 'native'});
});

it('should get and set floor with default value if no floors found', function() {
const bid01 = new BidRequestBuilder({
mediaTypes: {
video: {
context: 'outstream',
mimes: ['video/mp4']
}
}
}).withParams().build();
const bidderRequest = new BidderRequestBuilder().build();
bid01.getFloor = () => {
return { floor: NaN, currency: 'USD' }
}
const requests = spec.buildRequests([bid01], bidderRequest);

expect(requests[0].data.adUnits[0].floors.length).to.equal(1);
expect(requests[0].data.adUnits[0].floors[0]).to.deep.equal({f: 0.1, mt: 'video'});
});
});
});

describe('interpretResponse()', function() {
Expand Down