From f27ecd0f7cbcd6907d5b84c87695fb9259d1ee4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=BE=C3=B3r=20Magn=C3=BAsson?= Date: Fri, 14 Feb 2020 10:33:38 +0100 Subject: [PATCH] chore(analytics): add GARDEN_DISABLE_ANALYTICS env var --- .circleci/config.yml | 2 ++ CONTRIBUTING.md | 10 ++++++++++ garden-service/src/analytics/analytics.ts | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 353a0aed9b..e8dbd149bc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,6 +14,7 @@ orbs: - image: circleci/node:12 environment: GARDEN_DISABLE_VERSION_CHECK: "true" + GARDEN_DISABLE_ANALYTICS: "true" GARDEN_TASK_CONCURRENCY_LIMIT: "10" resource_class: large @@ -335,6 +336,7 @@ jobs: - image: gardendev/garden-gcloud:${CIRCLE_SHA1} environment: GARDEN_DISABLE_VERSION_CHECK: "true" + GARDEN_DISABLE_ANALYTICS: "true" GARDEN_TASK_CONCURRENCY_LIMIT: "10" steps: # Need to checkout to run example project diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 77b9187d92..3dc04d55e5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,6 +178,16 @@ Before pushing, we automatically run the `check-all` script from above, as well git push origin --no-verify ``` +### Environment Variables + +You should set the following environment variables when developing on Garden: + +```sh +GARDEN_DISABLE_ANALYTICS=true +GARDEN_DISABLE_VERSION_CHECK=true +ANALYTICS_DEV=true +``` + ## CI We use [Circle CI](https://circleci.com) for integration and end to end testing. Sometimes diff --git a/garden-service/src/analytics/analytics.ts b/garden-service/src/analytics/analytics.ts index dad889255c..b8310f12cc 100644 --- a/garden-service/src/analytics/analytics.ts +++ b/garden-service/src/analytics/analytics.ts @@ -247,7 +247,10 @@ export class AnalyticsHandler { /** * Used internally to check if a users has opted-in or not. */ - private hasOptedIn(): boolean { + private analyticsEnabled(): boolean { + if (process.env.GARDEN_DISABLE_ANALYTICS === "true") { + return false + } return this.globalConfig.optedIn || false } @@ -310,7 +313,7 @@ export class AnalyticsHandler { * @memberof AnalyticsHandler */ private async track(event: AnalyticsEvent) { - if (this.segment && this.hasOptedIn()) { + if (this.segment && this.analyticsEnabled()) { const segmentEvent: SegmentEvent = { userId: this.globalConfig.userId || "unknown", event: event.type,