-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.ts
More file actions
39 lines (37 loc) · 1.23 KB
/
analytics.ts
File metadata and controls
39 lines (37 loc) · 1.23 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
import { Mixpanel } from "mixpanel-react-native";
import analytics from "@react-native-firebase/analytics";
const mixpanel = new Mixpanel(process.env.EXPO_PUBLIC_MIXPANEL_TOKEN ?? "", true);
mixpanel.init();
mixpanel.setLoggingEnabled(true);
export default class Analytics {
static debug = {
enable: false,
logScreenView: false,
};
static track = (event: string, properties?: Record<string, any>) => {
mixpanel.track(event, properties);
analytics().logEvent(event, properties);
if (Analytics.debug.enable) {
if (Analytics.debug.logScreenView || event !== "screen_view") {
if (properties) console.log("Analytics.track", event, "\n", properties);
else console.log("Analytics.track", event);
}
mixpanel.flush();
}
};
static identify = (id: string) => {
mixpanel.identify(id);
analytics().setUserId(id);
};
static setUserProperties = (properties: Record<string, any>) => {
mixpanel.getPeople().set(properties);
// analytics().setUserProperties(properties);
};
static setSuperProperties = (properties: Record<string, any>) => {
mixpanel.registerSuperProperties(properties);
};
static reset = () => {
mixpanel.reset();
analytics().resetAnalyticsData();
};
}