Skip to content

Commit

Permalink
add adunit floor min price floors (#8396)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored May 10, 2022
1 parent b74cd10 commit 9b22db3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {})
matchingData: allPossibleMatches[0], // the first possible match is an "exact" so contains all data relevant for anlaytics adapters
matchingRule
};
// use adUnit floorMin as priority!
if (typeof deepAccess(bidObject, 'ortb2Imp.ext.prebid.floorMin') === 'number') {
matchingData.floorMin = bidObject.ortb2Imp.ext.prebid.floorMin;
}
matchingData.matchingFloor = Math.max(matchingData.floorMin, matchingData.floorRuleValue);
// save for later lookup if needed
deepSetValue(floorData, `matchingInputs.${matchingInput}`, {...matchingData});
Expand Down
50 changes: 50 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,56 @@ describe('the price floors module', function () {
matchingRule: undefined
});
});
it('correctly applies floorMin if on adunit', function () {
let inputFloorData = {
floorMin: 2.6,
currency: 'USD',
schema: {
delimiter: '|',
fields: ['adUnitCode']
},
values: {
'test_div_1': 1.0,
'test_div_2': 2.0
},
default: 0.5
};

let myBidRequest = { ...basicBidRequest };

// should take adunit floormin first even if lower
utils.deepSetValue(myBidRequest, 'ortb2Imp.ext.prebid.floorMin', 2.2);
expect(getFirstMatchingFloor(inputFloorData, myBidRequest, { mediaType: 'banner', size: '*' })).to.deep.equal({
floorMin: 2.2,
floorRuleValue: 1.0,
matchingFloor: 2.2,
matchingData: 'test_div_1',
matchingRule: 'test_div_1'
});
delete inputFloorData.matchingInputs;

// should take adunit floormin if higher
utils.deepSetValue(myBidRequest, 'ortb2Imp.ext.prebid.floorMin', 3.0);
expect(getFirstMatchingFloor(inputFloorData, myBidRequest, { mediaType: 'banner', size: '*' })).to.deep.equal({
floorMin: 3.0,
floorRuleValue: 1.0,
matchingFloor: 3.0,
matchingData: 'test_div_1',
matchingRule: 'test_div_1'
});
delete inputFloorData.matchingInputs;

// should take top floormin if no adunit floor min
delete myBidRequest.ortb2Imp;
expect(getFirstMatchingFloor(inputFloorData, myBidRequest, { mediaType: 'banner', size: '*' })).to.deep.equal({
floorMin: 2.6,
floorRuleValue: 1.0,
matchingFloor: 2.6,
matchingData: 'test_div_1',
matchingRule: 'test_div_1'
});
delete inputFloorData.matchingInputs;
});
it('selects the right floor for different mediaTypes', function () {
// banner with * size (not in rule file so does not do anything)
expect(getFirstMatchingFloor({...basicFloorData}, basicBidRequest, {mediaType: 'banner', size: '*'})).to.deep.equal({
Expand Down

0 comments on commit 9b22db3

Please sign in to comment.