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

Add support for Posthog Analytics under a labs flag #6495

Merged
merged 65 commits into from
Aug 2, 2021

Conversation

novocaine
Copy link
Contributor

@novocaine novocaine commented Jul 28, 2021

element-hq/element-web#18063

Add experimental support for Posthog analytics. The aim of these analytics is to understand better how people are using Element Web to improve the overall user experience; Element would self-host its own Posthog instance.

We are trialling the use of Posthog as a replacement for Matomo. This integration supersedes a previous experiment with Count.ly (#5365) which was unsuccessful. Count.ly and Matomo code will be removed in follow up PRs if we move forward with Posthog.

Support is activated via a labs flag feature_pseudonymousAnalyticsOptIn. Configuration is via new config keys posthog.projectApiKey and posthog.apiHost which are passed to posthog.init.

See comments in PosthogAnalytics.js for anonymity behaviour.

To roll out support for this approach, we will need to re-prompt users to opt in to Posthog tracking, as the tracking is slightly different to previously - we will be asking to pseudonymise matrix identifiers rather than redacting them completely.

(This went down a few rabbit holes, so apologies, not a lot of value in going through individual commits!)

* Make it an error to call it before its initialised, and separately track whether its been enabled
* Use anonmity enum in the public interface
* Properly await upstream calls
* Fix accidental test fixture cross-reliance
* Redact and pass the redacted url as a property. redactedCurrentLocation might have issues with concurrent events
* Remove DNT code and rely on posthog
We'd like to manually review each posthog change to avoid unanticipated tracking leakages;
each upgrade should include reviewing the data coming in on events
IEvent.properties is a placeholder that needs to be overriden by extenders for type validation to take place.

IWelcomeScreenLoad should have had properties declared for it. Because it didn't, a faulty call using it was possible.
…finition file

Posthog's type definitions refer to types in transitive dependencies we don't want to include.

Clone posthog.d.ts locally, remove the offending types from it, and provide an overriding mapping in tsconfig.

If this proves annoying to maintain, posthog.d.ts could just be an empty file.
tsconfig.json Show resolved Hide resolved
src/components/views/auth/Welcome.tsx Outdated Show resolved Hide resolved
src/PosthogAnalytics.ts Show resolved Hide resolved
@novocaine novocaine requested a review from a team July 30, 2021 07:59
Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise it looks reasonable to me, but I'm a bit unsure on how the opt-in/out behaviour is meant to work.

src/PosthogAnalytics.ts Outdated Show resolved Hide resolved
src/PosthogAnalytics.ts Outdated Show resolved Hide resolved
James Salter and others added 3 commits August 2, 2021 11:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants