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()); }