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

KRKPD-987: floors should reference Floors Module #26

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 24 additions & 12 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel } from '../src/utils.js';
import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel, logError } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -459,10 +459,6 @@ function getImpression(bid) {
code: bid.adUnitCode
};

if (bid.floorData != null && bid.floorData.floorMin > 0) {
imp.floor = bid.floorData.floorMin;
}

if (bid.bidRequestsCount > 0) {
imp.bidRequestCount = bid.bidRequestsCount;
}
Expand All @@ -482,17 +478,33 @@ function getImpression(bid) {
}
}

if (bid.mediaTypes != null) {
if (bid.mediaTypes.banner != null) {
imp.banner = bid.mediaTypes.banner;
if (bid.mediaTypes) {
const { banner, video, native } = bid.mediaTypes;

if (banner) {
imp.banner = banner;
}

if (bid.mediaTypes.video != null) {
imp.video = bid.mediaTypes.video;
if (video) {
imp.video = video;
}

nickllerandi marked this conversation as resolved.
Show resolved Hide resolved
if (bid.mediaTypes.native != null) {
imp.native = bid.mediaTypes.native;
if (native) {
imp.native = native;
}

nickllerandi marked this conversation as resolved.
Show resolved Hide resolved
if (typeof bid.getFloor === 'function') {
let floorInfo;
try {
floorInfo = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
});
} catch (e) {
logError('Kargo: getFloor threw an error: ', e);
}
imp.floor = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined;
}
}

Expand Down
16 changes: 14 additions & 2 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ describe('kargo adapter tests', function () {
},
fpd: {
gpid: '/22558409563,18834096/dfy_mobile_adhesion'
}
},
floor: 2
},
{
code: '303',
Expand All @@ -503,7 +504,8 @@ describe('kargo adapter tests', function () {
},
fpd: {
gpid: '/22558409563,18834096/dfy_mobile_adhesion'
}
},
floor: 3
}
],
socan: {
Expand Down Expand Up @@ -605,6 +607,16 @@ describe('kargo adapter tests', function () {
payload['gdprConsent'] = gdpr
}

clonedBids.forEach(bid => {
if (bid.mediaTypes.banner) {
bid.getFloor = () => ({ currency: 'USD', floor: 1 });
} else if (bid.mediaTypes.video) {
bid.getFloor = () => ({ currency: 'USD', floor: 2 });
} else if (bid.mediaTypes.native) {
bid.getFloor = () => ({ currency: 'USD', floor: 3 });
}
});

var request = spec.buildRequests(clonedBids, payload);
var krakenParams = request.data;

Expand Down