Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/client/tracking.ts
Views: 687
/*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 * as message from "@cocalc/util/message";78export class TrackingClient {9private client: WebappClient;10private log_error_cache: { [error: string]: number } = {};1112constructor(client: WebappClient) {13this.client = client;14}1516// Send metrics to the hub this client is connected to.17// There is no confirmation or response that this succeeded,18// which is fine, since dropping some metrics is fine.19public send_metrics(metrics: object): void {20this.client.hub_client.send(message.metrics({ metrics }));21}2223public async user_tracking(evt: string, value: object): Promise<void> {24await this.client.async_call({25message: message.user_tracking({ evt, value }),26});27}2829public log_error(error: any): void {30if (typeof error != "string") {31error = JSON.stringify(error);32}33const last = this.log_error_cache[error];34if (last != null && Date.now() - last <= 1000 * 60 * 15) {35return;36}37this.log_error_cache[error] = Date.now();38this.client.call({39message: message.log_client_error({ error }),40});41}4243public async webapp_error(opts: object): Promise<void> {44await this.client.async_call({ message: message.webapp_error(opts) });45}46}474849