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

PubMatic bid adapter: while retrieving floor from floor module pass banner-sizes instead of * #7419

Merged
merged 83 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
33762d1
added support for pubcommon, digitrust, id5id
pm-harshad-mane Sep 12, 2019
0722354
added support for IdentityLink
pm-harshad-mane Sep 13, 2019
f2c32c0
changed the source for id5
pm-harshad-mane Sep 13, 2019
37163d1
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 13, 2019
eaed987
added unit test cases
pm-harshad-mane Sep 13, 2019
602ee7e
changed source param for identityLink
pm-harshad-mane Sep 16, 2019
b6fcd36
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 23, 2019
58381f3
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 26, 2019
c9fb11b
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Oct 10, 2019
8ece7fd
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Oct 16, 2019
28d12a0
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Oct 16, 2019
05a55e1
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Oct 31, 2019
e8b10d5
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Nov 5, 2019
870085f
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Nov 12, 2019
844ce4e
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Nov 12, 2019
704eca3
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Nov 13, 2019
2565cb9
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 4, 2019
1d75bd4
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 4, 2019
6adde1e
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 6, 2019
477c98a
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 9, 2019
cef5422
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 10, 2019
c110a7d
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jan 9, 2020
e8fb062
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 5, 2020
d77cd71
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 17, 2020
817ce3f
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 24, 2020
cda825e
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 26, 2020
f34a3ec
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 27, 2020
f106dc8
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 4, 2020
1f6937e
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 6, 2020
06ffe84
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 6, 2020
5448ceb
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 6, 2020
e9b90fe
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 11, 2020
a7a1d12
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 11, 2020
30b72df
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 26, 2020
76adbc9
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 30, 2020
50e13bc
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 30, 2020
a1c7ca1
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 30, 2020
96fbadc
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 1, 2020
4b026e2
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 9, 2020
38740bc
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 10, 2020
9daf778
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 20, 2020
eff8828
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 21, 2020
ede95de
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 21, 2020
c98f1a1
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 23, 2020
312da6d
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane May 18, 2020
d92972c
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jun 1, 2020
fd4fb2e
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jun 26, 2020
e551136
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jun 30, 2020
cfdca3c
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jul 7, 2020
22505ff
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jul 28, 2020
795a54a
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Aug 10, 2020
433c98b
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 3, 2020
a0521ac
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 24, 2020
635fe74
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 25, 2020
2759212
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Oct 12, 2020
84737d8
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 2, 2020
df5fada
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 2, 2020
9ab7840
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Dec 2, 2020
ed4b566
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jan 8, 2021
f57d220
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jan 20, 2021
6a6d1f4
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 9, 2021
3650c9d
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 10, 2021
85c9d49
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 18, 2021
ca82340
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Feb 23, 2021
12e8f47
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 8, 2021
5d024e7
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Mar 15, 2021
4c87d00
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Apr 22, 2021
93ea6ca
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane May 6, 2021
1eaefc8
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jun 2, 2021
cd4a279
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Jun 7, 2021
4e9ff9f
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Aug 6, 2021
f971232
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Aug 11, 2021
24b2cd0
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 6, 2021
6d3d8a1
Merge remote-tracking branch 'upstream/master'
pm-harshad-mane Sep 10, 2021
e77199c
use minimum floor from each size
pm-harshad-mane Sep 10, 2021
ad80028
added comments
pm-harshad-mane Sep 10, 2021
534c748
floor retrieval: removed custom logic for Video; will pass * for video
pm-harshad-mane Sep 13, 2021
6eb5be6
added some logs
pm-harshad-mane Sep 13, 2021
4616e51
corrected teh value
pm-harshad-mane Sep 13, 2021
f9212ed
indent
pm-harshad-mane Sep 13, 2021
b6581ff
modified the test cases
pm-harshad-mane Sep 13, 2021
b0f8b51
read banner sizes from impObj than bid object
pm-harshad-mane Sep 14, 2021
dea6e23
Merge remote-tracking branch 'upstream/master' into pm_floor_fix
pm-harshad-mane Sep 15, 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
34 changes: 30 additions & 4 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,22 +740,48 @@ function _addFloorFromFloorModule(impObj, bid) {
if (typeof bid.getFloor === 'function' && !config.getConfig('pubmatic.disableFloors')) {
[BANNER, VIDEO, NATIVE].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))
let sizesArray = [];

if (mediaType === 'banner') {
if (impObj[mediaType].w && impObj[mediaType].h) {
sizesArray.push([impObj[mediaType].w, impObj[mediaType].h]);
}
if (utils.isArray(impObj[mediaType].format)) {
impObj[mediaType].format.forEach(size => sizesArray.push([size.w, size.h]));
}
}

