From 35aea314a9c695eae4c03dec007dd4482853ec9a Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:04:43 +0100 Subject: [PATCH] refactor: Renames analytics module (#19) * refactor: Renames analytics module * ci: Reflects changes on labeler --- .github/labeler.yml | 2 +- src/{telemetry.ts => analytics.ts} | 12 ++++++++---- src/extension.ts | 10 +++++----- 3 files changed, 14 insertions(+), 10 deletions(-) rename src/{telemetry.ts => analytics.ts} (73%) diff --git a/.github/labeler.yml b/.github/labeler.yml index 26c23e3..66de71e 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -11,7 +11,7 @@ - src/quack.ts "module: telemetry": - - src/telemetry.ts + - src/analytics.ts "module: util": - src/util/* diff --git a/src/telemetry.ts b/src/analytics.ts similarity index 73% rename from src/telemetry.ts rename to src/analytics.ts index bbf3cf1..2dbdc66 100644 --- a/src/telemetry.ts +++ b/src/analytics.ts @@ -8,7 +8,7 @@ import { PostHog } from "posthog-node"; import * as path from "path"; import * as dotenv from "dotenv"; -let telemetryClient: PostHog | null = null; +let analyticsClient: PostHog | null = null; const telemetryLevel: string = vscode.workspace .getConfiguration("telemetry") .get("telemetryLevel", "all"); @@ -17,11 +17,15 @@ const telemetryLevel: string = vscode.workspace const envPath = path.join(path.dirname(__dirname), ".env"); dotenv.config({ path: envPath }); -if (process.env.POSTHOG_KEY && telemetryLevel === "all") { - telemetryClient = new PostHog(process.env.POSTHOG_KEY, { +if ( + process.env.POSTHOG_KEY && + vscode.env.isTelemetryEnabled && + telemetryLevel === "all" +) { + analyticsClient = new PostHog(process.env.POSTHOG_KEY, { host: process.env.POSTHOG_HOST, }); console.log("Collecting anonymized usage data"); } -export default telemetryClient; +export default analyticsClient; diff --git a/src/extension.ts b/src/extension.ts index 0215d50..d86e7f9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,7 +11,7 @@ import { GuidelineTreeItem, GuidelineTreeProvider, } from "./webviews/guidelineView"; -import telemetryClient from "./telemetry"; +import analyticsClient from "./analytics"; import { getCurrentRepoName, getSelectionText, @@ -131,7 +131,7 @@ export async function activate(context: vscode.ExtensionContext) { } // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-fetch-guidelines", properties: { @@ -257,7 +257,7 @@ export async function activate(context: vscode.ExtensionContext) { // console.log(vscode.window.activeTextEditor?.document.languageId); // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-analyze-code", properties: { @@ -329,7 +329,7 @@ export async function activate(context: vscode.ExtensionContext) { diagnosticCollection.set(getEditor().document.uri, diagnostics); statusBarItem.dispose(); // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-analyze-code-mono", properties: { @@ -420,5 +420,5 @@ export async function activate(context: vscode.ExtensionContext) { } export function deactivate() { - telemetryClient?.shutdownAsync(); + analyticsClient?.shutdownAsync(); }