From da018c363977d332a0acbf35921071bc1ea14fef Mon Sep 17 00:00:00 2001 From: Mark Hahnenberg Date: Mon, 27 Mar 2017 14:05:36 -0700 Subject: [PATCH] [client-app] Report battery state changes to Mixpanel Summary: This diff will give us insight into how people use Nylas Mail on their computers with respect to how mobile they are (i.e. whether they use NM on battery or plugged in). Test Plan: Run locally Reviewers: evan, spang, juan Reviewed By: juan Subscribers: gleb Differential Revision: https://phab.nylas.com/D4267 --- .../client-app/src/services/battery-status-manager.es6 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/client-app/src/services/battery-status-manager.es6 b/packages/client-app/src/services/battery-status-manager.es6 index 7e1a11e9e..a9241be11 100644 --- a/packages/client-app/src/services/battery-status-manager.es6 +++ b/packages/client-app/src/services/battery-status-manager.es6 @@ -1,8 +1,11 @@ +import moment from 'moment-timezone' +import Actions from '../flux/actions' class BatteryStatusManager { constructor() { this._callbacks = []; this._battery = null; + this._lastChangeTime = Date.now(); } async activate() { @@ -22,6 +25,12 @@ class BatteryStatusManager { } _onChargingChange = () => { + const changeTime = Date.now(); + Actions.recordUserEvent("Battery State Changed", { + oldState: this.isBatteryCharging() ? 'battery' : 'ac', + oldStateDuration: Math.min(changeTime - this._lastChangeTime, moment.duration(12, 'hours').asMilliseconds()), + }); + this._lastChangeTime = changeTime; this._callbacks.forEach(cb => cb()); }