message: Add sample property to Mixpanel events
  Change-type: patch
diff: @@ -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
  