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

Sonobi bid adapter: add support for floor module #7206

Merged
merged 2 commits into from
Jul 22, 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
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 '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this always returns something, making the else in the wrapping function redundant i think?

}

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