mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add telemetry
Test Plan: Server tests. Reviewers: jarek Differential Revision: https://phab.getgrist.com/D3818
This commit is contained in:
23
app/client/lib/telemetry.ts
Normal file
23
app/client/lib/telemetry.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {logError} from 'app/client/models/errors';
|
||||
import {TelemetryEventName} from 'app/common/Telemetry';
|
||||
import {fetchFromHome, pageHasHome} from 'app/common/urlUtils';
|
||||
|
||||
export async function logTelemetryEvent(name: TelemetryEventName, metadata?: Record<string, any>) {
|
||||
if (!pageHasHome()) { return; }
|
||||
|
||||
await fetchFromHome('/api/telemetry', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
metadata,
|
||||
}),
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
}).catch((e: Error) => {
|
||||
console.warn(`Failed to log telemetry event ${name}`, e);
|
||||
logError(e);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user