blob: e848ca3fd9fba61da53dc38ca9e9b8d83d0c1d1f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import { Middleware } from 'redux';
import { State } from 'ts/redux/reducer';
import { ActionTypes } from 'ts/types';
import { analytics } from 'ts/utils/analytics';
export const analyticsMiddleware: Middleware = store => next => action => {
const nextAction = next(action);
const nextState = (store.getState() as any) as State;
switch (action.type) {
case ActionTypes.UpdateInjectedProviderName:
// tslint:disable-next-line:no-floating-promises
analytics.addEventPropertiesAsync({
injectedProviderName: nextState.injectedProviderName,
});
break;
case ActionTypes.UpdateNetworkId:
// tslint:disable-next-line:no-floating-promises
analytics.addEventPropertiesAsync({
networkId: nextState.networkId,
});
break;
case ActionTypes.UpdateUserAddress:
// tslint:disable-next-line:no-floating-promises
analytics.addUserPropertiesAsync({
ethAddress: nextState.userAddress,
});
break;
case ActionTypes.UpdateUserEtherBalance:
if (nextState.userEtherBalanceInWei) {
// tslint:disable-next-line:no-floating-promises
analytics.addUserPropertiesAsync({
ethBalance: nextState.userEtherBalanceInWei.toString(),
});
}
break;
case ActionTypes.UpdatePortalOnboardingStep:
// tslint:disable-next-line:no-floating-promises
analytics.trackAsync('Update Onboarding Step', {
stepIndex: nextState.portalOnboardingStep,
});
break;
default:
break;
}
return nextAction;
};
|