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

Lemma Bid Adapter: accepting the floor to use the getFloor function #6497

Merged
merged 37 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e4f79af
lemmaBidAdapter.js
lm-abhijit Aug 29, 2019
c2e3f7f
lemmaBidAdapter.md
lm-abhijit Aug 29, 2019
5bf2179
lemmaBidAdapter_spec.js
lm-abhijit Aug 29, 2019
6910666
Update lemmaBidAdapter.js
lm-abhijit Aug 29, 2019
cdea5c6
Update lemmaBidAdapter.js
lm-abhijit Sep 16, 2019
8b0c2e6
Update lemmaBidAdapter.md
lm-abhijit Sep 16, 2019
9f0d787
Update lemmaBidAdapter.js
lm-abhijit Feb 6, 2020
512db74
Update lemmaBidAdapter_spec.js
lm-abhijit Feb 6, 2020
dc454c2
Update lemmaBidAdapter.md
lm-abhijit Feb 6, 2020
40ad9bf
Merge branch 'master' into master
lm-abhijit Feb 6, 2020
cd97952
Update lemmaBidAdapter.js
lm-abhijit Nov 5, 2020
bca12e0
Merge branch 'master' into master
lm-abhijit Nov 5, 2020
9fddb97
updated include modules file extension.
lm-abhijit Nov 10, 2020
9ef28f3
Update lemmaBidAdapter_spec.js
lm-abhijit Nov 10, 2020
7802da8
Update lemmaBidAdapter.js
lm-abhijit Nov 11, 2020
0a64799
Update lemmaBidAdapter_spec.js
lm-abhijit Nov 11, 2020
8ac2aed
Set mediaType key value into bid object
lm-abhijit Nov 20, 2020
2074a6f
Update lemmaBidAdapter.js
lm-abhijit Nov 20, 2020
7b1f3ac
Update lemmaBidAdapter.js
lm-abhijit Nov 25, 2020
1859e1f
Merge branch 'master' into master
lm-abhijit Nov 25, 2020
923da84
Update lemmaBidAdapter_spec.js
lm-abhijit Dec 1, 2020
7ee232d
Update lemmaBidAdapter.js
lm-abhijit Mar 30, 2021
393f28d
Update lemmaBidAdapter.js
lm-abhijit Mar 31, 2021
d3d4426
Update lemmaBidAdapter_spec.js
lm-abhijit Mar 31, 2021
fb9e222
Merge branch 'master' of https://github.com/prebid/Prebid.js
abhijitmane Mar 31, 2021
fecf386
Update lemmaBidAdapter.js
lm-abhijit Apr 1, 2021
0e6e834
Merge branch 'master' of https://github.com/prebid/Prebid.js
abhijitmane Apr 1, 2021
56ec057
Update lemmaBidAdapter_spec.js
lm-abhijit Apr 1, 2021
0855940
Update lemmaBidAdapter_spec.js
lm-abhijit Apr 1, 2021
e4307c7
Update lemmaBidAdapter.js
lm-abhijit Apr 1, 2021
1eac5b7
Update lemmaBidAdapter.js
lm-abhijit Apr 1, 2021
5b3a043
Update lemmaBidAdapter_spec.js
lm-abhijit Apr 1, 2021
901e8aa
Merge branch 'master' of https://github.com/prebid/Prebid.js
abhijitmane Apr 1, 2021
0f1c91a
Merge branch 'master' of https://github.com/prebid/Prebid.js
abhijitmane Apr 1, 2021
4169ec5
Merge branch 'master' of https://github.com/prebid/Prebid.js
abhijitmane Apr 2, 2021
bad1e0e
Merge branch 'master' of https://github.com/lemmadev/Prebid.js
abhijitmane Apr 2, 2021
806ed23
Update lemmaBidAdapter_spec.js
lm-abhijit Apr 2, 2021
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
28 changes: 25 additions & 3 deletions modules/lemmaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ function _initConf(refererInfo) {
return conf;
}

function _setFloor(impObj, bid) {
let bidFloor = -1;
// get lowest floor from floorModule
if (typeof bid.getFloor === 'function') {
[BANNER, VIDEO].forEach(mediaType => {
if (impObj.hasOwnProperty(mediaType)) {
let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: '*' });
if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) {
let mediaTypeFloor = parseFloat(floorInfo.floor);
bidFloor = (bidFloor == -1 ? mediaTypeFloor : Math.min(mediaTypeFloor, bidFloor))
}
}
});
}
// get highest from impObj.bidfllor and floor from floor module
// as we are using Math.max, it is ok if we have not got any floor from floorModule, then value of bidFloor will be -1
if (impObj.bidfloor) {
bidFloor = Math.max(bidFloor, impObj.bidfloor)
}

