Skip to content

Commit

Permalink
Update Floor format to floor={adslotId}:{floorPriceInCents}[, ...] an…
Browse files Browse the repository at this point in the history
…d fix the size which is submitted to the Price Floors Module (prebid#9186)
  • Loading branch information
nkloeber authored and JacobKlein26 committed Feb 8, 2023
1 parent 408a983 commit 3d6899a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
14 changes: 10 additions & 4 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const spec = {

const adslotIds = []
const adslotSizes = [];
const adslotFloors = [];
const timestamp = Date.now()
const query = {
ts: timestamp,
Expand Down Expand Up @@ -77,7 +78,7 @@ export const spec = {
}
const floor = getBidFloor(bid, sizes)
if (floor) {
query.floor = floor;
adslotFloors.push(bid.params.adslotId + ':' + floor);
}
})

Expand All @@ -99,6 +100,11 @@ export const spec = {
if (adslotSizes.length > 0) {
query.sizes = adslotSizes.join(',')
}

if (adslotFloors.length > 0) {
query.floor = adslotFloors.join(',')
}

const queryString = createQueryString(query)

return {
Expand Down Expand Up @@ -463,7 +469,7 @@ function extractSizes(bid) {
*
* @param {Object} bid
* @param {string[]} sizes
* @returns The floor CPM of a matched rule based on the rule selection process (mediaType, size and currency),
* @returns The floor CPM in cents of a matched rule based on the rule selection process (mediaType, size and currency),
* using the getFloor() inputs. Multi sizes and unsupported media types will default to '*'
*/
function getBidFloor(bid, sizes) {
Expand All @@ -475,10 +481,10 @@ function getBidFloor(bid, sizes) {
const floor = bid.getFloor({
currency: CURRENCY_CODE,
mediaType: mediaType !== undefined && spec.supportedMediaTypes.includes(mediaType) ? mediaType : '*',
size: sizes.length !== 1 ? '*' : extractSizes(sizes)
size: sizes.length !== 1 ? '*' : sizes[0].split(DIMENSION_SIGN)
});
if (floor.currency === CURRENCY_CODE) {
return floor.floor;
return (floor.floor * 100).toFixed(0);
}
return undefined;
}
Expand Down
69 changes: 49 additions & 20 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,36 +658,65 @@ describe('yieldlabBidAdapter', () => {
});

describe('getBidFloor', function () {
let bidRequest, getFloor;

it('should add valid bid floor', () => {
getFloor = () => {
return {
currency: 'EUR',
floor: 1.33
};
};
let bidRequest, bidRequest2, currency, floor;
const getFloor = () => {
return {
currency: currency,
floor: floor
}
}

it('should add valid bid floor in the format floor={adslotId}:{floorPriceInCents}[, ...]', () => {
bidRequest = Object.assign(DEFAULT_REQUEST(), {
getFloor: () => {
return {
currency: 'EUR',
floor: 1.33
}
}});
bidRequest2 = Object.assign(DEFAULT_REQUEST(), {
params: {
adslotId: 2222
},
getFloor: () => {
return {
currency: 'EUR',
floor: 2.99
}
}
});
const result = spec.buildRequests([bidRequest, bidRequest2], REQPARAMS)
expect(result).to.have.nested.property('queryParams.floor', '1111:133,2222:299')
});

it('should round the floor price up', () => {
currency = 'EUR';
floor = 0.745;
bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor})
const result = spec.buildRequests([bidRequest], REQPARAMS)
expect(result).to.have.nested.property('queryParams.floor', 1.33)
expect(result).to.have.nested.property('queryParams.floor', '1111:75')
});

it('should not add empty bid floor', () => {
getFloor = () => {
return {};
};
it('should round the floor price down', () => {
currency = 'EUR';
floor = 0.034;
bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor})
const result = spec.buildRequests([bidRequest], REQPARAMS)
expect(result).to.have.nested.property('queryParams.floor', '1111:3')
});

it('should not add empty bid floor', () => {
bidRequest = Object.assign(DEFAULT_REQUEST(), {
getFloor: () => {
return {};
}})
const result = spec.buildRequests([bidRequest], REQPARAMS)
expect(result).not.to.have.nested.property('queryParams.floor')
});

it('should not add bid floor when currency is not matching', () => {
getFloor = (currency, mediaType, size) => {
return {
currency: 'USD',
floor: 1.33
};
};
currency = 'USD';
floor = 1.33;
bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor})
const result = spec.buildRequests([bidRequest], REQPARAMS)
expect(result).not.to.have.nested.property('queryParams.floor')
Expand Down

0 comments on commit 3d6899a

Please sign in to comment.