Skip to content

Commit

Permalink
PubMatic bid adapter: while retrieving floor from floor module pass b…
Browse files Browse the repository at this point in the history
…anner-sizes instead of * (prebid#7419)

* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* use minimum floor from each size

* added comments

* floor retrieval: removed custom logic for Video; will pass * for video

* added some logs

* corrected teh value

* indent

* modified the test cases

* read banner sizes from impObj than bid object
  • Loading branch information
pm-harshad-mane authored and Chris Pabst committed Jan 10, 2022
1 parent cd0e148 commit 39d7d36
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
34 changes: 30 additions & 4 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 20 additions & 7 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 39d7d36

Please sign in to comment.