-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathactionLogger.ts
More file actions
72 lines (63 loc) · 1.85 KB
/
actionLogger.ts
File metadata and controls
72 lines (63 loc) · 1.85 KB
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
import { trackMatomoEvent } from "./useMatomo";
/**
* Matomo logging function for events that depend purely on the state change.
*
* Events that are triggered by a user click are logged right in the components.
*
* @param {object} action redux action object
* @param {object} state redux state object
*/
const logAction = (action: any, state: any) => {
switch (action.type) {
case "INITIALIZE":
return trackMatomoEvent("Headstart", "Load");
// case "RESIZE":
// return trackMatomoEvent("Headstart", "Resize window");
case "SEARCH":
// TODO trackSiteSearch ?
// https://developer.matomo.org/guides/tracking-javascript-guide
return trackMatomoEvent("List controls", "Search", "Search box");
case "ZOOM_IN":
return trackZoomIn(action, state);
case "ZOOM_OUT":
return trackZoomOut(action);
case "SELECT_PAPER":
return trackSelectPaper(action);
case "DESELECT_PAPER":
return trackDeselectPaper(action);
default:
return;
}
};
export default logAction;
const trackZoomIn = (action: any, state: any) => {
if (!action.isFromBackButton) {
return;
}
if (action.selectedPaperData) {
return trackSelectPaper(action);
}
if (state.selectedPaper) {
return trackDeselectPaper(action);
}
trackMatomoEvent("Browser buttons", "Zoom in", "Back/Forward button");
};
const trackZoomOut = (action: any) => {
if (action.isFromBackButton) {
trackMatomoEvent("Browser buttons", "Zoom out", "Back/Forward button");
}
};
const trackSelectPaper = (action: any) => {
if (action.isFromBackButton) {
trackMatomoEvent("Browser buttons", "Select paper", "Back/Forward button");
}
};
const trackDeselectPaper = (action: any) => {
if (action.isFromBackButton) {
trackMatomoEvent(
"Browser buttons",
"Deselect paper",
"Back/Forward button"
);
}
};