Skip to content

Commit

Permalink
Improve Digital Bid Adapter: Bid floor is sent in USD when possible (p…
Browse files Browse the repository at this point in the history
…rebid#12341)

* 12238 - Azerion / Improve: does not properly support currency module

* **Type:** Fix
* **Scope:** improvedigitalBidAdapter
* **Subject:** Bid floors are always converted to USD.
* **Details:**
* Adds `DEFAULT_CURRENCY` variable which is set to USD
* Adds `convertBidFloorCurrency` function which in used to convert the bid floor when both `imp.bidfloor` and `imp.bidfloorcur` are present, and `imp.bidfloorcur` is not equal to the adapter's `DEFAULT_CURRENCY`;
* **Breaks:** N/A

* restored accidentally discarded change from unit test expect

* * Modifies behavior to pass bid floor as is when it cannot be converted to USD;
* Removes rounding of bid floor when converting its currency to USD;

* remove unnecessary uses of `toUpperCase()`

* * fix `convertCurrency` mock
* remove redundant checks for type and NaN from `convertBidFloorCurrency` function

---------

Co-authored-by: Lyubomir Shishkov <l.shishkov@azerion.com>
Co-authored-by: Jozef Bartek <31618107+jbartek25@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 19, 2024
1 parent 22a169f commit b8dcc7c
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 b8dcc7c

Please sign in to comment.