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
19.44k stars 1.14k forks source link

Saved filters #20314

Open benjackwhite opened 4 months ago

benjackwhite commented 4 months ago

Is your feature request related to a problem?

Trying to sum up what I think is the right solution for a range of issues: https://github.com/PostHog/posthog/issues/11838 https://github.com/PostHog/posthog/issues/19680 https://github.com/PostHog/posthog/issues/19477

In particular this came up in conversation about whether we need a "sites" concept for Web Analytics (related to this) which I pushed back on.

Describe the solution you'd like

Part 1 - Saved filters

I believe the problem we have is that people are often applying the same sort of filtering again and again in PostHog. We partly solve for this across Events and Persons via Actions and Cohorts (which are essentially Saved Filters for Events and Saved Filters for Persons).

Once saved, you could save filters as "favourites" or something, which would mean that anywhere that the filter applied it would show up automatically as a top level dropdown.

Derive an icon automatically based on the filter or allow them to specify one for easy visible matching.

Screenshot 2024-02-13 at 16 31 51

These are then available anywhere that we would have an "add filter" option - Activity, Persons, Session Replay, Trends filters etc. Likely we would need some way of distinguishing the "target" of a filter so that we only show saved filters that make sense (i.e. we don't show a filter based on events for the persons page)

Part 2 - Dynamic saved filters

Saved filters would allow you to save a common pattern (think filter internal users) that you could apply anywhere easily.

You may however not want to specify a hard coded value, but rather a "selectable" value. For example you might want to have a saved filter that dynamically gives you a dropdown of options based on a query value.

The top use case here I could see is something like Web Analytics "sites" - you specify a query (maybe a hogql query) to get a list of distinct values:

select distinct properties.$host from events where properties.$host like '%posthog.com';
-- or if they want to be super prescriptive and add a special property
select distinct properties.$site from events;

Then you can configure it as a favourite making it easy to select from a dynamic list

Screenshot 2024-02-13 at 16 42 32

With an additional setting we could make it show at the very top level.

Screenshot 2024-02-13 at 16 44 05

Part 3 - Default filters

Like we have an option for defaulting internal user filtering for insights, we could apply the same here either on a page by page basis or just globally. That way you are seeing the data you are looking for faster as you navigate PostHog.

Describe alternatives you've considered

The main proposed alternative is a full on "sites" concept. My main reservations with that are:

  1. It doesn't mean much - what is site if not a saved filter?
  2. It has a bunch of other connotations - I would expect separate sites to have different configurations, tokens etc - this is what projects are sort of. Until we would figure that out it would be best to avoid it
  3. It requires a user to setup extra client side things. If we avoid that need, then it just a very narrow definition of the saved filters concept that I'm proposing in this PR.

Additional context

Internal slack thread that prompted this

Thank you for your feature request – we love each and every one!

joethreepwood commented 4 months ago

I full-on love this. This feels very similar to what I've been proposing around having templates for every product, but with more user customization!

daibhin commented 4 months ago

I really like this too and plays nicely with some of the changes we were recently talking about in Replay land around filtering & playlists.

One thing not mentioned that might be worth considering is whether these saved filters can be combined in any way. Thinking about session replay I'd like users to be able to construct queries like:

Ideally, I'd like not to have to make saved filters like VIPs with errors in sessions. Perhaps it's just a UI level thing where we wouldn't use a select dropdown for replay but curious to know if combinatorial filter groups would be possible?

annikaschmid commented 4 months ago

I like this too! Agree would be very useful for session replay.

In the concept of a filter as described above, is it 1 property = 1 saved filter? Or could one filter also be multiple properties?

Twixes commented 4 months ago

If we did not have Actions and Cohorts I would say this is a no-brainer, but we already have them, and they already are saved filters in essence – as you pointed out @benjackwhite. You can apply actions and cohorts as filters in lots of places. Why is this not something much simpler: a parametric action?

As for the issues linked:

daibhin commented 3 weeks ago

Following up on this as it might be useful context from the replay point of view:

Cohorts are super powerful so I get the pushback on replicating a lot of their functionality elsewhere but Saved filters (that can contain Cohorts) seem like the thing that would make most sense from a Replay perspective.