From eda11cfc08fe6e29dc0ca08a3cca3a24eb9ed5b1 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Thu, 9 Feb 2023 12:57:54 +0100 Subject: [PATCH] Inform that the user that config keys are missing (#880) --- src/PosthogAnalytics.ts | 9 +++++---- src/initializer.tsx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PosthogAnalytics.ts b/src/PosthogAnalytics.ts index 28f50d22..4e91a6d6 100644 --- a/src/PosthogAnalytics.ts +++ b/src/PosthogAnalytics.ts @@ -94,7 +94,7 @@ export class PosthogAnalytics { private static ANALYTICS_EVENT_TYPE = "im.vector.analytics"; // set true during the constructor if posthog config is present, otherwise false - private static internalInstance = null; + private static internalInstance: PosthogAnalytics | null = null; private identificationPromise: Promise; private readonly enabled: boolean = false; @@ -137,6 +137,9 @@ export class PosthogAnalytics { }); this.enabled = true; } else { + logger.info( + "Posthog is not enabled because there is no api key or no host given in the config" + ); this.enabled = false; } this.startListeningToSettingsChanges(); @@ -225,9 +228,7 @@ export class PosthogAnalytics { } public async identifyUser(analyticsIdGenerator: () => string) { - // There might be a better way to get the client here. - - if (this.anonymity == Anonymity.Pseudonymous) { + if (this.anonymity == Anonymity.Pseudonymous && this.enabled) { // Check the user's account_data for an analytics ID to use. Storing the ID in account_data allows // different devices to send the same ID. let analyticsID = await this.getAnalyticsId(); diff --git a/src/initializer.tsx b/src/initializer.tsx index 3de39de5..e10a4ec5 100644 --- a/src/initializer.tsx +++ b/src/initializer.tsx @@ -214,5 +214,5 @@ export class Initializer { resolve(); } } - private initPromise: Promise; + private initPromise: Promise | null; }