-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.ts
More file actions
63 lines (51 loc) · 1.66 KB
/
analytics.ts
File metadata and controls
63 lines (51 loc) · 1.66 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
import httpClient from './httpClient';
class Analytics {
public sendEvent(eventName: string, eventID:string, errorMessage?: string, diagramType?:string, userLoginState: boolean = true) {
const analyticsID = getAnalyticsID();
const pluginID= "google-docs-plugin";
const pluginSource = 'googledocs';
const payload = {
analyticsID,
pluginID,
eventName,
eventID,
userLoginState,
pluginSource,
errorMessage,
diagramType
};
httpClient.post('/rest-api/plugins/pulse', payload).catch(error => {
if (error.code !== 'ERR_NETWORK') {
console.error('Failed to send analytics event:', error);
}
});
}
public trackLogin() {
this.sendEvent('Google Docs Plugin Logged In','GOOGLE_DOCS_PLUGIN_LOGIN');
}
public trackLogout() {
this.sendEvent('Google Docs Logged Out','GOOGLE_DOCS_PLUGIN_LOGOUT', undefined, undefined, false);
}
public trackBrowseDiagram() {
this.sendEvent('Google Docs Browse Diagram','GOOGLE_DOCS_PLUGIN_BROWSE_DIAGRAM');
}
public trackNewDiagram() {
this.sendEvent('Google Docs New Diagram', 'GOOGLE_DOCS_PLUGIN_NEW_DIAGRAM');
}
public trackEditDiagram() {
this.sendEvent('Google Docs Edit Diagram', 'GOOGLE_DOCS_PLUGIN_EDIT_DIAGRAM');
}
public trackUpdateAllDiagrams() {
this.sendEvent('Google Docs Update All Diagrams', 'GOOGLE_DOCS_PLUGIN_UPDATE_ALL_DIAGRAMS');
}
}
function getAnalyticsID() {
const STORAGE_KEY = 'MERMAIDCHART_ANALYTICS_ID';
let id = localStorage.getItem(STORAGE_KEY);
if (!id) {
id = crypto.randomUUID();
localStorage.setItem(STORAGE_KEY, id);
}
return id;
}
export default new Analytics();