posthog
posthog copied to clipboard
Saved filters
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.
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
With an additional setting we could make it show at the very top level.
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:
- It doesn't mean much - what is site if not a saved filter?
- 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
- 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!
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!
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:
-
VIP customers
whoHad errors in their session
-
New users
whoConverted
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?
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?
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:
- #11838 - this is already saved by the event explorer, event views can be saved as insights; I just closed the issue
- #19680 - as far as I can tell, session replay's equivalent of a dashboard/insight is a playlist, so we can deploy the same UX as with dashboard templates – where customization is already figured out
- #19477 - you can already apply a "saved filter", i.e. a cohort, manually to the persons list; the problem of a default is orthogonal to saved filters
Following up on this as it might be useful context from the replay point of view:
- I strongly think that the concept of saved filters we have in Replay right now with Playlists needs to be split. We should have static playlists to which you can just add recordings, and a separate concept of Segments / Saved filters that you can use to filter recordings.
- Cohorts apply to a given person and don't support Session properties (e.g. first URL) or replay properties (e.g. duration, console logs).
- Unclear to me if there is some technical limitations to adding them or if it's just the case that we haven't gotten around to it.
- If it was possible it still begs the question how that might work e.g. you could add a "has had a session > 10 minutes" to the cohort but that would match recordings based on the person, rather than return the specific sessions.
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.