Skip to content

Commit

Permalink
Merge pull request #20 from ImproveDigital/improvedigital-bid-floor-c…
Browse files Browse the repository at this point in the history
…urrency-convertion

Improve Digital Bid Adapter: Bid floor is sent in USD when possible
  • Loading branch information
jbartek25 authored Oct 17, 2024
2 parents 4cc7d25 + 9e0a49c commit cb54dce
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
23 changes: 22 additions & 1 deletion modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
import {hasPurpose1Consent} from '../src/utils/gdpr.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import {convertCurrency} from '../libraries/currencyUtils/currency.js';
/**
* See https://github.com/prebid/Prebid.js/pull/8827 for details on linting exception
* ImproveDigital only imports after winning a bid and only if the creative cannot reach top
Expand All @@ -30,6 +31,7 @@ const BASIC_ADS_BASE_URL = 'https://ad.360yield-basic.com';
const PB_ENDPOINT = 'pb';
const EXTEND_URL = 'https://pbs.360yield.com/openrtb2/auction';
const IFRAME_SYNC_URL = 'https://hb.360yield.com/prebid-universal-creative/load-cookie.html';
const DEFAULT_CURRENCY = 'USD';

const VIDEO_PARAMS = {
DEFAULT_MIMES: ['video/mp4']
Expand Down Expand Up @@ -125,6 +127,21 @@ export const spec = {

registerBidder(spec);

const convertBidFloorCurrency = (imp) => {
try {
const bidFloor = convertCurrency(
imp.bidfloor,
imp.bidfloorcur,
DEFAULT_CURRENCY,
false,
);
imp.bidfloor = bidFloor;
imp.bidfloorcur = DEFAULT_CURRENCY;
} catch (err) {
logWarn(`Failed to convert bid floor to ${DEFAULT_CURRENCY}. Passing floor price in its original currency.`, err);
}
};

export const CONVERTER = ortbConverter({
context: {
ttl: CREATIVE_TTL,
Expand All @@ -139,7 +156,11 @@ export const CONVERTER = ortbConverter({
imp.secure = Number(window.location.protocol === 'https:');
if (!imp.bidfloor && bidRequest.params.bidFloor) {
imp.bidfloor = bidRequest.params.bidFloor;
imp.bidfloorcur = getBidIdParameter('bidFloorCur', bidRequest.params).toUpperCase() || 'USD'
imp.bidfloorcur = getBidIdParameter('bidFloorCur', bidRequest.params).toUpperCase() || DEFAULT_CURRENCY;
}

if (imp.bidfloor && imp.bidfloorcur && imp.bidfloorcur !== DEFAULT_CURRENCY) {
convertBidFloorCurrency(imp);
}
const bidderParamsPath = context.extendMode ? 'ext.prebid.bidder.improvedigital' : 'ext.bidder';
const placementId = bidRequest.params.placementId;
Expand Down
Loading

0 comments on commit cb54dce

Please sign in to comment.