mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-20 09:46:31 +00:00
Add sample property to Mixpanel events
Change-type: patch Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzoa@balena.io>
This commit is contained in:
parent
af462b3486
commit
fc1c1b402b
@ -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,10 +48,16 @@ resinCorvus.install({
|
||||
}
|
||||
})
|
||||
|
||||
let mixpanelSample = DEFAULT_PROBABILITY
|
||||
|
||||
getConfig(configUrl)
|
||||
.then((config) => {
|
||||
const mixpanel = _.get(config, [ 'analytics', 'mixpanel' ], {})
|
||||
const probability = mixpanel.probability || DEFAULT_PROBABILITY
|
||||
mixpanelSample = probability
|
||||
const validatedConfig = isClientEligible(probability) ? validateMixpanelConfig(mixpanel) : null
|
||||
resinCorvus.setConfigs({
|
||||
mixpanel: getMixpanelConfig(config)
|
||||
mixpanel: validatedConfig
|
||||
})
|
||||
})
|
||||
|
||||
@ -70,14 +76,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 +128,12 @@ exports.logDebug = resinCorvus.logDebug
|
||||
* image: '/dev/disk2'
|
||||
* });
|
||||
*/
|
||||
exports.logEvent = resinCorvus.logEvent
|
||||
exports.logEvent = (message, data) => {
|
||||
const sessionData = {
|
||||
mixpanelSample
|
||||
}
|
||||
resinCorvus.logEvent(message, { ...data, sessionData })
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Log an exception
|
||||
|
Loading…
x
Reference in New Issue
Block a user