Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group reamining breakdown values into "Other" for funnels #5538

Merged
merged 7 commits into from
Aug 12, 2021

Conversation

neilkakkar
Copy link
Collaborator

Changes

Resolves #5427

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests
  • Jest frontend tests
  • Cypress end-to-end tests
  • Migrations are safe to run at scale (e.g. PostHog Cloud) – present proof if not obvious
  • New/changed UI is decent on smartphones (viewport width around 360px)

@timgl timgl temporarily deployed to posthog-pr-5538 August 11, 2021 08:57 Inactive
self._filter, first_entity, "count(*)", self._team.pk, limit
)
limit = self._filter.breakdown_limit_or_default
first_entity = next(x for x in self._filter.entities if x.order == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Code issue:

This doesn't work as you'd like:

In [2]: next(iter([]))
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-2-bfed92c5b1cf> in <module>
----> 1 next(iter([]))

StopIteration: 

Given that entities are sorted already entities[0] does the trick

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense! I guess we never hit this earlier because we have a check that entities exist. I'm just going to get rid of the validation error completely!

if self._filter.breakdown_type == "person":
values = get_breakdown_person_prop_values(self._filter, first_entity, "count(*)", self._team.pk, limit)
elif self._filter.breakdown_type == "event":
values = get_breakdown_event_prop_values(self._filter, first_entity, "count(*)", self._team.pk, limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

So what happens if the second entity has a different set of person property values? Is it impossible due to how funnels work?

If so, worth adding a comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean by different set of person property values for second entity? Maybe an example?

If you mean something like: breakdown by X, and second entity has a filter like: X=a, where a is very rare, then earlier, yes, this would mean that drop off is 100%. After this PR, they'd all get grouped into "Other".

Copy link
Contributor

Choose a reason for hiding this comment

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

So entities in this case are things like:

  1. { type: event, value: 'fooevent' }
  2. { type: event, value: 'barevent' }

Let's walk through a scenario
If you break down first with $some_property you get values A, B. If you broke the second with $some_property you would get B and C

Would the table contain A and B only or would C get included as well or is this scenario impossible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Earlier:
If possible, table would contain A, B only.

Now:
if possible, table will contain A, B, Other

Judging possibility:
Hmm, one case where I can imagine this being possible is if second never happened with A value of $some_property and first never happened with C value of $some_property. Unlikely, but possible. It smells of event-dependent values of $some_property though, which doesn't seem right. Like, it implies the user in a single session did first and then second event, but the properties changed in the middle.

The idea with choosing the first event: anything that occurs for the Nth event but not the first event wouldn't make it inside the funnel, since the first event needs to happen ... first.

Copy link
Contributor

Choose a reason for hiding this comment

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

I hope you see now why this needs at minimum a clarifying comment - there's a ton to unpack here.

Why Other not C? 3 values will fall well below the line of 5 or 10. :)

Given you can break down by event properties, it's more than possible that the second step in the funnel has a different set of properties than the first. It's kind of how event properties work - they don't stick around for all events for a session.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I see what you mean now, "Why other not C" is a very valid question!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh wait, actually, in the funnel, all event properties are constrained to the first in line, so even with other grouping, the breakdown values would only be A, B, no other. (will write a test to confirm). My bad here, I got confused: the query never does anything with props for events following the first one.

I'll chalk this one up to a funnel limitation. With event props, makes sense to extend this like you say.

@EDsCODE can confirm?

@timgl timgl temporarily deployed to posthog-pr-5538 August 12, 2021 09:16 Inactive
@neilkakkar neilkakkar marked this pull request as ready for review August 12, 2021 09:21
@timgl timgl temporarily deployed to posthog-pr-5538 August 12, 2021 09:43 Inactive
@timgl timgl temporarily deployed to posthog-pr-5538 August 12, 2021 09:47 Inactive
@@ -397,30 +397,28 @@ def _get_cohort_breakdown_join(self) -> str:

def _get_breakdown_conditions(self) -> str:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this pattern is turning out to be a bit icky, where this function modifies state (self.params) and returns empty string.

Will leave refactoring to a follow up PR - it might make sense to do it for the rest of the functions like this one.

@timgl timgl temporarily deployed to posthog-pr-5538 August 12, 2021 11:33 Inactive
@neilkakkar neilkakkar enabled auto-merge (squash) August 12, 2021 13:19
@neilkakkar neilkakkar merged commit a245c15 into master Aug 12, 2021
@neilkakkar neilkakkar deleted the breakdown_grouping branch August 12, 2021 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain breakdown quirks in the UI for Funnels
3 participants