Skip to content

Commit

Permalink
Beachfront Bid Adapter: add floors module support (#6752)
Browse files Browse the repository at this point in the history
* add price floors support to beachfront adapter

* revert doc changes to create separate pull request

Co-authored-by: John Salis <john@beachfront.com>
  • Loading branch information
2 people authored and idettman committed May 21, 2021
1 parent e2aa319 commit 261f0e1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
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 @@ -79,7 +80,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 @@ -111,7 +112,7 @@ export const spec = {
width: bid.w,
height: bid.h,
mediaType: BANNER,
currency: 'USD',
currency: CURRENCY,
netRevenue: true,
ttl: 300
};
Expand Down Expand Up @@ -251,6 +252,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 @@ -316,7 +327,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 @@ -358,7 +369,7 @@ function createVideoRequestData(bid, bidderRequest) {
user: {
ext: {}
},
cur: ['USD']
cur: [CURRENCY]
};

if (bidderRequest && bidderRequest.uspConsent) {
Expand Down Expand Up @@ -394,7 +405,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 @@ -171,6 +171,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 @@ -403,6 +421,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

0 comments on commit 261f0e1

Please sign in to comment.