Skip to content

Commit

Permalink
Price Floors: use standard cpmAdjustment (#6194)
Browse files Browse the repository at this point in the history
* use standard cpmAdjustment

* spaces
  • Loading branch information
robertrmartinez committed Jan 20, 2021
1 parent 90b2b61 commit 4faaf47
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function generatePossibleEnumerations(arrayOfFields, delimiter) {
* @summary If a the input bidder has a registered cpmadjustment it returns the input CPM after being adjusted
*/
export function getBiddersCpmAdjustment(bidderName, inputCpm, bid = {}) {
const adjustmentFunction = utils.deepAccess(getGlobal(), `bidderSettings.${bidderName}.bidCpmAdjustment`);
const adjustmentFunction = utils.deepAccess(getGlobal(), `bidderSettings.${bidderName}.bidCpmAdjustment`) || utils.deepAccess(getGlobal(), 'bidderSettings.standard.bidCpmAdjustment');
if (adjustmentFunction) {
return parseFloat(adjustmentFunction(inputCpm, {...bid, cpm: inputCpm}));
}
Expand Down
35 changes: 35 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,41 @@ describe('the price floors module', function () {
floor: 1.3334 // 1.3334 * 0.75 = 1.000005 which is the floor (we cut off getFloor at 4 decimal points)
});
});

it('should use standard cpmAdjustment if no bidder cpmAdjustment', function () {
getGlobal().bidderSettings = {
rubicon: {
bidCpmAdjustment: function (bidCpm, bidResponse) {
return bidResponse.cpm * 0.5;
},
},
standard: {
bidCpmAdjustment: function (bidCpm, bidResponse) {
return bidResponse.cpm * 0.75;
},
}
};
_floorDataForAuction[bidRequest.auctionId] = utils.deepClone(basicFloorConfig);
_floorDataForAuction[bidRequest.auctionId].data.values = { '*': 1.0 };
let appnexusBid = {
...bidRequest,
bidder: 'appnexus'
};

// the conversion should be what the bidder would need to return in order to match the actual floor
// rubicon
expect(bidRequest.getFloor()).to.deep.equal({
currency: 'USD',
floor: 2.0 // a 2.0 bid after rubicons cpm adjustment would be 1.0 and thus is the floor after adjust
});

// appnexus
expect(appnexusBid.getFloor()).to.deep.equal({
currency: 'USD',
floor: 1.3334 // 1.3334 * 0.75 = 1.000005 which is the floor (we cut off getFloor at 4 decimal points)
});
});

it('should work when cpmAdjust function uses bid object', function () {
getGlobal().bidderSettings = {
rubicon: {
Expand Down

0 comments on commit 4faaf47

Please sign in to comment.