-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGTag.ts
More file actions
59 lines (51 loc) · 1.86 KB
/
GTag.ts
File metadata and controls
59 lines (51 loc) · 1.86 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
import ReactGA from 'react-ga4';
export default class GTag {
public static initialize() {
GTag.doInit();
setTimeout(() => {
async function doPageView() {
const { urlPathStore } = await import('./store/UrlPathStore');
if (urlPathStore.isGitHubPages()) {
GTag.pageView('Package: Github Pages App');
} else {
const { socketStore } = await import('./store/SocketStore');
const type = await socketStore.emitGetInstallType();
GTag.pageView('Package: ' + type);
}
}
doPageView();
// Initialize gtag once every hour
setInterval(() => {
GTag.doInit();
GTag.pageView('Initializing GTAG every hour');
}, 1000 * 60 * 60);
}, 1000);
}
private static doInit() {
const path = document.location.pathname;
if (path.includes('jsonlogs')) {
ReactGA.initialize('G-K9M5MG60BK');
} else if (path.includes('json-log-viewer') || path.includes('jlogviewer')) {
ReactGA.initialize('G-LXBMLPXTGQ');
} else if (path.includes('mitmproxy')) {
ReactGA.initialize('G-JBBB8K7GRR');
} else {
ReactGA.initialize('G-H1NDQRZW8J');
}
}
public static pageView(title: string) {
setTimeout(() => ReactGA.event('page_view', {
page_title: process.env.REACT_APP_VERSION + ' ' + title
}));
}
public static search(searchTerm: string) {
setTimeout(() => ReactGA.event('search', {
search_term: searchTerm
}));
}
public static exception(description: string, fatal: boolean) {
setTimeout(() => ReactGA.event('exception', {
description, fatal
}));
}
}