-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathkeen-flux-logger.js
49 lines (42 loc) · 1.19 KB
/
keen-flux-logger.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
import KeenTracking from 'keen-tracking';
// Record all actions to a single event stream
const EVENT_STREAM_NAME = 'app-actions';
// Omit noisy actions if necessary
const OMITTED_ACTIONS = [
// 'KEYPRESS',
// 'WINDOW_RESIZED'
];
// Define a client instance
const client = new KeenTracking({
projectId: 'PROJECT_ID',
writeKey: 'WRITE_KEY'
});
if (process.env.NODE_ENV !== 'production') {
// Optionally prevent recording in dev mode
Keen.enabled = false;
// Display events in the browser console
client.on('recordEvent', Keen.log);
}
// Track a 'pageview' event and initialize auto-tracking data model
client.initAutoTracking({
recordClicks: false,
recordFormSubmits: false,
recordPageViews: true
});
const fluxLogger = function(state, action) {
const eventBody = {
'action': action,
'state': state
/*
Include additional properties here, or
refine the state data that is recorded
by cherry-picking specific properties
*/
};
// Filter omitted actions by action.type
// ...or whatever you name this property
if (OMITTED_ACTIONS.indexOf(action.type) < 0) {
client.recordEvent(EVENT_STREAM_NAME, eventBody);
}
}
export default fluxLogger;