forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixpanel.ts
More file actions
58 lines (42 loc) · 1.21 KB
/
Copy pathmixpanel.ts
File metadata and controls
58 lines (42 loc) · 1.21 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
import mixpanel from 'mixpanel-browser';
const MIXPANEL_TOKEN = process.env.NEXT_PUBLIC_MIXPANEL_TOKEN;
let isInitialized = false;
export const MixpanelManager = {
init() {
if (isInitialized || !MIXPANEL_TOKEN) {
return;
}
mixpanel.init(MIXPANEL_TOKEN, {
track_pageview: false,
persistence: 'localStorage',
});
isInitialized = true;
},
identify(userId: string, properties?: { name?: string; email?: string }) {
if (!isInitialized) return;
mixpanel.identify(userId);
if (properties) {
const userProps: Record<string, string> = {
Platform: 'web',
};
if (properties.name) userProps['$name'] = properties.name;
if (properties.email) userProps['$email'] = properties.email;
mixpanel.people.set(userProps);
}
},
track(event: string, properties?: Record<string, unknown>) {
if (!isInitialized) return;
mixpanel.track(event, properties);
},
pageView(pageName: string) {
this.track(`${pageName} Page Viewed`);
},
reset() {
if (!isInitialized) return;
mixpanel.reset();
},
setUserProperty(key: string, value: unknown) {
if (!isInitialized) return;
mixpanel.people.set({ [key]: value });
},
};