Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/client/tracking.ts
1503 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { WebappClient } from "./client";
7
import { redux } from "@cocalc/frontend/app-framework";
8
9
export class TrackingClient {
10
private client: WebappClient;
11
private log_error_cache: { [error: string]: number } = {};
12
private userTrackingEnabled?: string;
13
14
constructor(client: WebappClient) {
15
this.client = client;
16
}
17
18
user_tracking = async (event: string, value: object): Promise<void> => {
19
if (this.userTrackingEnabled == null) {
20
this.userTrackingEnabled = redux
21
.getStore("customize")
22
?.get("user_tracking");
23
}
24
if (this.userTrackingEnabled == "yes") {
25
await this.client.conat_client.hub.system.userTracking({ event, value });
26
}
27
};
28
29
log_error = (error: any): void => {
30
if (typeof error != "string") {
31
error = JSON.stringify(error);
32
}
33
const last = this.log_error_cache[error];
34
if (last != null && Date.now() - last <= 1000 * 60 * 15) {
35
return;
36
}
37
this.log_error_cache[error] = Date.now();
38
(async () => {
39
try {
40
await this.client.conat_client.hub.system.logClientError({
41
event: "error",
42
error,
43
});
44
} catch (err) {
45
console.log(`WARNING -- issue reporting error -- ${err}`);
46
}
47
})();
48
};
49
50
webapp_error = async (opts: object): Promise<void> => {
51
await this.client.conat_client.hub.system.webappError(opts);
52
};
53
}
54
55