mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 19:26:33 +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 DEFAULT_PROBABILITY = 1
|
||||
const DEFAULT_PROBABILITY = 0.1
|
||||
|
||||
const services = {
|
||||
sentry: sentryToken,
|
||||
@ -48,12 +48,30 @@ resinCorvus.install({
|
||||
}
|
||||
})
|
||||
|
||||
getConfig(configUrl)
|
||||
.then((config) => {
|
||||
resinCorvus.setConfigs({
|
||||
mixpanel: getMixpanelConfig(config)
|
||||
})
|
||||
let mixpanelSample = DEFAULT_PROBABILITY
|
||||
|
||||
/**
|
||||
* @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({
|
||||
mixpanel: validatedConfig
|
||||
})
|
||||
}
|
||||
|
||||
initConfig()
|
||||
|
||||
/**
|
||||
* @summary Get etcher configs stored online
|
||||
@ -70,14 +88,8 @@ function getConfig(url) {
|
||||
* @param {Object} - config
|
||||
*/
|
||||
// eslint-disable-next-line
|
||||
function getMixpanelConfig(config) {
|
||||
const analytics = config.analytics || {}
|
||||
const mixpanel = analytics.mixpanel || {}
|
||||
const probability = mixpanel.probability || DEFAULT_PROBABILITY
|
||||
if (Math.random() > probability) {
|
||||
return null
|
||||
}
|
||||
return validateMixpanelConfig(mixpanel)
|
||||
function isClientEligible(probability) {
|
||||
return Math.random() > probability
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +140,9 @@ exports.logDebug = resinCorvus.logDebug
|
||||
* image: '/dev/disk2'
|
||||
* });
|
||||
*/
|
||||
exports.logEvent = resinCorvus.logEvent
|
||||
exports.logEvent = (message, data) => {
|
||||
resinCorvus.logEvent(message, { ...data, sample: mixpanelSample })
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Log an exception
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 481cacb7f1533985507c84f28940cada0fb109e5
|
||||
Subproject commit c80a0d906ffbfcac7d5490b8daf02d528d4a87aa
|
Loading…
x
Reference in New Issue
Block a user