-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
109 lines (91 loc) · 2.31 KB
/
example.ts
File metadata and controls
109 lines (91 loc) · 2.31 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Example file showing which Mixpanel methods we actually use
* The usage-tracker will scan this to determine what to keep
*/
import mixpanel from 'mixpanel-browser';
// Initialize Mixpanel
export function initAnalytics() {
mixpanel.init('YOUR_TOKEN', {
debug: false,
track_pageview: true,
persistence: 'localStorage'
});
}
// Track events
export function trackEvent(eventName: string, properties?: Record<string, any>) {
mixpanel.track(eventName, properties);
}
// Identify users
export function identifyUser(userId: string) {
mixpanel.identify(userId);
}
// Set user properties
export function setUserProperties(properties: Record<string, any>) {
mixpanel.people.set(properties);
}
// Track revenue
export function trackPurchase(amount: number, properties?: Record<string, any>) {
mixpanel.track('Purchase', {
amount,
...properties
});
mixpanel.people.track_charge(amount, properties);
}
// Reset on logout
export function logout() {
mixpanel.reset();
}
// Register super properties (persist across all events)
export function setSuperProperties(properties: Record<string, any>) {
mixpanel.register(properties);
}
// Time events
export function startTimer(eventName: string) {
mixpanel.time_event(eventName);
}
// Increment user properties
export function incrementUserProperty(property: string, value: number = 1) {
mixpanel.people.increment(property, value);
}
// Set once (only if not already set)
export function setUserPropertyOnce(properties: Record<string, any>) {
mixpanel.people.set_once(properties);
}
// Get distinct ID
export function getUserId(): string {
return mixpanel.get_distinct_id();
}
// Opt out of tracking
export function optOut() {
mixpanel.opt_out_tracking();
}
// Opt back in
export function optIn() {
mixpanel.opt_in_tracking();
}
// Check if opted out
export function isOptedOut(): boolean {
return mixpanel.has_opted_out_tracking();
}
// Get property
export function getProperty(propertyName: string): any {
return mixpanel.get_property(propertyName);
}
/**
* Methods we're using:
* - init
* - track
* - identify
* - reset
* - register
* - time_event
* - get_distinct_id
* - get_property
* - opt_out_tracking
* - opt_in_tracking
* - has_opted_out_tracking
* - people.set
* - people.set_once
* - people.increment
* - people.track_charge
*/