-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracking-utils.ts
46 lines (40 loc) · 942 Bytes
/
tracking-utils.ts
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 {UserActivity} from '../types';
type Analytics = {
track: (eventName: string, data: Record<string, any>) => void;
page: (url: string) => void;
};
declare let global: {
analytics: Analytics;
};
declare let window: {
analytics: Analytics;
};
export const trackEvent = (
eventName: string,
data: Record<string, any>,
): void => {
if (global?.analytics) {
global.analytics.track(eventName, data);
}
};
export const trackTutorialStepViewed = (
chainId: string,
stepTitle: string,
action: 'next' | 'prev',
) => {
trackEvent(UserActivity.TUTORIAL_STEP_VIEWED, {
protocol: chainId,
stepTitle,
action,
});
};
export const trackStorageCleared = (chainId: string) => {
trackEvent(UserActivity.STORAGE_CLEARED, {
protocol: chainId,
});
};
export const trackPageView = (url: string): void => {
if (typeof window !== 'undefined' && window.analytics) {
window.analytics.page(url);
}
};