if (sizesArray.length === 0) {
sizesArray.push('*')
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if mediaType = banner => use all sizes

else => use *

👍


sizesArray.forEach(size => {
let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: size });
utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module returned for mediatype:', mediaType, ' and size:', size, ' is: currency', floorInfo.currency, 'floor', floorInfo.floor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

with newer versions of prebid, the Bider Code is prefixed in the console, so we do not need our prefix's anymore

(not needed to change this now just something I have to change in our adapter as well!)

if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) {
let mediaTypeFloor = parseFloat(floorInfo.floor);
utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module:', mediaTypeFloor, 'previous floor value', bidFloor, 'Min:', Math.min(mediaTypeFloor, bidFloor));
if (bidFloor === -1) {
bidFloor = mediaTypeFloor;
} else {
bidFloor = Math.min(mediaTypeFloor, bidFloor)
}
utils.logInfo(LOG_WARN_PREFIX, 'new floor value:', 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) {
utils.logInfo(LOG_WARN_PREFIX, 'floor from floor module:', bidFloor, 'impObj.bidfloor', impObj.bidfloor, 'Max:', Math.max(bidFloor, impObj.bidfloor));
bidFloor = Math.max(bidFloor, impObj.bidfloor)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we take the max of (pub provided bidder param kadfloor) and the (minimum floor from all sizes of floors module)

I can't remember if the intention of the 5.0 was just "read the floors module if you use floor signaling" or "if floors module only use that"

Prob the former so I think this PR is fine. Just a note!


// assign value only if bidFloor is > 0
impObj.bidfloor = ((!isNaN(bidFloor) && bidFloor > 0) ? bidFloor : UNDEFINED);
utils.logInfo(LOG_WARN_PREFIX, 'new impObj.bidfloor value:', impObj.bidfloor);
}

function _getFlocId(validBidRequests, flocFormat) {
Expand Down
27 changes: 20 additions & 7 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1846,14 +1846,25 @@ describe('PubMatic adapter', function () {
let newRequest;
let floorModuleTestData;
let getFloor = function(req) {
return floorModuleTestData[req.mediaType];
// actual getFloor module does not work like this :)
// special treatment for banner since for other mediaTypes we pass *
if (req.mediaType === 'banner') {
return floorModuleTestData[req.mediaType][ req.size[0] + 'x' + req.size[1] ] || {};
}
return floorModuleTestData[req.mediaType] || {};
};

beforeEach(() => {
floorModuleTestData = {
'banner': {
'currency': 'USD',
'floor': 1.50
'300x250': {
'currency': 'USD',
'floor': 1.50
},
'300x600': {
'currency': 'USD',
'floor': 2.0
}
},
'video': {
'currency': 'USD',
Expand All @@ -1869,7 +1880,7 @@ describe('PubMatic adapter', function () {
});

it('bidfloor should be undefined if calculation is <= 0', function() {
floorModuleTestData.banner.floor = 0; // lowest of them all
floorModuleTestData.banner['300x250'].floor = 0; // lowest of them all
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest, {
auctionId: 'new-auction-id'
Expand All @@ -1880,7 +1891,8 @@ describe('PubMatic adapter', function () {
});

it('ignore floormodule o/p if floor is not number', function() {
floorModuleTestData.banner.floor = 'INR';
floorModuleTestData.banner['300x250'].floor = 'Not-a-Number';
floorModuleTestData.banner['300x600'].floor = 'Not-a-Number';
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest, {
auctionId: 'new-auction-id'
Expand All @@ -1891,7 +1903,8 @@ describe('PubMatic adapter', function () {
});

it('ignore floormodule o/p if currency is not matched', function() {
floorModuleTestData.banner.currency = 'INR';
floorModuleTestData.banner['300x250'].currency = 'INR';
floorModuleTestData.banner['300x600'].currency = 'INR';
newRequest[0].params.kadfloor = undefined;
let request = spec.buildRequests(newRequest, {
auctionId: 'new-auction-id'
Expand Down Expand Up @@ -1921,7 +1934,7 @@ describe('PubMatic adapter', function () {
expect(data.bidfloor).to.equal(3);
});

it('kadfloor is passed as 1, use min of fllorModule as it is highest', function() {
it('kadfloor is passed as 1, use min of floorModule as it is highest', function() {
newRequest[0].params.kadfloor = '1.0';// yes, we want it as a string
let request = spec.buildRequests(newRequest, {
auctionId: 'new-auction-id'
Expand Down