Skip to content

Commit

Permalink
PubMatic bid adapter to support price floors module (#5387)
Browse files Browse the repository at this point in the history
* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* added support for floors module

* using floorModule to set floor

* removed commented console.log statements
  • Loading branch information
pm-harshad-mane authored Jun 18, 2020
1 parent eb4bc85 commit 5ac08c6
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
26 changes: 26 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,37 @@ function _createImpressionObject(bid, conf) {
impObj.banner = bannerObj;
}

_addFloorFromFloorModule(impObj, bid);

return impObj.hasOwnProperty(BANNER) ||
impObj.hasOwnProperty(NATIVE) ||
impObj.hasOwnProperty(VIDEO) ? impObj : UNDEFINED;
}

function _addFloorFromFloorModule(impObj, bid) {
let bidFloor = -1;
// get lowest floor from floorModule
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))
}
}
});
}
// 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) {
bidFloor = Math.max(bidFloor, impObj.bidfloor)
}

// assign value only if bidFloor is > 0
impObj.bidfloor = ((!isNaN(bidFloor) && bidFloor > 0) ? bidFloor : UNDEFINED);
}

function _getDigiTrustObject(key) {
function getDigiTrustId() {
let digiTrustUser = window.DigiTrust && (config.getConfig('digiTrustId') || window.DigiTrust.getUser({member: key}));
Expand Down
84 changes: 84 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,90 @@ describe('PubMatic adapter', function () {
expect(data2.regs).to.equal(undefined);// USP/CCPAs
});

describe('setting imp.floor using floorModule', function() {
/*
Use the minimum value among floor from floorModule per mediaType
If params.adfloor is set then take max(kadfloor, min(floors from floorModule))
set imp.bidfloor only if it is more than 0
*/

let newRequest;
let floorModuleTestData;
let getFloor = function(req) {
return floorModuleTestData[req.mediaType];
};

beforeEach(() => {
floorModuleTestData = {
'banner': {
'currency': 'USD',
'floor': 1.50
},
'video': {
'currency': 'USD',
'floor': 2.50
},
'native': {
'currency': 'USD',
'floor': 3.50
}
};
newRequest = utils.deepClone(bannerVideoAndNativeBidRequests);
newRequest[0].getFloor = getFloor;
});

it('bidfloor should be undefined if calculation is <= 0', function() {
floorModuleTestData.banner.floor = 0; // lowest of them all
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(undefined);
});

it('ignore floormodule o/p if floor is not number', function() {
floorModuleTestData.banner.floor = 'INR';
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(2.5); // video will be lowest now
});

it('ignore floormodule o/p if currency is not matched', function() {
floorModuleTestData.banner.currency = 'INR';
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(2.5); // video will be lowest now
});

it('kadfloor is not passed, use minimum from floorModule', function() {
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(1.5);
});

it('kadfloor is passed as 3, use kadfloor as it is highest', function() {
newRequest[0].params.kadfloor = '3.0';// yes, we want it as a string
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(3);
});

it('kadfloor is passed as 1, use min of fllorModule as it is highest', function() {
newRequest[0].params.kadfloor = '1.0';// yes, we want it as a string
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(1.5);
});
});

it('Request should have digitrust params', function() {
window.DigiTrust = {
getUser: function () {
Expand Down

0 comments on commit 5ac08c6

Please sign in to comment.