Skip to content

Commit

Permalink
Merge pull request #26 from KargoGlobal/krkpd-987-utilizeFloorsMod
Browse files Browse the repository at this point in the history
KRKPD-987: floors should reference Floors Module
  • Loading branch information
nickllerandi authored Mar 8, 2024
2 parents 0698fbc + 3acaeda commit 2344cab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
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;
}

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

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

0 comments on commit 2344cab

Please sign in to comment.