aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux/analytics_middleware.ts
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-16 02:43:42 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-16 02:43:42 +0800
commit61f227e123218ba76a7fdf7fc2ee89171c2bf16c (patch)
treed821f01c41dd58e03b093a40930748dac51c2148 /packages/instant/src/redux/analytics_middleware.ts
parent20ed4fbbd46f359ca1436b2d3b9d17527c01df54 (diff)
downloaddexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar.gz
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar.bz2
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar.lz
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar.xz
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.tar.zst
dexon-sol-tools-61f227e123218ba76a7fdf7fc2ee89171c2bf16c.zip
feat(instant): Heap middleware and first tracking events
Diffstat (limited to 'packages/instant/src/redux/analytics_middleware.ts')
-rw-r--r--packages/instant/src/redux/analytics_middleware.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/instant/src/redux/analytics_middleware.ts b/packages/instant/src/redux/analytics_middleware.ts
new file mode 100644
index 000000000..8dd674e94
--- /dev/null
+++ b/packages/instant/src/redux/analytics_middleware.ts
@@ -0,0 +1,38 @@
+import { ObjectMap } from '@0x/types';
+import * as _ from 'lodash';
+import { Middleware } from 'redux';
+
+import { analytics } from '../util/analytics';
+
+import { AccountState } from './../types';
+import { Action, ActionTypes } from './actions';
+import { State } from './reducer';
+
+export const analyticsMiddleware: Middleware = store => next => middlewareAction => {
+ const prevState = store.getState() as State;
+ const nextAction = next(middlewareAction) as Action;
+ const nextState = store.getState() as State;
+
+ const curAccount = nextState.providerState.account;
+ const prevAccount = prevState.providerState.account;
+ switch (nextAction.type) {
+ case ActionTypes.SET_ACCOUNT_STATE_READY:
+ if (curAccount.state === AccountState.Ready && !_.isEqual(curAccount, prevAccount)) {
+ const ethAddress = curAccount.address;
+ analytics.addUserProperties({ ethAddress });
+ analytics.track('Wallet - Ready');
+ }
+ break;
+ case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE:
+ if (
+ curAccount.state === AccountState.Ready &&
+ curAccount.ethBalanceInWei &&
+ !_.isEqual(curAccount, prevAccount)
+ ) {
+ const ethBalanceInWei = curAccount.ethBalanceInWei.toString();
+ analytics.addUserProperties({ ethBalanceInWei });
+ }
+ }
+
+ return nextAction;
+};