mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-28 05:36:34 +00:00
Merge pull request #2726 from balena-io/analytics-version-weight
Add sample property to Mixpanel events
This commit is contained in:
commit
b73ebb6f92
@ -31,7 +31,7 @@ const mixpanelToken = settings.get('analyticsMixpanelToken') ||
|
|||||||
|
|
||||||
const configUrl = settings.get('configUrl') || 'http://balena.io/etcher/static/config.json'
|
const configUrl = settings.get('configUrl') || 'http://balena.io/etcher/static/config.json'
|
||||||
|
|
||||||
const DEFAULT_PROBABILITY = 1
|
const DEFAULT_PROBABILITY = 0.1
|
||||||
|
|
||||||
const services = {
|
const services = {
|
||||||
sentry: sentryToken,
|
sentry: sentryToken,
|
||||||
@ -48,12 +48,30 @@ resinCorvus.install({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
getConfig(configUrl)
|
let mixpanelSample = DEFAULT_PROBABILITY
|
||||||
.then((config) => {
|
|
||||||
|
/**
|
||||||
|
* @summary Init analytics configurations
|
||||||
|
* @example initConfig()
|
||||||
|
*/
|
||||||
|
const initConfig = async () => {
|
||||||
|
let validatedConfig = null
|
||||||
|
try {
|
||||||
|
const config = await getConfig(configUrl)
|
||||||
|
const mixpanel = _.get(config, [ 'analytics', 'mixpanel' ], {})
|
||||||
|
mixpanelSample = mixpanel.probability || DEFAULT_PROBABILITY
|
||||||
|
if (isClientEligible(mixpanelSample)) {
|
||||||
|
validatedConfig = validateMixpanelConfig(mixpanel)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
resinCorvus.logException(err)
|
||||||
|
}
|
||||||
resinCorvus.setConfigs({
|
resinCorvus.setConfigs({
|
||||||
mixpanel: getMixpanelConfig(config)
|
mixpanel: validatedConfig
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
initConfig()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Get etcher configs stored online
|
* @summary Get etcher configs stored online
|
||||||
@ -70,14 +88,8 @@ function getConfig(url) {
|
|||||||
* @param {Object} - config
|
* @param {Object} - config
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
function getMixpanelConfig(config) {
|
function isClientEligible(probability) {
|
||||||
const analytics = config.analytics || {}
|
return Math.random() > probability
|
||||||
const mixpanel = analytics.mixpanel || {}
|
|
||||||
const probability = mixpanel.probability || DEFAULT_PROBABILITY
|
|
||||||
if (Math.random() > probability) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return validateMixpanelConfig(mixpanel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,7 +140,9 @@ exports.logDebug = resinCorvus.logDebug
|
|||||||
* image: '/dev/disk2'
|
* image: '/dev/disk2'
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
exports.logEvent = resinCorvus.logEvent
|
exports.logEvent = (message, data) => {
|
||||||
|
resinCorvus.logEvent(message, { ...data, sample: mixpanelSample })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Log an exception
|
* @summary Log an exception
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 481cacb7f1533985507c84f28940cada0fb109e5
|
Subproject commit c80a0d906ffbfcac7d5490b8daf02d528d4a87aa
|
Loading…
x
Reference in New Issue
Block a user