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; }