mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
24 lines
683 B
TypeScript
24 lines
683 B
TypeScript
|
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);
|
||
|
});
|
||
|
}
|