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

Insticator Bid Adapter: Add support for BidFloors #11472

Merged
Show file tree
Hide file tree
Changes from 6 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
57 changes: 56 additions & 1 deletion modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {config} from '../src/config.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {deepAccess, generateUUID, logError, isArray, isInteger, isArrayOfNums, deepSetValue} from '../src/utils.js';
import {deepAccess, generateUUID, logError, isArray, isInteger, isArrayOfNums, deepSetValue, isFn, logWarn} from '../src/utils.js';
import {getStorageManager} from '../src/storageManager.js';
import {find} from '../src/polyfill.js';

Expand Down Expand Up @@ -170,6 +170,18 @@ function buildImpression(bidRequest) {
},
}

let bidFloor = parseFloat(deepAccess(bidRequest, 'params.floor'));

if (!isNaN(bidFloor)) {
imp.bidfloor = deepAccess(bidRequest, 'params.floor');
imp.bidfloorcur = 'USD';
const bidfloorcur = deepAccess(bidRequest, 'params.bidfloorcur')
if (bidfloorcur && bidfloorcur !== 'USD') {
delete imp.bidfloor;
delete imp.bidfloorcur;
}
ncolletti marked this conversation as resolved.
Show resolved Hide resolved
}

if (deepAccess(bidRequest, 'mediaTypes.banner')) {
imp.banner = buildBanner(bidRequest);
}
Expand All @@ -178,6 +190,49 @@ function buildImpression(bidRequest) {
imp.video = buildVideo(bidRequest);
}

if (isFn(bidRequest.getFloor)) {
let moduleBidFloor;

const mediaType = deepAccess(bidRequest, 'mediaTypes.banner') ? 'banner' : deepAccess(bidRequest, 'mediaTypes.video') ? 'video' : undefined;

let _mediaType = mediaType;
let _size = '*';

if (mediaType && ['banner', 'video'].includes(mediaType)) {
if (mediaType === 'banner') {
const { w: width, h: height } = imp[mediaType];
if (width && height) {
_size = [width, height];
}
} else {
const sizes = deepAccess(bidRequest, 'mediaTypes.banner.format');
if (sizes && sizes.length > 0) {
const [width, height] = sizes[0];
_size = [width, height];
}
}
} else if (mediaType === 'video') {
const { w: width, h: height } = imp[mediaType];
_mediaType = mediaType;
_size = [width, height];
}
try {
moduleBidFloor = bidRequest.getFloor({
currency: 'USD',
mediaType: _mediaType,
size: _size
});
} catch (err) {
// continue with no module floors
logWarn('priceFloors module call getFloor failed, error : ', err);
ncolletti marked this conversation as resolved.
Show resolved Hide resolved
}

if (moduleBidFloor) {
imp.bidfloor = moduleBidFloor.floor;
imp.bidfloorcur = moduleBidFloor.currency;
}
}

return imp;
}

Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,20 @@ describe('InsticatorBidAdapter', function () {
expect(data.imp[0].video.h).to.equal(480);
});

it('should have bidder bidfloor from the request', function () {
const tempBiddRequest = {
...bidRequest,
params: {
...bidRequest.params,
floor: 0.5,
},
}
const requests = spec.buildRequests([tempBiddRequest], bidderRequest);
const data = JSON.parse(requests[0].data);
expect(data.imp[0].bidfloor).to.equal(0.5);
expect(data.imp[0].bidfloorcur).to.equal('USD');
});

it('should have sites first party data if present in bidderRequest ortb2', function () {
bidderRequest = {
...bidderRequest,
Expand Down