From bf59478e0872d3965180278e68e85f6111711789 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Mon, 13 Jan 2025 16:29:26 +0500 Subject: [PATCH 01/13] Getting whole bid from bidcpmadjustment function and then equalizing the bid currency to the converted currency --- src/auction.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/auction.js b/src/auction.js index c7ccaa27b14..8575f7647bd 100644 --- a/src/auction.js +++ b/src/auction.js @@ -908,10 +908,11 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { } export function adjustBids(bid) { - let bidPriceAdjusted = adjustCpm(bid.cpm, bid); + let bidPriceAdjusted = adjustCpm(bid, bid); - if (bidPriceAdjusted >= 0) { - bid.cpm = bidPriceAdjusted; + if (bidPriceAdjusted.cpm >= 0) { + bid.cpm = bidPriceAdjusted.cpm; + bid.currency = bidPriceAdjusted.currency } } From ea182c0c8dd6e34185907bf983830fe4f3f59405 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Mon, 13 Jan 2025 17:09:13 +0500 Subject: [PATCH 02/13] Setting the bidCurrency to adServerCurrency for people using bidcpmadjustment --- src/auction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/auction.js b/src/auction.js index c7ccaa27b14..a1a0b537f57 100644 --- a/src/auction.js +++ b/src/auction.js @@ -912,6 +912,7 @@ export function adjustBids(bid) { if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; + bid.currency = adServerCurrency; } } From 99e8e72d3b2d9a20a5abcdff09f5af2026989cbc Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Mon, 13 Jan 2025 17:31:10 +0500 Subject: [PATCH 03/13] Adjusted adservercurrency retrieval for currency code conversion correctly in Prebid Professor --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index 8658b3a1fce..b9c6d11b0b8 100644 --- a/src/auction.js +++ b/src/auction.js @@ -912,7 +912,7 @@ export function adjustBids(bid) { if (bidPriceAdjusted.cpm >= 0) { bid.cpm = bidPriceAdjusted; - bid.currency = adServerCurrency + bid.currency = $$PREBID_GLOBAL$$.getConfig('currency').adServerCurrency; } } From 54b91a1469b40185adbf3806585c474b0edc71d3 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 11:29:27 +0500 Subject: [PATCH 04/13] Resolving bidpriceadjusted error and requesting a review again --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index b9c6d11b0b8..83bacd21647 100644 --- a/src/auction.js +++ b/src/auction.js @@ -910,7 +910,7 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { export function adjustBids(bid) { let bidPriceAdjusted = adjustCpm(bid.cpm, bid); - if (bidPriceAdjusted.cpm >= 0) { + if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; bid.currency = $$PREBID_GLOBAL$$.getConfig('currency').adServerCurrency; } From 5a356e857a4529a647d44db8089754f8848f33e6 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 11:35:03 +0500 Subject: [PATCH 05/13] pbjs error resolved --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index 83bacd21647..7c8eb5c116a 100644 --- a/src/auction.js +++ b/src/auction.js @@ -912,7 +912,7 @@ export function adjustBids(bid) { if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; - bid.currency = $$PREBID_GLOBAL$$.getConfig('currency').adServerCurrency; + bid.currency = pbjs.getConfig('currency')?.adServerCurrency; } } From ca1664bb2f0e19f1e23cd87608ae7cbb5b7b1303 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 11:43:59 +0500 Subject: [PATCH 06/13] declared pbjs to rectify error --- src/auction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/auction.js b/src/auction.js index 7c8eb5c116a..98d809d4fc0 100644 --- a/src/auction.js +++ b/src/auction.js @@ -116,6 +116,7 @@ const sourceInfo = {}; const queuedCalls = []; const pbjsInstance = getGlobal(); +var pbjs = pbjs || {}; /** * Clear global state for tests From 8bc3d3b666a077909411887ab3196719b12abc54 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 11:50:41 +0500 Subject: [PATCH 07/13] Tried resolving lint error --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index 98d809d4fc0..0455bc91af5 100644 --- a/src/auction.js +++ b/src/auction.js @@ -100,6 +100,7 @@ import {ttlCollection} from './utils/ttlCollection.js'; import {getMinBidCacheTTL, onMinBidCacheTTLChange} from './bidTTL.js'; const { syncUsers } = userSync; +var pbjs = pbjs || {}; export const AUCTION_STARTED = 'started'; export const AUCTION_IN_PROGRESS = 'inProgress'; @@ -116,7 +117,6 @@ const sourceInfo = {}; const queuedCalls = []; const pbjsInstance = getGlobal(); -var pbjs = pbjs || {}; /** * Clear global state for tests From 24faedd63d99c2eb13f6067a0272babcc250acc2 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 12:05:53 +0500 Subject: [PATCH 08/13] lint error resolve --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index 0455bc91af5..07684325b19 100644 --- a/src/auction.js +++ b/src/auction.js @@ -100,7 +100,6 @@ import {ttlCollection} from './utils/ttlCollection.js'; import {getMinBidCacheTTL, onMinBidCacheTTLChange} from './bidTTL.js'; const { syncUsers } = userSync; -var pbjs = pbjs || {}; export const AUCTION_STARTED = 'started'; export const AUCTION_IN_PROGRESS = 'inProgress'; @@ -909,6 +908,7 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { } export function adjustBids(bid) { + var pbjs = pbjs || {}; let bidPriceAdjusted = adjustCpm(bid.cpm, bid); if (bidPriceAdjusted >= 0) { From 761a13c2c6eca5fe6b36b1548b9750adce952105 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 12:10:53 +0500 Subject: [PATCH 09/13] lint error resolve --- src/auction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auction.js b/src/auction.js index 07684325b19..25f655e9291 100644 --- a/src/auction.js +++ b/src/auction.js @@ -101,6 +101,9 @@ import {getMinBidCacheTTL, onMinBidCacheTTLChange} from './bidTTL.js'; const { syncUsers } = userSync; +const pbjsInstance = getGlobal(); +var pbjs = pbjs || {}; + export const AUCTION_STARTED = 'started'; export const AUCTION_IN_PROGRESS = 'inProgress'; export const AUCTION_COMPLETED = 'completed'; @@ -115,8 +118,6 @@ const outstandingRequests = {}; const sourceInfo = {}; const queuedCalls = []; -const pbjsInstance = getGlobal(); - /** * Clear global state for tests */ @@ -908,7 +909,6 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { } export function adjustBids(bid) { - var pbjs = pbjs || {}; let bidPriceAdjusted = adjustCpm(bid.cpm, bid); if (bidPriceAdjusted >= 0) { From 6857db3529df413bf8c9ceded189acf41ab67ccf Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 12:24:05 +0500 Subject: [PATCH 10/13] lint error resolve --- src/auction.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/auction.js b/src/auction.js index 25f655e9291..e1e0823f235 100644 --- a/src/auction.js +++ b/src/auction.js @@ -101,9 +101,6 @@ import {getMinBidCacheTTL, onMinBidCacheTTLChange} from './bidTTL.js'; const { syncUsers } = userSync; -const pbjsInstance = getGlobal(); -var pbjs = pbjs || {}; - export const AUCTION_STARTED = 'started'; export const AUCTION_IN_PROGRESS = 'inProgress'; export const AUCTION_COMPLETED = 'completed'; @@ -118,6 +115,15 @@ const outstandingRequests = {}; const sourceInfo = {}; 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 */ From 67b78fed42919ff360340c04f5278a7747144669 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Tue, 14 Jan 2025 12:28:47 +0500 Subject: [PATCH 11/13] Fixed pbjs not defined linting error --- src/auction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index e1e0823f235..90b6a278d38 100644 --- a/src/auction.js +++ b/src/auction.js @@ -919,7 +919,7 @@ export function adjustBids(bid) { if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; - bid.currency = pbjs.getConfig('currency')?.adServerCurrency; + bid.currency = config.getConfig('currency')?.adServerCurrency; } } From 722e05496d1657d60812868ac759531f4b61e746 Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Wed, 15 Jan 2025 15:34:08 +0500 Subject: [PATCH 12/13] Added currency code adjustment as optional and created unit test --- src/auction.js | 8 +- src/bidderSettings.js | 18 ++++ src/constants.js | 3 +- .../unit/core/bidderSettings_currency_spec.js | 92 +++++++++++++++++++ 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 test/spec/unit/core/bidderSettings_currency_spec.js diff --git a/src/auction.js b/src/auction.js index 90b6a278d38..4f7ff0b27e4 100644 --- a/src/auction.js +++ b/src/auction.js @@ -919,7 +919,13 @@ export function adjustBids(bid) { if (bidPriceAdjusted >= 0) { bid.cpm = bidPriceAdjusted; - bid.currency = config.getConfig('currency')?.adServerCurrency; + + // 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..88b33e078bb 100644 --- a/src/bidderSettings.js +++ b/src/bidderSettings.js @@ -8,6 +8,24 @@ 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..4014445311c --- /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'); + }); + }); +}); \ No newline at end of file From e32c56bb4a5b38648ceaf8e6eab517b2d5341e1b Mon Sep 17 00:00:00 2001 From: Muhammad Ubaid Ashraf Date: Wed, 15 Jan 2025 15:46:47 +0500 Subject: [PATCH 13/13] Clear lint --- src/auction.js | 2 -- src/bidderSettings.js | 2 -- test/spec/unit/core/bidderSettings_currency_spec.js | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/auction.js b/src/auction.js index 4f7ff0b27e4..603172d406a 100644 --- a/src/auction.js +++ b/src/auction.js @@ -919,10 +919,8 @@ 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 88b33e078bb..7e0681e2900 100644 --- a/src/bidderSettings.js +++ b/src/bidderSettings.js @@ -17,12 +17,10 @@ export class ScopedSettings { 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; } diff --git a/test/spec/unit/core/bidderSettings_currency_spec.js b/test/spec/unit/core/bidderSettings_currency_spec.js index 4014445311c..574405c956c 100644 --- a/test/spec/unit/core/bidderSettings_currency_spec.js +++ b/test/spec/unit/core/bidderSettings_currency_spec.js @@ -89,4 +89,4 @@ describe('Bidder Settings Currency Adjustment', function() { expect(bid.currency).to.equal('USD'); }); }); -}); \ No newline at end of file +});