diff --git a/src/auction.js b/src/auction.js index c7ccaa27b14..603172d406a 100644 --- a/src/auction.js +++ b/src/auction.js @@ -117,6 +117,13 @@ const queuedCalls = []; const pbjsInstance = getGlobal(); +/** + * Get Prebid config options + * @param {Object} options + * @alias module:pbjs.getConfig + */ +pbjsInstance.getConfig = config.getAnyConfig; + /** * Clear global state for tests */ @@ -912,6 +919,11 @@ export function adjustBids(bid) { if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; + // Get the currency adjust setting for this bidder + const shouldAdjustCurrency = bidderSettings.getCurrencyAdjust(bid.bidderCode); + if (shouldAdjustCurrency === true) { + bid.currency = config.getConfig('currency')?.adServerCurrency; + } } } diff --git a/src/bidderSettings.js b/src/bidderSettings.js index 4d97ed2b95e..7e0681e2900 100644 --- a/src/bidderSettings.js +++ b/src/bidderSettings.js @@ -8,6 +8,22 @@ export class ScopedSettings { this.defaultScope = defaultScope; } + // To validate currency settings + validateCurrencyAdjust(value) { + return value === undefined || typeof value === 'boolean'; + } + + // Currency Adjust Method + getCurrencyAdjust(bidderCode) { + // For bidder specific + let currencyAdjust = this.get(bidderCode, JSON_MAPPING.CURRENCY_ADJUST); + // For standard + if (typeof currencyAdjust === 'undefined') { + currencyAdjust = this.get(this.defaultScope, JSON_MAPPING.CURRENCY_ADJUST); + } + return currencyAdjust; + } + /** * Get setting value at `path` under the given scope, falling back to the default scope if needed. * If `scope` is `null`, get the setting's default value. diff --git a/src/constants.js b/src/constants.js index 1a17cf3eec0..9d660c78e29 100644 --- a/src/constants.js +++ b/src/constants.js @@ -6,7 +6,8 @@ export const JSON_MAPPING = { BD_ID: 'paramsd', BD_PL_ID: 'placementId', ADSERVER_TARGETING: 'adserverTargeting', - BD_SETTING_STANDARD: 'standard' + BD_SETTING_STANDARD: 'standard', + CURRENCY_ADJUST: 'adjustCurrency' }; export const DEBUG_MODE = 'pbjs_debug'; diff --git a/test/spec/unit/core/bidderSettings_currency_spec.js b/test/spec/unit/core/bidderSettings_currency_spec.js new file mode 100644 index 00000000000..574405c956c --- /dev/null +++ b/test/spec/unit/core/bidderSettings_currency_spec.js @@ -0,0 +1,92 @@ +// test/spec/bidderSettings_currency_spec.js +import { JSON_MAPPING } from '../../../../src/constants.js'; +import { expect } from 'chai/index.js'; +import {bidderSettings} from '../../../../src/bidderSettings.js'; +import {config} from '../../../../src/config.js'; +import { getGlobal } from '../../../../src/prebidGlobal'; +import { adjustBids } from '../../../../src/auction.js'; + +describe('Bidder Settings Currency Adjustment', function() { + let bid; + let sandbox; + + beforeEach(function() { + bid = { + bidderCode: 'appnexus', + cpm: 1.5, + currency: 'USD' + }; + + // Reset pbjs global object + window.pbjs = getGlobal(); + window.pbjs.bidderSettings = {}; + + // Set default currency config + config.setConfig({ + currency: { + adServerCurrency: 'EUR' + } + }); + }); + + afterEach(function() { + config.resetConfig(); + }); + + describe('currency adjustment setting', function() { + it('should respect bidder-specific currency adjustment setting', function() { + // Setup + window.pbjs.bidderSettings = { + appnexus: { + [JSON_MAPPING.CURRENCY_ADJUST]: true + } + }; + + // Execute + adjustBids(bid); + + // Assert + expect(bid.currency).to.equal('EUR'); + }); + + it('should use standard setting when bidder-specific not defined', function() { + // Setup + window.pbjs.bidderSettings = { + standard: { + [JSON_MAPPING.CURRENCY_ADJUST]: true + } + }; + + // Execute + adjustBids(bid); + + // Assert + expect(bid.currency).to.equal('EUR'); + }); + + it('should not adjust currency when setting is false', function() { + // Setup + window.pbjs.bidderSettings = { + appnexus: { + [JSON_MAPPING.CURRENCY_ADJUST]: false + } + }; + + // Execute + adjustBids(bid); + + // Assert + expect(bid.currency).to.equal('USD'); + }); + + it('should not adjust currency when setting is undefined', function() { + // Setup - no settings defined + + // Execute + adjustBids(bid); + + // Assert + expect(bid.currency).to.equal('USD'); + }); + }); +});