Skip to content

Commit

Permalink
Impactify Bid Adapter: add support for BidFloor (prebid#9277)
Browse files Browse the repository at this point in the history
* Add support of getFloor function

* Add support of getFloor function

* Add support of getFloor function

* Add support of getFloor function

* Add unit test for bid floor

* Add unit test for bid floor

Co-authored-by: Thomas De Stefano <thomas.destefano@impactify.io>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent eebe3af commit fe33aab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion modules/impactifyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import {ajax} from '../src/ajax.js';
import { ajax } from '../src/ajax.js';
import { createEidsArray } from './userId/eids.js';

const BIDDER_CODE = 'impactify';
Expand All @@ -27,6 +27,18 @@ const getDeviceType = () => {
return 2;
};

const getFloor = (bid) => {
const floorInfo = bid.getFloor({
currency: DEFAULT_CURRENCY,
mediaType: '*',
size: '*'
});
if (typeof floorInfo === 'object' && floorInfo.currency === DEFAULT_CURRENCY && !isNaN(parseFloat(floorInfo.floor))) {
return parseFloat(floorInfo.floor);
}
return null;
}

const createOpenRtbRequest = (validBidRequests, bidderRequest) => {
// Create request and set imp bids inside
let request = {
Expand Down Expand Up @@ -114,6 +126,12 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => {
if (bid.params.container) {
imp.ext.impactify.container = bid.params.container;
}
if (typeof bid.getFloor === 'function') {
const floor = getFloor(bid);
if (floor) {
imp.bidfloor = floor;
}
}
request.imp.push(imp);
});

Expand Down
13 changes: 13 additions & 0 deletions test/spec/modules/impactifyBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ describe('ImpactifyAdapter', function () {
}
};

it('should pass bidfloor', function () {
videoBidRequests[0].getFloor = function() {
return {
currency: 'USD',
floor: 1.23,
}
}

const res = spec.buildRequests(videoBidRequests, videoBidderRequest)
const resData = JSON.parse(res.data)
expect(resData.imp[0].bidfloor).to.equal(1.23)
});

it('sends video bid request to ENDPOINT via POST', function () {
const request = spec.buildRequests(videoBidRequests, videoBidderRequest);
expect(request.url).to.equal(ORIGIN + AUCTIONURI);
Expand Down

0 comments on commit fe33aab

Please sign in to comment.