mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add optional telemetry to grist-core
Summary: Adds support for optional telemetry to grist-core. A new environment variable, GRIST_TELEMETRY_LEVEL, controls the level of telemetry collected. Test Plan: Server and unit tests. Reviewers: paulfitz Reviewed By: paulfitz Subscribers: dsagal, anaisconce Differential Revision: https://phab.getgrist.com/D3880
This commit is contained in:
@@ -197,11 +197,11 @@ function _beaconOpen(userObj: IUserObj|null, options: IBeaconOpenOptions) {
|
||||
|
||||
Beacon('once', 'open', () => logTelemetryEvent('beaconOpen'));
|
||||
Beacon('on', 'article-viewed', (article) => logTelemetryEvent('beaconArticleViewed', {
|
||||
articleId: article!.id,
|
||||
full: {articleId: article!.id},
|
||||
}));
|
||||
Beacon('on', 'email-sent', () => logTelemetryEvent('beaconEmailSent'));
|
||||
Beacon('on', 'search', (search) => logTelemetryEvent('beaconSearch', {
|
||||
searchQuery: search!.query,
|
||||
full: {searchQuery: search!.query},
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import {logError} from 'app/client/models/errors';
|
||||
import {TelemetryEventName} from 'app/common/Telemetry';
|
||||
import {fetchFromHome, pageHasHome} from 'app/common/urlUtils';
|
||||
import {Level, TelemetryContracts, TelemetryEvent, TelemetryMetadataByLevel} from 'app/common/Telemetry';
|
||||
import {fetchFromHome, getGristConfig, pageHasHome} from 'app/common/urlUtils';
|
||||
|
||||
export function logTelemetryEvent(name: TelemetryEventName, metadata?: Record<string, any>) {
|
||||
export function logTelemetryEvent(event: TelemetryEvent, metadata?: TelemetryMetadataByLevel) {
|
||||
if (!pageHasHome()) { return; }
|
||||
|
||||
const {telemetry} = getGristConfig();
|
||||
if (!telemetry) { return; }
|
||||
|
||||
const {telemetryLevel} = telemetry;
|
||||
if (Level[telemetryLevel] < TelemetryContracts[event].minimumTelemetryLevel) { return; }
|
||||
|
||||
fetchFromHome('/api/telemetry', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
event,
|
||||
metadata,
|
||||
}),
|
||||
credentials: 'include',
|
||||
@@ -17,7 +23,7 @@ export function logTelemetryEvent(name: TelemetryEventName, metadata?: Record<st
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
}).catch((e: Error) => {
|
||||
console.warn(`Failed to log telemetry event ${name}`, e);
|
||||
console.warn(`Failed to log telemetry event ${event}`, e);
|
||||
logError(e);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user