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

Improve Digital Bid Adapter: Bid floor is sent in USD when possible #20

Merged
merged 5 commits into from
Oct 17, 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
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 @@ -29,6 +30,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 @@ -124,6 +126,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 @@ -138,7 +155,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;
lyubomirshishkov marked this conversation as resolved.
Show resolved Hide resolved
}

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