// assign value only if bidFloor is > 0
impObj.bidfloor = ((!isNaN(bidFloor) && bidFloor > 0) ? bidFloor : undefined);
}

function parseRTBResponse(request, response) {
var bidResponses = [];
try {
Expand Down Expand Up @@ -352,11 +376,9 @@ function _getImpressionObject(bid) {
secure: window.location.protocol === 'https:' ? 1 : 0,
bidfloorcur: params.currency ? params.currency : DEFAULT_CURRENCY
};

if (params.bidFloor) {
impression.bidfloor = params.bidFloor;
}

if (bid.hasOwnProperty('mediaTypes')) {
for (mediaTypes in bid.mediaTypes) {
switch (mediaTypes) {
Expand Down Expand Up @@ -392,7 +414,7 @@ function _getImpressionObject(bid) {
}
impression.banner = bObj;
}

_setFloor(impression, bid);
return impression.hasOwnProperty(BANNER) ||
impression.hasOwnProperty(VIDEO) ? impression : undefined;
}
Expand Down
75 changes: 75 additions & 0 deletions test/spec/modules/lemmaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('lemmaBidAdapter', function() {
pubId: 1001,
adunitId: 1,
currency: 'AUD',
bidFloor: 1.3,
geo: {
lat: '12.3',
lon: '23.7',
Expand All @@ -46,6 +47,7 @@ describe('lemmaBidAdapter', function() {
params: {
pubId: 1001,
adunitId: 1,
bidFloor: 1.3,
video: {
mimes: ['video/mp4', 'video/x-flv'],
skippable: true,
Expand Down Expand Up @@ -161,6 +163,7 @@ describe('lemmaBidAdapter', function() {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.pubId.toString()); // publisher Id
expect(data.imp[0].tagid).to.equal('1'); // tagid
expect(data.imp[0].bidfloorcur).to.equal(bidRequests[0].params.currency);
expect(data.imp[0].bidfloor).to.equal(bidRequests[0].params.bidFloor);
});
it('Request params check without mediaTypes object', function() {
var bidRequests = [{
Expand Down Expand Up @@ -192,6 +195,7 @@ describe('lemmaBidAdapter', function() {
expect(data.site.publisher.id).to.equal(bidRequests[0].params.pubId.toString()); // publisher Id
expect(data.imp[0].tagid).to.equal(undefined); // tagid
expect(data.imp[0].bidfloorcur).to.equal(bidRequests[0].params.currency);
expect(data.imp[0].bidfloor).to.equal(bidRequests[0].params.bidFloor);
});
it('Request params multi size format object check', function() {
var bidRequests = [{
Expand Down Expand Up @@ -309,6 +313,77 @@ describe('lemmaBidAdapter', function() {
expect(data.imp[0]['video']['w']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0]);
expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[1]);
});
describe('setting imp.floor using floorModule', function() {
/*
Use the minimum value among floor from floorModule per mediaType
If params.bidFloor is set then take max(floor, min(floors from floorModule))
set imp.bidfloor only if it is more than 0
*/

let newRequest;
let floorModuleTestData;
let getFloor = function(req) {
return floorModuleTestData[req.mediaType];
};

beforeEach(() => {
floorModuleTestData = {
'banner': {
'currency': 'USD',
'floor': 1.50
},
'video': {
'currency': 'USD',
lm-abhijit marked this conversation as resolved.
Show resolved Hide resolved
'floor': 2.00
}
};
newRequest = utils.deepClone(bidRequests);
newRequest[0].getFloor = getFloor;
});

it('bidfloor should be undefined if calculation is <= 0', function() {
floorModuleTestData.banner.floor = 0; // lowest of them all
newRequest[0].params.bidFloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(undefined);
});

it('ignore floormodule o/p if floor is not number', function() {
floorModuleTestData.banner.floor = 'INR';
newRequest[0].params.bidFloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(undefined); // video will be lowest now
});

it('ignore floormodule o/p if currency is not matched', function() {
floorModuleTestData.banner.currency = 'INR';
newRequest[0].params.bidFloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(undefined); // video will be lowest now
});

it('bidFloor is not passed, use minimum from floorModule', function() {
newRequest[0].params.bidFloor = undefined;
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(undefined);
});

it('bidFloor is passed as 1, use min of floorModule as it is highest', function() {
newRequest[0].params.bidFloor = '1.0';// yes, we want it as a string
let request = spec.buildRequests(newRequest);
let data = JSON.parse(request.data);
data = data.imp[0];
expect(data.bidfloor).to.equal(1);
});
});
describe('Response checking', function() {
it('should check for valid response values', function() {
var request = spec.buildRequests(bidRequests);
Expand Down