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

Beachfront Bid Adapter: add floors module support #6752

Merged
merged 2 commits into from
May 19, 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
23 changes: 17 additions & 6 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js';
import find from 'core-js-pure/features/array/find.js';
import includes from 'core-js-pure/features/array/includes.js';

const ADAPTER_VERSION = '1.15';
const ADAPTER_VERSION = '1.16';
const ADAPTER_NAME = 'BFIO_PREBID';
const OUTSTREAM = 'outstream';
const CURRENCY = 'USD';

export const VIDEO_ENDPOINT = 'https://reachms.bfmio.com/bid.json?exchange_id=';
export const BANNER_ENDPOINT = 'https://display.bfmio.com/prebid_display';
Expand Down Expand Up @@ -78,7 +79,7 @@ export const spec = {
creativeId: response.crid || response.cmpId,
renderer: context === OUTSTREAM ? createRenderer(bidRequest) : null,
mediaType: VIDEO,
currency: 'USD',
currency: CURRENCY,
netRevenue: true,
ttl: 300
};
Expand Down Expand Up @@ -110,7 +111,7 @@ export const spec = {
width: bid.w,
height: bid.h,
mediaType: BANNER,
currency: 'USD',
currency: CURRENCY,
netRevenue: true,
ttl: 300
};
Expand Down Expand Up @@ -250,6 +251,16 @@ function getPlayerBidParam(bid, key, defaultValue) {
return param === undefined ? defaultValue : param;
}

function getBannerBidFloor(bid) {
let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {};
return floorInfo.floor || getBannerBidParam(bid, 'bidfloor');
}

function getVideoBidFloor(bid) {
let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {};
return floorInfo.floor || getVideoBidParam(bid, 'bidfloor');
}

function isVideoBidValid(bid) {
return isVideoBid(bid) && getVideoBidParam(bid, 'appId') && getVideoBidParam(bid, 'bidfloor');
}
Expand Down Expand Up @@ -315,7 +326,7 @@ function createVideoRequestData(bid, bidderRequest) {
let firstSize = getFirstSize(sizes);
let video = getVideoTargetingParams(bid);
let appId = getVideoBidParam(bid, 'appId');
let bidfloor = getVideoBidParam(bid, 'bidfloor');
let bidfloor = getVideoBidFloor(bid);
let tagid = getVideoBidParam(bid, 'tagid');
let topLocation = getTopWindowLocation(bidderRequest);
let eids = getEids(bid);
Expand Down Expand Up @@ -354,7 +365,7 @@ function createVideoRequestData(bid, bidderRequest) {
user: {
ext: {}
},
cur: ['USD']
cur: [CURRENCY]
};

if (bidderRequest && bidderRequest.uspConsent) {
Expand Down Expand Up @@ -386,7 +397,7 @@ function createBannerRequestData(bids, bidderRequest) {
return {
slot: bid.adUnitCode,
id: getBannerBidParam(bid, 'appId'),
bidfloor: getBannerBidParam(bid, 'bidfloor'),
bidfloor: getBannerBidFloor(bid),
tagid: getBannerBidParam(bid, 'tagid'),
sizes: getBannerSizes(bid)
};
Expand Down
36 changes: 36 additions & 0 deletions test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ describe('BeachfrontAdapter', function () {
expect(data.cur).to.deep.equal(['USD']);
});

it('must read from the floors module if available', function () {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
bidRequest.getFloor = () => ({ currency: 'USD', floor: 1.16 });
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].bidfloor).to.equal(1.16);
});

it('must use the bid floor param if no value is returned from the floors module', function () {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
bidRequest.getFloor = () => ({});
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor);
});

it('must parse bid size from a nested array', function () {
const width = 640;
const height = 480;
Expand Down Expand Up @@ -365,6 +383,24 @@ describe('BeachfrontAdapter', function () {
expect(data.ua).to.equal(navigator.userAgent);
});

it('must read from the floors module if available', function () {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { banner: {} };
bidRequest.getFloor = () => ({ currency: 'USD', floor: 1.16 });
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].bidfloor).to.equal(1.16);
});

it('must use the bid floor param if no value is returned from the floors module', function () {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { banner: {} };
bidRequest.getFloor = () => ({});
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].bidfloor).to.equal(bidRequest.params.bidfloor);
});

it('must parse bid size from a nested array', function () {
const width = 300;
const height = 250;
Expand Down