Skip to content
Permalink
Browse files

Chore: Use shared instrumentation key in VS Code

Also rename `storage` variables for clarity.
  • Loading branch information
antross authored and molant committed Nov 11, 2019
1 parent 48ce26c commit 3f9aec8a798170c3d14309dffd8bb80834ee2817
Showing with 8 additions and 10 deletions.
  1. +0 −2 packages/extension-vscode/src/server.ts
  2. +8 −8 packages/extension-vscode/src/utils/analytics.ts
@@ -9,7 +9,6 @@ import * as notifications from './utils/notifications';
// Look two-levels up for `package.json` as this will be in `dist/src/` post-build.
const { version } = require('../../package.json');

const instrumentationKey = '8ef2b55b-2ce9-4c33-a09a-2c3ef605c97d';
const defaultProperties = { 'extension-version': version };

const [,, globalStoragePath, telemetryEnabled, everEnabledTelemetryStr] = process.argv;
@@ -65,7 +64,6 @@ connection.listen();
initTelemetry({
defaultProperties,
enabled: telemetryEnabled === 'enabled',
instrumentationKey,
post: (url, data) => {
return new Promise((resolve, reject) => {
const request = https.request(url, { method: 'POST' }, (response) => {
@@ -16,7 +16,7 @@ export type ResultData = {
export type TelemetryState = 'ask' | 'disabled' | 'enabled';

const activityKey = 'webhint-activity';
const config = new Configstore('vscode-webhint');
const configstore = new Configstore('vscode-webhint');

// Remember per-document results for analytics.
const prevProblems = new Map<string, ProblemCountMap>();
@@ -45,25 +45,25 @@ const toTrackedResult = (data: ResultData) => {
* Data includes `last28Days` (e.g. `"1001100110011001100110011001"`)
* and `lastUpdated` (e.g. `"2019-10-04T00:00:00.000Z"`).
*/
const trackActive = (s: Configstore) => {
const trackActive = (storage: Configstore) => {
// Don't count a user as active if telemetry is disabled.
if (!enabled()) {
return;
}

const activity = getUpdatedActivity(s.get(activityKey));
const activity = getUpdatedActivity(storage.get(activityKey));

if (activity) {
s.set(activityKey, activity);
storage.set(activityKey, activity);
trackEvent('vscode-activity', activity);
}
};

const trackOpen = (result: ProblemCountMap, languageId: string, s: Configstore) => {
const trackOpen = (result: ProblemCountMap, languageId: string, storage: Configstore) => {
const status = determineHintStatus({}, result);

trackEvent('vscode-open', { ...status, languageId });
trackActive(s);
trackActive(storage);
};

export const trackOptIn = (telemetryEnabled: TelemetryState, everEnabledTelemetry: boolean) => {
@@ -79,7 +79,7 @@ export const trackClose = (uri: string) => {
lastSaveTimes.delete(uri);
};

export const trackResult = (uri: string, languageId: string, result: ResultData, s = config) => {
export const trackResult = (uri: string, languageId: string, result: ResultData, storage = configstore) => {
const problems = toTrackedResult(result);

languageIds.set(uri, languageId);
@@ -88,7 +88,7 @@ export const trackResult = (uri: string, languageId: string, result: ResultData,
nextProblems.set(uri, problems);
} else {
prevProblems.set(uri, problems);
trackOpen(problems, languageId, s);
trackOpen(problems, languageId, storage);
}
};

0 comments on commit 3f9aec8

Please sign in to comment.
You can’t perform that action at this time.