diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 7edeb5589d1..46e3257ae2e 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -740,22 +740,48 @@ function _addFloorFromFloorModule(impObj, bid) { if (typeof bid.getFloor === 'function' && !config.getConfig('pubmatic.disableFloors')) { [BANNER, VIDEO, NATIVE].forEach(mediaType => { if (impObj.hasOwnProperty(mediaType)) { - let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: '*' }); - if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) { - let mediaTypeFloor = parseFloat(floorInfo.floor); - bidFloor = (bidFloor == -1 ? mediaTypeFloor : Math.min(mediaTypeFloor, bidFloor)) + let sizesArray = []; + + if (mediaType === 'banner') { + if (impObj[mediaType].w && impObj[mediaType].h) { + sizesArray.push([impObj[mediaType].w, impObj[mediaType].h]); + } + if (utils.isArray(impObj[mediaType].format)) { + impObj[mediaType].format.forEach(size => sizesArray.push([size.w, size.h])); + } + } + + if (sizesArray.length === 0) { + sizesArray.push('*') } + + sizesArray.forEach(size => { + let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: size }); + utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module returned for mediatype:', mediaType, ' and size:', size, ' is: currency', floorInfo.currency, 'floor', floorInfo.floor); + if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) { + let mediaTypeFloor = parseFloat(floorInfo.floor); + utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module:', mediaTypeFloor, 'previous floor value', bidFloor, 'Min:', Math.min(mediaTypeFloor, bidFloor)); + if (bidFloor === -1) { + bidFloor = mediaTypeFloor; + } else { + bidFloor = Math.min(mediaTypeFloor, bidFloor) + } + utils.logInfo(LOG_WARN_PREFIX, 'new floor value:', bidFloor); + } + }); } }); } // get highest from impObj.bidfllor and floor from floor module // as we are using Math.max, it is ok if we have not got any floor from floorModule, then value of bidFloor will be -1 if (impObj.bidfloor) { + utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module:', bidFloor, 'impObj.bidfloor', impObj.bidfloor, 'Max:', Math.max(bidFloor, impObj.bidfloor)); bidFloor = Math.max(bidFloor, impObj.bidfloor) } // assign value only if bidFloor is > 0 impObj.bidfloor = ((!isNaN(bidFloor) && bidFloor > 0) ? bidFloor : UNDEFINED); + utils.logInfo(LOG_WARN_PREFIX, 'new impObj.bidfloor value:', impObj.bidfloor); } function _getFlocId(validBidRequests, flocFormat) { diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index df3516579de..54da555e6ce 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1846,14 +1846,25 @@ describe('PubMatic adapter', function () { let newRequest; let floorModuleTestData; let getFloor = function(req) { - return floorModuleTestData[req.mediaType]; + // actual getFloor module does not work like this :) + // special treatment for banner since for other mediaTypes we pass * + if (req.mediaType === 'banner') { + return floorModuleTestData[req.mediaType][ req.size[0] + 'x' + req.size[1] ] || {}; + } + return floorModuleTestData[req.mediaType] || {}; }; beforeEach(() => { floorModuleTestData = { 'banner': { - 'currency': 'USD', - 'floor': 1.50 + '300x250': { + 'currency': 'USD', + 'floor': 1.50 + }, + '300x600': { + 'currency': 'USD', + 'floor': 2.0 + } }, 'video': { 'currency': 'USD', @@ -1869,7 +1880,7 @@ describe('PubMatic adapter', function () { }); it('bidfloor should be undefined if calculation is <= 0', function() { - floorModuleTestData.banner.floor = 0; // lowest of them all + floorModuleTestData.banner['300x250'].floor = 0; // lowest of them all newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1880,7 +1891,8 @@ describe('PubMatic adapter', function () { }); it('ignore floormodule o/p if floor is not number', function() { - floorModuleTestData.banner.floor = 'INR'; + floorModuleTestData.banner['300x250'].floor = 'Not-a-Number'; + floorModuleTestData.banner['300x600'].floor = 'Not-a-Number'; newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1891,7 +1903,8 @@ describe('PubMatic adapter', function () { }); it('ignore floormodule o/p if currency is not matched', function() { - floorModuleTestData.banner.currency = 'INR'; + floorModuleTestData.banner['300x250'].currency = 'INR'; + floorModuleTestData.banner['300x600'].currency = 'INR'; newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1921,7 +1934,7 @@ describe('PubMatic adapter', function () { expect(data.bidfloor).to.equal(3); }); - it('kadfloor is passed as 1, use min of fllorModule as it is highest', function() { + it('kadfloor is passed as 1, use min of floorModule as it is highest', function() { newRequest[0].params.kadfloor = '1.0';// yes, we want it as a string let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id'