Skip to content

Commit

Permalink
Floors Module update to include floorMin (prebid#5805)
Browse files Browse the repository at this point in the history
* Update to floors module to allow floorMin definition using setConfig({floors:...});
1) If floorMin exists, set floorValue to new property floorRuleValue.
2) If floorMin is greater than floorValue, set floorValue to floorMin.

Update to Rubicon Analytics Adapter to pass floorMin under auction.floors.floorMin if exists. Also includes update to pass floorRuleValue for each bid if floorMin exists

Update to floorsModule roundup functionality to fix to one decimal place prior to roundup. This will fix issues in which JS evalutates a whole number to include a very small decimal value that forces a roundup to the next whole number.

* Remove extra spaces

* Package Lock revert

* Updates to commit

* Remove comment

* Remove excess spaces

* Update to priceFloor and rubiconAnalytics adapters
  • Loading branch information
mmoschovas authored and stsepelin committed May 28, 2021
1 parent 8ec9521 commit f7cb7d9
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 8 deletions.
15 changes: 11 additions & 4 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export let _floorDataForAuction = {};
* @summary Simple function to round up to a certain decimal degree
*/
function roundUp(number, precision) {
return Math.ceil(parseFloat(number) * Math.pow(10, precision)) / Math.pow(10, precision);
return Math.ceil((parseFloat(number) * Math.pow(10, precision)).toFixed(1)) / Math.pow(10, precision);
}

let referrerHostname;
Expand Down Expand Up @@ -98,7 +98,7 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {})
let fieldValues = enumeratePossibleFieldValues(utils.deepAccess(floorData, 'schema.fields') || [], bidObject, responseObject);
if (!fieldValues.length) return { matchingFloor: floorData.default };

// look to see iof a request for this context was made already
// look to see if a request for this context was made already
let matchingInput = fieldValues.map(field => field[0]).join('-');
// if we already have gotten the matching rule from this matching input then use it! No need to look again
let previousMatch = utils.deepAccess(floorData, `matchingInputs.${matchingInput}`);
Expand All @@ -109,10 +109,12 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {})
let matchingRule = find(allPossibleMatches, hashValue => floorData.values.hasOwnProperty(hashValue));

let matchingData = {
matchingFloor: floorData.values[matchingRule] || floorData.default,
floorMin: floorData.floorMin || 0,
floorRuleValue: floorData.values[matchingRule] || floorData.default,
matchingData: allPossibleMatches[0], // the first possible match is an "exact" so contains all data relevant for anlaytics adapters
matchingRule
};
matchingData.matchingFloor = Math.max(matchingData.floorMin, matchingData.floorRuleValue);
// save for later lookup if needed
utils.deepSetValue(floorData, `matchingInputs.${matchingInput}`, {...matchingData});
return matchingData;
Expand Down Expand Up @@ -287,11 +289,12 @@ export function updateAdUnitsForAuction(adUnits, floorData, auctionId) {
bid.floorData = {
skipped: floorData.skipped,
skipRate: floorData.skipRate,
floorMin: floorData.floorMin,
modelVersion: utils.deepAccess(floorData, 'data.modelVersion'),
location: utils.deepAccess(floorData, 'data.location', 'noData'),
floorProvider: floorData.floorProvider,
fetchStatus: _floorsConfig.fetchStatus
}
};
});
});
}
Expand Down Expand Up @@ -336,6 +339,8 @@ export function createFloorsDataForAuction(adUnits, auctionId) {
const isSkipped = Math.random() * 100 < parseFloat(auctionSkipRate);
resolvedFloorsData.skipped = isSkipped;
}
// copy FloorMin to floorData.data
if (resolvedFloorsData.hasOwnProperty('floorMin')) resolvedFloorsData.data.floorMin = resolvedFloorsData.floorMin;
// add floorData to bids
updateAdUnitsForAuction(adUnits, resolvedFloorsData, auctionId);
return resolvedFloorsData;
Expand Down Expand Up @@ -568,6 +573,7 @@ function addFieldOverrides(overrides) {
*/
export function handleSetFloorsConfig(config) {
_floorsConfig = utils.pick(config, [
'floorMin',
'enabled', enabled => enabled !== false, // defaults to true
'auctionDelay', auctionDelay => auctionDelay || 0,
'floorProvider', floorProvider => utils.deepAccess(config, 'data.floorProvider', floorProvider),
Expand Down Expand Up @@ -623,6 +629,7 @@ function addFloorDataToBid(floorData, floorInfo, bid, adjustedCpm) {
bid.floorData = {
floorValue: floorInfo.matchingFloor,
floorRule: floorInfo.matchingRule,
floorRuleValue: floorInfo.floorRuleValue,
floorCurrency: floorData.data.currency,
cpmAfterAdjustments: adjustedCpm,
enforcements: {...floorData.enforcement},
Expand Down
3 changes: 3 additions & 0 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function sendMessage(auctionId, bidWonId) {
'dimensions',
'mediaType',
'floorValue',
'floorRuleValue',
'floorRule'
]) : undefined
]);
Expand Down Expand Up @@ -233,6 +234,7 @@ function sendMessage(auctionId, bidWonId) {
'dealsEnforced', () => utils.deepAccess(auctionCache.floorData, 'enforcements.floorDeals'),
'skipRate',
'fetchStatus',
'floorMin',
'floorProvider as provider'
]);
}
Expand Down Expand Up @@ -344,6 +346,7 @@ export function parseBidResponse(bid, previousBidResponse, auctionFloorData) {
},
'seatBidId',
'floorValue', () => utils.deepAccess(bid, 'floorData.floorValue'),
'floorRuleValue', () => utils.deepAccess(bid, 'floorData.floorRuleValue'),
'floorRule', () => utils.debugTurnedOn() ? utils.deepAccess(bid, 'floorData.floorRule') : undefined
]);
}
Expand Down
Loading

0 comments on commit f7cb7d9

Please sign in to comment.