forked from SnakeByteDevelopment/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngx-analytics-mixpanel.ts
102 lines (90 loc) · 2.34 KB
/
ngx-analytics-mixpanel.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
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
import { Injectable } from '@angular/core';
import { NgxAnalytics } from 'ngx-analytics';
declare var mixpanel: any;
@Injectable()
export class NgxAnalyticsMixpanel {
constructor(
private ngxAnalytics: NgxAnalytics
) {
this.ngxAnalytics.pageTrack.subscribe((x) => this.pageTrack(x.path));
this.ngxAnalytics.eventTrack.subscribe((x) => this.eventTrack(x.action, x.properties));
this.ngxAnalytics.setUsername.subscribe((x: string) => this.setUsername(x));
this.ngxAnalytics.setUserProperties.subscribe((x) => this.setUserProperties(x));
this.ngxAnalytics.setUserPropertiesOnce.subscribe((x) => this.setUserPropertiesOnce(x));
this.ngxAnalytics.setSuperProperties.subscribe((x) => this.setSuperProperties(x));
this.ngxAnalytics.setSuperPropertiesOnce.subscribe((x) => this.setSuperPropertiesOnce(x));
this.ngxAnalytics.setAlias.subscribe((x) => this.setAlias(x));
}
pageTrack(path: string) {
try {
mixpanel.track('Page Viewed', { page: path });
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
eventTrack(action: string, properties: any) {
try {
mixpanel.track(action, properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setUsername(userId: string) {
try {
mixpanel.identify(userId);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setUserProperties(properties: any) {
try {
mixpanel.people.set(properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setUserPropertiesOnce(properties: any) {
try {
mixpanel.people.set_once(properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setSuperProperties(properties: any) {
try {
mixpanel.register(properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setSuperPropertiesOnce(properties: any) {
try {
mixpanel.register_once(properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
setAlias(alias: any) {
try {
mixpanel.alias(alias);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
}