Skip to content

Commit

Permalink
fix(vscode): fix opt-out event for data collection (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and mrmeku committed Nov 25, 2019
1 parent cb43114 commit 7a2c3ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
28 changes: 19 additions & 9 deletions apps/vscode/src/app/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function getTelemetry() {
return telemetry;
}

const enableTelemetry = 'enableTelemetry';
const configurationSection = VSCodeStorage.configurationSection;
const telemetrySetting = `${configurationSection}.${enableTelemetry}`;

// using shared memory here is a shortcut, this should be an api call
export function initTelemetry(context: ExtensionContext, store: Store) {
telemetry = environment.disableTelemetry
Expand All @@ -25,23 +29,29 @@ export function initTelemetry(context: ExtensionContext, store: Store) {
context.globalState.update('shownTelemetryPrompt', true);
}

const enableTelemetry = 'enableTelemetry';
const configurationSection = VSCodeStorage.configurationSection;
const telemetrySetting = `${configurationSection}.${enableTelemetry}`;

disposer = workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(telemetrySetting)) {
if (store.get(enableTelemetry, true)) {
telemetry.startedTracking();
} else {
telemetry.stoppedTracking();
}
updateTelemetryTracking();
}
});

updateTelemetryTracking();

return telemetry;
}

function updateTelemetryTracking() {
const configuration = workspace.getConfiguration(
VSCodeStorage.configurationSection
);
const enabled = configuration.get('enableTelemetry');
if (enabled === true || typeof enabled === 'undefined') {
telemetry.startedTracking();
} else {
telemetry.stoppedTracking();
}
}

export function teardownTelemetry() {
if (disposer) {
disposer.dispose();
Expand Down
5 changes: 4 additions & 1 deletion libs/server/src/lib/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ export class Telemetry implements TelemetryMessageBuilder {
}

stoppedTracking(): void {
// Record event before disabling data collection.
// Otherwise we won't get the opt-out event.
this.record('StoppedTracking');

this.user.untracked();
this.userStateChanged();
this.record('StoppedTracking');
}

userStateChanged() {
Expand Down

0 comments on commit 7a2c3ea

Please sign in to comment.