Skip to content

Commit

Permalink
OpenX: Add floor module support (#5468)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimee02 authored Jul 24, 2020
1 parent a71d376 commit c933c4f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 21 deletions.
20 changes: 18 additions & 2 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ function buildOXBannerRequest(bids, bidderRequest) {
let customFloorsForAllBids = [];
let hasCustomFloor = false;
bids.forEach(function (bid) {
if (bid.params.customFloor) {
customFloorsForAllBids.push((Math.round(bid.params.customFloor * 100) / 100) * 1000);
let floor = getBidFloor(bid, BANNER);

if (floor) {
customFloorsForAllBids.push(floor);
hasCustomFloor = true;
} else {
customFloorsForAllBids.push(0);
Expand Down Expand Up @@ -453,4 +455,18 @@ function createVideoBidResponses(response, {bid, startTime}) {
return bidResponses;
}

function getBidFloor(bidRequest, mediaType) {
let floorInfo = {};
if (typeof bidRequest.getFloor === 'function') {
floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: mediaType,
size: '*'
});
}
let floor = floorInfo.floor || bidRequest.params.customFloor || 0;

return Math.round(floor * 1000); // normalize to microCpm
}

registerBidder(spec);
72 changes: 53 additions & 19 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,25 +540,6 @@ describe('OpenxAdapter', function () {
expect(dataParams.tps).to.equal(btoa('test1=testval1.&test2=testval2_,testval3'));
});

it('should send out custom floors on bids that have customFloors specified', function () {
const bidRequest = Object.assign({},
bidRequestsWithMediaTypes[0],
{
params: {
'unit': '12345678',
'delDomain': 'test-del-domain',
'customFloor': 1.500001
}
}
);

const request = spec.buildRequests([bidRequest], mockBidderRequest);
const dataParams = request[0].data;

expect(dataParams.aumfs).to.exist;
expect(dataParams.aumfs).to.equal('1500');
});

it('should send out custom bc parameter, if override is present', function () {
const bidRequest = Object.assign({},
bidRequestsWithMediaTypes[0],
Expand Down Expand Up @@ -1121,6 +1102,59 @@ describe('OpenxAdapter', function () {
});
});
});

context('floors', function () {
it('should send out custom floors on bids that have customFloors specified', function () {
const bidRequest = Object.assign({},
bidRequestsWithMediaTypes[0],
{
params: {
'unit': '12345678',
'delDomain': 'test-del-domain',
'customFloor': 1.500001
}
}
);

const request = spec.buildRequests([bidRequest], mockBidderRequest);
const dataParams = request[0].data;

expect(dataParams.aumfs).to.exist;
expect(dataParams.aumfs).to.equal('1500');
});

it('should send out floors on bids when there', function () {
const bidRequest1 = Object.assign({},
bidRequestsWithMediaTypes[0],
{
getFloor: () => {
return {
currency: 'AUS',
floor: 9.99
}
}
}
);

const bidRequest2 = Object.assign({},
bidRequestsWithMediaTypes[1],
{
getFloor: () => {
return {
currency: 'AUS',
floor: 18.881
}
}
}
);

const request = spec.buildRequests([bidRequest1, bidRequest2], mockBidderRequest);
const dataParams = request[0].data;

expect(dataParams.aumfs).to.exist;
expect(dataParams.aumfs).to.equal('9990,18881');
});
})
});

describe('buildRequests for video', function () {
Expand Down

0 comments on commit c933c4f

Please sign in to comment.