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 3 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
65 changes: 53 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 All @@ -13,6 +13,7 @@ const BIDDER = Object.freeze({
REQUEST_ENDPOINT: '/api/v1/prebid',
TIMEOUT_ENDPOINT: '/api/v1/event/timeout',
GVLID: 972,
// NATIVE?? Referenced below as well as https://docs.prebid.org/dev-docs/bidders/kargo.html
nickllerandi marked this conversation as resolved.
Show resolved Hide resolved
SUPPORTED_MEDIA_TYPES: [BANNER, VIDEO],
});

Expand Down Expand Up @@ -451,6 +452,32 @@ function sendTimeoutData(auctionId, auctionTimeout) {
} catch (e) {}
}

function getBidFloors(bid, mediaType) {
let floorInfo;
try {
floorInfo = bid.getFloor({
currency: 'USD',
mediaType,
size: '*'
});
} catch (e) {
logError('Kargo: getFloor threw an error: ', e);
}
return typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined;
}

function getHighestFloor(bannerFloor, videoFloor, nativeFloor) {
const validFloors = [bannerFloor, videoFloor, nativeFloor].filter(floor => !isNaN(floor));

if (validFloors.length === 0) {
return null;
}

const highestFloor = Math.max(...validFloors);

return highestFloor;
}

function getImpression(bid) {
const imp = {
id: bid.bidId,
Expand All @@ -459,10 +486,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 +505,35 @@ 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;
let bannerFloor, videoFloor, nativeFloor;
const hasGetFloor = typeof bid.getFloor === 'function';

if (banner) {
imp.banner = banner;
if (hasGetFloor) {
bannerFloor = getBidFloors(bid, 'banner');
}
}

if (bid.mediaTypes.video != null) {
imp.video = bid.mediaTypes.video;
if (video) {
imp.video = video;
if (hasGetFloor) {
videoFloor = getBidFloors(bid, 'video');
}
}

nickllerandi marked this conversation as resolved.
Show resolved Hide resolved
if (native) {
imp.native = native;
if (hasGetFloor) {
nativeFloor = getBidFloors(bid, 'native');
}
}

nickllerandi marked this conversation as resolved.
Show resolved Hide resolved
if (bid.mediaTypes.native != null) {
imp.native = bid.mediaTypes.native;
const highestFloor = getHighestFloor(bannerFloor, videoFloor, nativeFloor);
if (highestFloor) {
imp.floor = highestFloor;
}
}

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