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