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 Bid Adapter: add floor support for Video #6460

Merged
merged 3 commits into from
Mar 25, 2021
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
39 changes: 23 additions & 16 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,7 @@ function buildOXBannerRequest(bids, bidderRequest) {
queryParams.tps = customParamsForAllBids.join(',');
}

let customFloorsForAllBids = [];
let hasCustomFloor = false;
bids.forEach(function (bid) {
let floor = getBidFloor(bid, BANNER);

if (floor) {
customFloorsForAllBids.push(floor);
hasCustomFloor = true;
} else {
customFloorsForAllBids.push(0);
}
});
if (hasCustomFloor) {
queryParams.aumfs = customFloorsForAllBids.join(',');
}
enrichQueryWithFloors(queryParams, BANNER, bids);

let url = queryParams.ph
? `https://u.openx.net/w/1.0/arj`
Expand Down Expand Up @@ -430,6 +416,9 @@ function generateVideoParameters(bid, bidderRequest) {
queryParams.vtest = 1;
}

// each video bid makes a separate request
enrichQueryWithFloors(queryParams, VIDEO, [bid]);

return queryParams;
}

Expand Down Expand Up @@ -463,6 +452,24 @@ function createVideoBidResponses(response, {bid, startTime}) {
return bidResponses;
}

function enrichQueryWithFloors(queryParams, mediaType, bids) {
let customFloorsForAllBids = [];
let hasCustomFloor = false;
bids.forEach(function (bid) {
let floor = getBidFloor(bid, mediaType);

if (floor) {
customFloorsForAllBids.push(floor);
hasCustomFloor = true;
} else {
customFloorsForAllBids.push(0);
}
});
if (hasCustomFloor) {
queryParams.aumfs = customFloorsForAllBids.join(',');
}
}

function getBidFloor(bidRequest, mediaType) {
let floorInfo = {};
const currency = config.getConfig('currency.adServerCurrency') || DEFAULT_CURRENCY;
Expand All @@ -476,7 +483,7 @@ function getBidFloor(bidRequest, mediaType) {
}
let floor = floorInfo.floor || bidRequest.params.customFloor || 0;

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

registerBidder(spec);
84 changes: 84 additions & 0 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from 'chai';
import {spec, USER_ID_CODE_TO_QUERY_ARG} from 'modules/openxBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from 'src/mediaTypes.js';
import {userSync} from 'src/userSync.js';
import {config} from 'src/config.js';
import * as utils from 'src/utils.js';
Expand Down Expand Up @@ -1187,6 +1188,7 @@ describe('OpenxAdapter', function () {
let getFloorSpy = sinon.spy(bidRequest1, 'getFloor');

spec.buildRequests([bidRequest1], mockBidderRequest);
expect(getFloorSpy.args[0][0].mediaType).to.equal(BANNER);
expect(getFloorSpy.args[0][0].currency).to.equal('USD');
});

Expand All @@ -1205,6 +1207,7 @@ describe('OpenxAdapter', function () {
let getFloorSpy = sinon.spy(bidRequest1, 'getFloor');

spec.buildRequests([bidRequest1], mockBidderRequest);
expect(getFloorSpy.args[0][0].mediaType).to.equal(BANNER);
expect(getFloorSpy.args[0][0].currency).to.equal('bitcoin');
});
})
Expand Down Expand Up @@ -1345,6 +1348,87 @@ describe('OpenxAdapter', function () {
});
});
});

describe('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');
});

context('with floors module', function () {
let adServerCurrencyStub;
function makeBidWithFloorInfo(floorInfo) {
return Object.assign(utils.deepClone(bidRequestsWithMediaTypes[0]),
{
getFloor: () => {
return floorInfo;
}
});
}

beforeEach(function () {
adServerCurrencyStub = sinon
.stub(config, 'getConfig')
.withArgs('currency.adServerCurrency')
});

afterEach(function () {
config.getConfig.restore();
});

it('should send out floors on bids', function () {
const floors = [9.99, 18.881];
const bidRequests = floors.map(floor => {
return makeBidWithFloorInfo({
currency: 'AUS',
floor: floor
});
});
const request = spec.buildRequests(bidRequests, mockBidderRequest);

expect(request[0].data.aumfs).to.exist;
expect(request[0].data.aumfs).to.equal('9990');
expect(request[1].data.aumfs).to.exist;
expect(request[1].data.aumfs).to.equal('18881');
});

it('should send out floors on bids in the default currency', function () {
const bidRequest1 = makeBidWithFloorInfo({});

let getFloorSpy = sinon.spy(bidRequest1, 'getFloor');

spec.buildRequests([bidRequest1], mockBidderRequest);
expect(getFloorSpy.args[0][0].mediaType).to.equal(VIDEO);
expect(getFloorSpy.args[0][0].currency).to.equal('USD');
});

it('should send out floors on bids in the ad server currency if defined', function () {
adServerCurrencyStub.returns('bitcoin');

const bidRequest1 = makeBidWithFloorInfo({});

let getFloorSpy = sinon.spy(bidRequest1, 'getFloor');

spec.buildRequests([bidRequest1], mockBidderRequest);
expect(getFloorSpy.args[0][0].mediaType).to.equal(VIDEO);
expect(getFloorSpy.args[0][0].currency).to.equal('bitcoin');
});
})
})
});

describe('buildRequest for multi-format ad', function () {
Expand Down