This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
/
analytics.saga.js
106 lines (98 loc) · 2.89 KB
/
analytics.saga.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// @flow
/**
* This saga is responsible for the bulk of our tracking, by listening for
* dispatched actions and firing off log events to our analytics provider.
*
* It is not the exclusive source of track events; React components can fire
* them as well. For example, `App.js` fires a `load-application` event on
* mount.
*
* The goal of our analytics is to help us understand how people are using
* Guppy so that we can make it better for them. Guppy is not a money-making
* operation, so we aren't interested in data-mining or collecting any
* personally-identifiable information. We don't collect information about,
* for example, what people name their projects, because that doesn't teach
* us anything about how we can make Guppy better.
*/
import { call, takeEvery } from 'redux-saga/effects';
import logger from '../services/analytics.service';
import {
ADD_PROJECT,
IMPORT_EXISTING_PROJECT_FINISH,
SELECT_PROJECT,
LAUNCH_DEV_SERVER,
RUN_TASK,
CLEAR_CONSOLE,
ADD_DEPENDENCY,
UPDATE_DEPENDENCY,
DELETE_DEPENDENCY,
FINISH_DELETING_PROJECT,
} from '../actions';
import type { Action } from 'redux';
import type { Saga } from 'redux-saga';
import type { EventType } from '../services/analytics.service';
type LoggableAction = {
name: EventType,
getMetadata: (payload: Object) => Object,
};
type LoggableActionsMap = {
[actionType: string]: LoggableAction,
};
const loggableActions: LoggableActionsMap = {
[ADD_PROJECT]: {
name: 'create-project',
getMetadata: payload => ({ type: payload.projectType }),
},
[IMPORT_EXISTING_PROJECT_FINISH]: {
name: 'import-project',
getMetadata: payload => ({ type: payload.projectType }),
},
[SELECT_PROJECT]: {
name: 'select-project',
getMetadata: payload => ({}),
},
[LAUNCH_DEV_SERVER]: {
name: 'launch-dev-server',
getMetadata: payload => ({}),
},
[RUN_TASK]: {
name: 'run-task',
getMetadata: payload => ({ name: payload.task.name }),
},
[CLEAR_CONSOLE]: {
name: 'clear-console',
getMetadata: payload => ({}),
},
[ADD_DEPENDENCY]: {
name: 'add-dependency',
getMetadata: payload => ({
dependencyName: payload.dependencyName,
}),
},
[UPDATE_DEPENDENCY]: {
name: 'update-dependency',
getMetadata: payload => ({
dependencyName: payload.dependencyName,
}),
},
[DELETE_DEPENDENCY]: {
name: 'delete-dependency',
getMetadata: payload => ({
dependencyName: payload.dependencyName,
}),
},
[FINISH_DELETING_PROJECT]: {
name: 'delete-project',
getMetadata: payload => ({}),
},
};
export function* handleAction({ type, ...payload }: Action): Saga<void> {
if (loggableActions[type]) {
const { name, getMetadata } = loggableActions[type];
const metadata = getMetadata(payload);
yield call(logger.logEvent, name, metadata);
}
}
export default function* rootSaga(): Saga<void> {
yield takeEvery('*', handleAction);
}