Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

Add an option for Price Floors module to wait for currency

Open piotrj-rtbh opened this issue 2 years ago • 6 comments

Type of issue

Bug: the Price Floors module is not able to properly use the Currency module for converting currencies in bid floors if the exchange rates are taken from an external file (eg. the default one on jsdelivr)

Description

Currency conversion should take place after the currency rate file is loaded so to safely apply the actual rates. Only in certain cases (eg. file could not be loaded or a timeout) the rates should be taken from the currency.defaultRates property. We have noticed that once the currency file is cached then the exchange rates are taken from the file. It happens to load quickly right before the bidRequests are to be processed. Without caching the file is loaded but too late and the floors are calculated with the use of defaultRates only.

Steps to reproduce

  1. Build the bundle using your bidder adapter which is able to use Price Floors module (calls bidRequest.getFloor() method somewhere) and the bidder should accept USD; add also: currency and priceFloors modules
  2. Add it as your prebid.js file
  3. Setup standard prebid environment with one ad unit and one ad size (should be enough)
  4. Add the following to your ad unit:
floors: {
      currency: "EUR",
      schema: {
        fields: ["mediaType"]
      },
      values: {
        banner: 0.3
      }
    },
  1. Make a setConfig call with params:
pbjs.setConfig({
    currency: {
      adServerCurrency: "EUR",
      defaultRates: { EUR: { USD: 10 } }
    },
    floors: {}
  });

Test page

Codesandbox test page: https://efo8ku.csb.app/?pbjs_debug=true

Expected results

With caching turned on it works as expected. The messages are in that order:

MESSAGE: Emitting event for: requestBids
INFO: currencyRates set to {"dataAsOf":....
...
MESSAGE: Emitting event for: beforeRequestBids
...
MESSAGE: CALLING BIDDER
MESSAGE: Emitting event for: bidRequested
INFO: getCurrencyConversion using reciprocal EUR to USD conversionRate 1.0894
MESSAGE: Adding conversionCache value 1.0894 for EUR->USD
MESSAGE: Emitting event for: beforeBidderHttp

Actual results

With caching turned off the messages are in that order:

MESSAGE: Emitting event for: requestBids
...
MESSAGE: Emitting event for: beforeRequestBids
...
MESSAGE: CALLING BIDDER
MESSAGE: Emitting event for: bidRequested
INFO: getCurrencyConversion using direct EUR to USD conversionRate 10
MESSAGE: Adding conversionCache value 10 for EUR->USD
MESSAGE: Emitting event for: beforeBidderHttp
INFO: currencyRates set to {"dataAsOf":...

Platform details

Prebid 7.34.0, Chrome 109.0.5414.120, Windows 10, Node 14.20.0, npm 6.14.17

Other information

piotrj-rtbh avatar Feb 01 '23 16:02 piotrj-rtbh