Skip to content

Commit

Permalink
Rubicon analytics (prebid#2278)
Browse files Browse the repository at this point in the history
rubicon analytics adapter
  • Loading branch information
snapwich authored and dluxemburg committed Jul 17, 2018
1 parent e40244f commit 4df0fb0
Show file tree
Hide file tree
Showing 16 changed files with 6,942 additions and 7,288 deletions.
12 changes: 6 additions & 6 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function newPluginsArray(browserstack) {
'karma-chrome-launcher',
'karma-coverage-istanbul-reporter',
'karma-es5-shim',
'karma-expect',
'karma-mocha',
'karma-chai',
'karma-requirejs',
'karma-sinon',
'karma-sourcemap-loader',
Expand All @@ -43,7 +43,6 @@ function newPluginsArray(browserstack) {
];
if (browserstack) {
plugins.push('karma-browserstack-launcher');
plugins.push('karma-sauce-launcher');
plugins.push('karma-firefox-launcher');
plugins.push('karma-opera-launcher');
plugins.push('karma-safari-launcher');
Expand All @@ -64,8 +63,6 @@ function setReporters(karmaConf, codeCoverage, browserstack) {
suppressSkipped: false,
suppressPassed: true
};
} else {
karmaConf.reporters = ['progress'];
}
if (codeCoverage) {
karmaConf.reporters.push('coverage-istanbul');
Expand Down Expand Up @@ -120,7 +117,7 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) {
},
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['es5-shim', 'mocha', 'expect', 'sinon'],
frameworks: ['es5-shim', 'mocha', 'chai', 'sinon'],

files: files,

Expand All @@ -143,7 +140,10 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) {
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

reporters: ['progress'],
reporters: ['mocha'],
mochaReporter: {
showDiff: true
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
Expand Down
32 changes: 17 additions & 15 deletions modules/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,21 @@ function processBidResponseQueue() {

function wrapFunction(fn, context, params) {
return function() {
var bid = params[1];
let bid = params[1];
if (bid !== undefined && 'currency' in bid && 'cpm' in bid) {
var fromCurrency = bid.currency;
let fromCurrency = bid.currency;
try {
var conversion = getCurrencyConversion(fromCurrency);
bid.originalCpm = bid.cpm;
let conversion = getCurrencyConversion(fromCurrency);
let cpm = bid.originalCpm = bid.cpm;
bid.originalCurrency = bid.currency;
if (conversion !== 1) {
bid.cpm = (parseFloat(bid.cpm) * conversion).toFixed(4);
bid.currency = adServerCurrency;
}
// used for analytics
bid.getCpmInNewCurrency = function(toCurrency) {
return (parseFloat(cpm) * getCurrencyConversion(fromCurrency, toCurrency)).toFixed(3);
};
} catch (e) {
utils.logWarn('Returning NO_BID, getCurrencyConversion threw error: ', e);
params[1] = bidfactory.createBid(STATUS.NO_BID, {
Expand All @@ -196,24 +200,22 @@ function wrapFunction(fn, context, params) {
};
}

function getCurrencyConversion(fromCurrency) {
function getCurrencyConversion(fromCurrency, toCurrency = adServerCurrency) {
var conversionRate = null;
var rates;

if (fromCurrency in conversionCache) {
conversionRate = conversionCache[fromCurrency];
utils.logMessage('Using conversionCache value ' + conversionRate + ' for fromCurrency ' + fromCurrency);
let cacheKey = `${fromCurrency}->${toCurrency}`;
if (cacheKey in conversionCache) {
conversionRate = conversionCache[cacheKey];
utils.logMessage('Using conversionCache value ' + conversionRate + ' for ' + cacheKey);
} else if (currencySupportEnabled === false) {
if (fromCurrency === 'USD') {
conversionRate = 1;
} else {
throw new Error('Prebid currency support has not been enabled and fromCurrency is not USD');
}
} else if (fromCurrency === adServerCurrency) {
} else if (fromCurrency === toCurrency) {
conversionRate = 1;
} else {
var toCurrency = adServerCurrency;

if (fromCurrency in currencyRates.conversions) {
// using direct conversion rate from fromCurrency to toCurrency
rates = currencyRates.conversions[fromCurrency];
Expand Down Expand Up @@ -252,9 +254,9 @@ function getCurrencyConversion(fromCurrency) {
utils.logInfo('getCurrencyConversion using intermediate ' + fromCurrency + ' thru ' + anyBaseCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate);
}
}
if (!(fromCurrency in conversionCache)) {
utils.logMessage('Adding conversionCache value ' + conversionRate + ' for fromCurrency ' + fromCurrency);
conversionCache[fromCurrency] = conversionRate;
if (!(cacheKey in conversionCache)) {
utils.logMessage('Adding conversionCache value ' + conversionRate + ' for ' + cacheKey);
conversionCache[cacheKey] = conversionRate;
}
return conversionRate;
}
Expand Down
Loading

0 comments on commit 4df0fb0

Please sign in to comment.