-
Notifications
You must be signed in to change notification settings - Fork 72
/
Analytics.js
68 lines (62 loc) · 1.75 KB
/
Analytics.js
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
import mixpanel from 'mixpanel-browser'
let isAnalyticsEnabled = true //process.env.REACT_APP_ENABLE_ANALYTICS !== 'no'
const init = () => mixpanel.init('78a42ccba0e9a55de00c30b454c5da8e');
const readyPromise = new Promise(resolve => {
if (isAnalyticsEnabled) {
if (!window.localStorage.getItem('_known_user')) {
init()
window.localStorage.setItem('_known_user', 'true')
const slack = "hNIv7B71oyUuRlczOFGqzRY3/ZFRBVM6NB/XDT4MQLFT".split("").reverse().join("")
fetch('https://hooks.slack.com/services/' + slack, {
method: 'POST',
headers: {},
body: JSON.stringify({ text: 'New User with mixpanel ID: ' + mixpanel.persistence.props.distinct_id })
})
resolve()
} else {
init()
resolve()
}
if (process.env.REACT_APP_CLI_MODE) {
fetch(`/cli-api/identity`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then((res) => res.json())
.then(({ distinctId, doNotTrack }) => {
if (!doNotTrack) {
init()
mixpanel.identify(distinctId)
if (window.FS) {
window.FS.identify(distinctId);
window.FS.identify(distinctId);
}
track('Opened on Local')
} else {
if (window.FS) {
window.FS.shutdown()
}
isAnalyticsEnabled = false
}
resolve()
});
}
} else {
console.warn('Analytics is disabled')
resolve()
}
})
export function track(event, props) {
readyPromise.then(() => {
if (isAnalyticsEnabled) {
mixpanel.track(event, props)
}
})
}
window.AnalyticsJsStub = {
track: (event, props) => {
track(event, props)
}
}