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

Smartadserver Bid Adapter: add support for floors module #7259

Merged
merged 5 commits into from
Aug 4, 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
53 changes: 36 additions & 17 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import * as utils from '../src/utils.js';
import {
BANNER,
VIDEO
} from '../src/mediaTypes.js';
import {
config
} from '../src/config.js';
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
createEidsArray
} from './userId/eids.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { createEidsArray } from './userId/eids.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'smartadserver';
const GVL_ID = 45;
const DEFAULT_FLOOR = 0.0;

export const spec = {
code: BIDDER_CODE,
gvlid: GVL_ID,
Expand Down Expand Up @@ -137,8 +131,8 @@ export const spec = {
*/
buildRequests: function (validBidRequests, bidderRequest) {
// use bidderRequest.bids[] to get bidder-dependent request info
// if your bidder supports multiple currencies, use config.getConfig(currency)
// to find which one the ad server needs

const adServerCurrency = config.getConfig('currency.adServerCurrency');

// pull requested transaction ID from bidderRequest.bids[].transactionId
return validBidRequests.reduce((bidRequests, bid) => {
Expand All @@ -147,8 +141,8 @@ export const spec = {
siteid: bid.params.siteId,
pageid: bid.params.pageId,
formatid: bid.params.formatId,
currencyCode: config.getConfig('currency.adServerCurrency'),
bidfloor: bid.params.bidfloor || 0.0,
currencyCode: adServerCurrency,
bidfloor: bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency),
targeting: bid.params.target && bid.params.target !== '' ? bid.params.target : undefined,
buid: bid.params.buId && bid.params.buId !== '' ? bid.params.buId : undefined,
appname: bid.params.appName && bid.params.appName !== '' ? bid.params.appName : undefined,
Expand Down Expand Up @@ -249,6 +243,31 @@ export const spec = {
return bidResponses;
},

/**
* Get floors from Prebid Price Floors module
*
* @param {object} bid Bid request object
* @param {string} currency Ad server currency
* @return {number} Floor price
*/
getBidFloor: function (bid, currency) {
if (!utils.isFn(bid.getFloor)) {
return DEFAULT_FLOOR;
}

const floor = bid.getFloor({
currency: currency || 'USD',
mediaType: '*',
size: '*'
});

if (utils.isPlainObject(floor) && !isNaN(floor.floor)) {
return floor.floor;
}

return DEFAULT_FLOOR;
},

/**
* User syncs.
*
Expand Down
59 changes: 45 additions & 14 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import {
expect
} from 'chai';
import {
spec
} from 'modules/smartadserverBidAdapter.js';
import {
newBidder
} from 'src/adapters/bidderFactory.js';
import {
config
} from 'src/config.js';
import * as utils from 'src/utils.js';
import { requestBidsHook } from 'modules/consentManagement.js';
import { expect } from 'chai';
import { config } from 'src/config.js';
import { spec } from 'modules/smartadserverBidAdapter.js';

// Default params with optional ones
describe('Smart bid adapter tests', function () {
Expand Down Expand Up @@ -985,6 +974,48 @@ describe('Smart bid adapter tests', function () {
});
});

describe('Floors module', function () {
it('should include floor from bid params', function() {
const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS))[0].data);
expect(bidRequest.bidfloor).to.deep.equal(DEFAULT_PARAMS[0].params.bidfloor);
});

it('should return floor from module', function() {
const moduleFloor = 1.5;
const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data);
bidRequest.getFloor = function () {
return { floor: moduleFloor };
};

const floor = spec.getBidFloor(bidRequest, 'EUR');
expect(floor).to.deep.equal(moduleFloor);
});

it('should return default floor when module not activated', function() {
const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data);

const floor = spec.getBidFloor(bidRequest, 'EUR');
expect(floor).to.deep.equal(0);
});

it('should return default floor when getFloor returns not proper object', function() {
const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data);
bidRequest.getFloor = function () {
return { floor: 'one' };
};

const floor = spec.getBidFloor(bidRequest, 'EUR');
expect(floor).to.deep.equal(0.0);
});

it('should return default floor when currency unknown', function() {
const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data);

const floor = spec.getBidFloor(bidRequest, null);
expect(floor).to.deep.equal(0);
});
});

describe('Verify bid requests with multiple mediaTypes', function () {
afterEach(function () {
config.resetConfig();
Expand Down