-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Analytics.ts
65 lines (55 loc) · 1.71 KB
/
Analytics.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Constants from 'expo-constants';
import * as Amplitude from 'expo-analytics-amplitude';
import { TrackingOptions, normalizeTrackingOptions } from './AnalyticsUtils';
import Environment from '../utils/Environment';
let isInitialized = false;
const { manifest } = Constants;
const apiKey = manifest.extra && manifest.extra.amplitudeApiKey;
export const events = {
USER_LOGGED_IN: 'USER_LOGGED_IN',
USER_LOGGED_OUT: 'USER_LOGGED_OUT',
USER_CREATED_ACCOUNT: 'USER_CREATED_ACCOUNT',
USER_RESET_PASSWORD: 'USER_RESET_PASSWORD',
USER_LINKED_SOCIAL: 'USER_LINKED_SOCIAL',
USER_UPDATED_EMAIL: 'USER_UPDATED_EMAIL',
USER_UPDATED_PROFILE: 'USER_UPDATED_PROFILE',
USER_UPDATED_LINKS: 'USER_UPDATED_SOCIAL_LINKS',
USER_UPDATED_PRIVACY: 'USER_UPDATED_PRIVACY',
USER_REMOVED_PROJECT: 'USER_REMOVED_PROJECT',
USER_OPENED_CREATION: 'USER_OPENED_CREATION',
USER_UPDATED_SETTINGS: 'USER_UPDATED_SETTINGS',
};
export function initialize(): void {
if (isInitialized || !Environment.isProduction || !apiKey) {
return;
}
Amplitude.initialize(apiKey);
isInitialized = true;
}
export function identify(id: string | null, options?: TrackingOptions) {
initialize();
const properties = normalizeTrackingOptions(options);
if (id) {
Amplitude.setUserId(id);
if (properties) {
Amplitude.setUserProperties(properties);
}
} else {
Amplitude.clearUserProperties();
}
}
export function track(event: string, options?: TrackingOptions): void {
initialize();
const properties = normalizeTrackingOptions(options);
if (properties) {
Amplitude.logEventWithProperties(event, properties);
} else {
Amplitude.logEvent(event);
}
}
export default {
events,
initialize,
identify,
track,
};