gristlabs_grist-core/app/client/lib/telemetry.ts

24 lines
683 B
TypeScript
Raw Normal View History

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);
});
}