PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
21.78k stars 1.3k forks source link

Feature Flags Autocapture #15329

Open neilkakkar opened 1 year ago

neilkakkar commented 1 year ago

We want users to be able to gather insights on feature-flagged features easily, while also making implementation easier.

We're testing whether people like a component that does it all for you, and also whether this kind of instrumentation leads to richer analytics.

There's three components to this feature:

  1. A standard interface which lets us know when a feature is visible / interacted with, so we can easily hook this into recordings / gather richer analytics on how the feature is used.
  2. A React component that implements this interface, for easy setup for people using React.
  3. Some posthog-js helper functions that implement part of this interface.

Essentially, the autocapture happens only inside the react component. However, the posthog-js functions should allow anyone, using any frontend framework, to build their own component.

The interface supports 2 things:

  1. An event representing when the feature is visible: $feature_visible with property: {$feature_flag: <key>}
  2. An event representing when the feature is interacted with: $feature_interaction with property: {$feature_flag: <key>}

with corresponding posthog-js functions: posthog.captureFeatureVisible(<key>) and posthog.captureFeatureInteraction(<key>)

The React component, in addition to the above interface, also supports flag matching, so it can do the above things, and also control when to do them (when the flag is enabled).

Open questions:

  1. How deep do we want to go with $feature_interaction property? Do we want to do what autocapture does, or keep it simple?
  2. Do we need both $feature_visible and $feature_interaction ?
  3. Do we need the posthog-js helpers at all, if the interface is so simple? It's just a capture call.
neilkakkar commented 1 year ago

We'll want to support a person property as well, to make feature flag targeting easier. For example, if I had a property checking whether a person has interacted with a feature or not, I could then use this to target feedback modals specifically to these people.