diff --git a/app/src/reducers/index.ts b/app/src/reducers/index.ts index f93a1eb..f3fba97 100644 --- a/app/src/reducers/index.ts +++ b/app/src/reducers/index.ts @@ -2,6 +2,8 @@ import * as q from '../../../backend/src/Model' import { Action, Reducer } from 'redux' +import { trackEvent } from '../tracking' + export enum ActionTypes { setAutoExpandLimit = 'SET_AUTO_EXPAND_LIMIT', toggleSettingsVisibility = 'TOGGLE_SETTINGS_VISIBILITY', @@ -48,6 +50,7 @@ const reducer: Reducer = (state, action) => if (!state) { throw Error('No initial state') } + trackEvent(action.type) switch (action.type) { case ActionTypes.setAutoExpandLimit: diff --git a/app/src/tracking.ts b/app/src/tracking.ts index 3411b9d..0f65104 100644 --- a/app/src/tracking.ts +++ b/app/src/tracking.ts @@ -1,5 +1,21 @@ +let userId = window.localStorage.getItem('userId') +const sha1 = require('sha1') + +if (!userId) { + userId = sha1(sha1(Math.random()) + sha1(performance.now()) + sha1(Date.now())).slice(0, 8) as string + window.localStorage.setItem('userId', userId) +} + const Nucleus = require('electron-nucleus')('5c3b3e0443b7cc00eec3782b', { + userId, disableInDev: true, }) export default Nucleus + +export function trackEvent(name: string) { + if (name.match(/^@@redux/)) { + return + } + Nucleus.track(name) +}