Skip to content

Commit

Permalink
Sonobi bid adapter: add support for floor module (#7206)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonGoSonobi authored Jul 22, 2021
1 parent a3232ea commit f873332
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 22 additions & 3 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, deepClone, getGptSlotInfoForAdUnitCode } from '../src/utils.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, deepClone, getGptSlotInfoForAdUnitCode, isFn, isPlainObject } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
Expand Down Expand Up @@ -303,8 +303,10 @@ function _validateSlot (bid) {
}

function _validateFloor (bid) {
if (bid.params.floor) {
return '';
const floor = getBidFloor(bid);

if (floor) {
return `|f=${floor}`;
}
return '';
}
Expand Down Expand Up @@ -407,4 +409,21 @@ function _iframeAllowed() {
return userSync.canBidderRegisterSync('iframe', BIDDER_CODE);
}

function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return (bid.params.floor) ? bid.params.floor : null;
}

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

if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
return floor.floor;
}
return '';
}

registerBidder(spec);
10 changes: 8 additions & 2 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ describe('SonobiBidAdapter', function () {
'adUnitCode': 'adunit-code-3',
'sizes': [[120, 600], [300, 600], [160, 600]],
'bidId': '30b31c1838de1d',
'getFloor': ({currency, mediaType, size}) => {
return {
currency: 'USD',
floor: 0.42
}
}
},
{
'bidder': 'sonobi',
Expand All @@ -307,8 +313,8 @@ describe('SonobiBidAdapter', function () {
}];

let keyMakerData = {
'30b31c1838de1f': '1a2b3c4d5e6f1a2b3c4d|300x250,300x600|gpid=/123123/gpt_publisher/adunit-code-1',
'30b31c1838de1d': '1a2b3c4d5e6f1a2b3c4e|300x250,300x600|gpid=/123123/gpt_publisher/adunit-code-3',
'30b31c1838de1f': '1a2b3c4d5e6f1a2b3c4d|300x250,300x600|f=1.25|gpid=/123123/gpt_publisher/adunit-code-1',
'30b31c1838de1d': '1a2b3c4d5e6f1a2b3c4e|300x250,300x600|f=0.42|gpid=/123123/gpt_publisher/adunit-code-3',
'/7780971/sparks_prebid_LB|30b31c1838de1e': '300x250,300x600|gpid=/7780971/sparks_prebid_LB',
};

Expand Down

0 comments on commit f873332

Please sign in to comment.