Skip to content

Commit

Permalink
Insticator Bid Adapter: Add support for BidFloors (prebid#11472)
Browse files Browse the repository at this point in the history
* support bidfloor from params

* update test case for bidder bidfloor

* prioritize module floor

* fix

* update bidfloorcur

* add USD currency for module floor

* add test cases for bidfloors and fix module floor scopes

* add logwarn for non usd floors
  • Loading branch information
shubhamc-ins authored and DecayConstant committed Jul 18, 2024
1 parent edbec6e commit 151a456
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 1 deletion.
58 changes: 57 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,19 @@ 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;
logWarn('insticator: bidfloorcur supported by insticator is USD only. ignoring bidfloor and bidfloorcur params');
}
}

if (deepAccess(bidRequest, 'mediaTypes.banner')) {
imp.banner = buildBanner(bidRequest);
}
Expand All @@ -178,6 +191,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 {w: width, h: 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);
}

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

return imp;
}

Expand Down
94 changes: 94 additions & 0 deletions test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,100 @@ 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 bidder bidfloorcur from the request', function () {
const expectedFloor = 1.5;
const currency = 'USD';
const tempBiddRequest = {
...bidRequest,
params: {
...bidRequest.params,
floor: 0.5,
currency: 'USD',
},
}
tempBiddRequest.getFloor = () => ({ floor: expectedFloor, currency })

const requests = spec.buildRequests([tempBiddRequest], bidderRequest);
const data = JSON.parse(requests[0].data);
expect(data.imp[0].bidfloor).to.equal(1.5);
expect(data.imp[0].bidfloorcur).to.equal('USD');
});

it('should have 1 floor for banner 300x250 and 1.5 for 300x600', function () {
const tempBiddRequest = {
...bidRequest,
params: {
...bidRequest.params,
},
mediaTypes: {
banner: {
sizes: [[300, 250]],
format: [{ w: 300, h: 250 }]
},
},
}
tempBiddRequest.getFloor = (params) => {
return { floor: params.size[1] === 250 ? 1 : 1.5, currency: 'USD' }
}

const requests = spec.buildRequests([tempBiddRequest], bidderRequest);
const data = JSON.parse(requests[0].data);
expect(data.imp[0].bidfloor).to.equal(1);

tempBiddRequest.mediaTypes.banner.format = [ { w: 300, h: 600 },
];
const request2 = spec.buildRequests([tempBiddRequest], bidderRequest);
const data2 = JSON.parse(request2[0].data);
expect(data2.imp[0].bidfloor).to.equal(1.5);
});

it('should have 4 floor for video 300x250 and 4.5 for 300x600', function () {
const tempBiddRequest = {
...bidRequest,
params: {
...bidRequest.params,
},
mediaTypes: {
video: {
mimes: [
'video/mp4',
'video/mpeg',
],
w: 300,
h: 250,
placement: 2,
},
},
}
tempBiddRequest.getFloor = (params) => {
return { floor: params.size[1] === 250 ? 4 : 4.5, currency: 'USD' }
}

const requests = spec.buildRequests([tempBiddRequest], bidderRequest);
const data = JSON.parse(requests[0].data);
expect(data.imp[0].bidfloor).to.equal(4);

tempBiddRequest.mediaTypes.video.w = 300;
tempBiddRequest.mediaTypes.video.h = 600;
const request2 = spec.buildRequests([tempBiddRequest], bidderRequest);
const data2 = JSON.parse(request2[0].data);
expect(data2.imp[0].bidfloor).to.equal(4.5);
});

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

0 comments on commit 151a456

Please sign in to comment.