Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenX: Add floor module support #5468

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -449,4 +451,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 @@ -508,25 +508,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 @@ -1089,6 +1070,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