Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
refactor: Renames analytics module (#19)
Browse files Browse the repository at this point in the history
* refactor: Renames analytics module

* ci: Reflects changes on labeler
  • Loading branch information
frgfm authored Dec 12, 2023
1 parent 864317c commit 35aea31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- src/quack.ts

"module: telemetry":
- src/telemetry.ts
- src/analytics.ts

"module: util":
- src/util/*
Expand Down
12 changes: 8 additions & 4 deletions src/telemetry.ts → src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand 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;
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
GuidelineTreeItem,
GuidelineTreeProvider,
} from "./webviews/guidelineView";
import telemetryClient from "./telemetry";
import analyticsClient from "./analytics";
import {
getCurrentRepoName,
getSelectionText,
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function activate(context: vscode.ExtensionContext) {
}

// Telemetry
telemetryClient?.capture({
analyticsClient?.capture({
distinctId: userId,
event: "vscode-fetch-guidelines",
properties: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -420,5 +420,5 @@ export async function activate(context: vscode.ExtensionContext) {
}

export function deactivate() {
telemetryClient?.shutdownAsync();
analyticsClient?.shutdownAsync();
}

0 comments on commit 35aea31

Please sign in to comment.