Skip to content

Mix and Match ordering and visualization of funnels #5031

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

Merged
merged 6 commits into from
Jul 8, 2021
Merged

Conversation

neilkakkar
Copy link
Contributor

@neilkakkar neilkakkar commented Jul 7, 2021

Changes

Resolves #4988

More details inline. This PR sets up get_step_counts_without_aggregation_query as one step "below" get_step_counts_query such that everything which needs these values can use them as they see fit.

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)

@neilkakkar neilkakkar closed this Jul 7, 2021
@neilkakkar neilkakkar reopened this Jul 7, 2021
@neilkakkar neilkakkar marked this pull request as draft July 7, 2021 15:10
@timgl timgl temporarily deployed to posthog-pr-5031 July 7, 2021 15:11 Inactive
@timgl timgl temporarily deployed to posthog-pr-5031 July 7, 2021 15:38 Inactive
@@ -66,3 +66,55 @@ def _format_single_funnel(self, result, with_breakdown=False):
steps.append(serialized_result)

return steps[::-1] #  reverse

def get_step_counts_without_aggregation_query(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this replaces _get_steps_per_person_query

cols.append(f"if({comparison}, NULL, latest_{i}) as latest_{i}")
return ", ".join(cols)

def build_step_subquery(self, level_index: int, max_steps: int):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

everything that's only used by the ordered funnel moves "up" from base.

@@ -16,7 +16,18 @@ def get_step_counts_query(self):

max_steps = len(self._filter.entities)

partition_select = self.get_partition_cols(1, max_steps)
formatted_query = self.get_step_counts_without_aggregation_query()
Copy link
Contributor Author

@neilkakkar neilkakkar Jul 7, 2021

Choose a reason for hiding this comment

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

this pattern extends well to all types of orderings: First we get the base un-aggregated query, then perform some aggregation on it.

Split it into these two components, because some visualisations need the un-aggregated version (trends), while others need the aggregated version (time to convert, persons)

) GROUP BY person_id
"""

def get_step_counts_without_aggregation_query(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the name kinda implies the "without aggregation" part happens after get_step_counts_query.

Maybe I should rename these to: get_step_counts_query, get_aggregated_step_counts_query.

Hmm, but the existing aggregated version is get_step_counts_query. Maybe this makes the new naming more confusing 😂

class ClickhouseFunnelTimeToConvert(ClickhouseFunnelBase):
def __init__(self, filter: Filter, team: Team, funnel_order_class: Type[ClickhouseFunnelBase]) -> None:
super().__init__(filter, team)
self.funnel_order = funnel_order_class(filter, team)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the composition. Every visualization type expects an ordering type via which it generates its inner query.

@@ -89,7 +89,7 @@ def funnel_order_type(self) -> Optional[FunnelOrderType]:
def funnel_viz_type(self) -> Optional[FunnelVizType]:
funnel_viz_type = self._data.get(FUNNEL_VIZ_TYPE)
if (
not funnel_viz_type is None
funnel_viz_type is None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Twixes wasn't sure if the not was intentional?

I'd expect, since viz_type is new setting, if it's set, should override TRENDS_LINEAR? (and when not set, we wouldn't return TRENDS?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, this would explain #5015 (comment). Looks like I accidentally did not funnel_viz_type and funnel_viz_type is None at once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see it now, that makes sense 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test for this, too. I should've done this when I introduced the change in the first place :$

@neilkakkar neilkakkar marked this pull request as ready for review July 7, 2021 16:00
@Twixes Twixes self-requested a review July 7, 2021 16:41
@neilkakkar neilkakkar requested a review from EDsCODE July 7, 2021 16:47
@Twixes
Copy link
Member

Twixes commented Jul 7, 2021

Warning: some merge conflicts appeared

@timgl timgl temporarily deployed to posthog-pr-5031 July 8, 2021 09:58 Inactive
Copy link
Collaborator

@EDsCODE EDsCODE left a comment

Choose a reason for hiding this comment

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

  1. Might be worth splitting up the files to have more structure/grouping based on hierarchy of how the classes are used
  2. I think a follow up here would be to make the orderings work for funnel breakdown too? Because breakdown is only on the ClickhouseFunnel path right now

otherwise lgtm. great job

@neilkakkar
Copy link
Contributor Author

  1. Makes sense, will do this! (actually can I do it in a separate PR? dependent PRs will get annoying merge conflicts otherwise)
  2. Right, the breakdown PR is in draft: Enable person breakdowns querying for all ordering funnels #5043

@timgl timgl temporarily deployed to posthog-pr-5031 July 8, 2021 16:30 Inactive
@neilkakkar neilkakkar enabled auto-merge (squash) July 8, 2021 16:31
@neilkakkar neilkakkar merged commit 6394988 into master Jul 8, 2021
@neilkakkar neilkakkar deleted the mixnmatch branch July 8, 2021 16: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.

Allow mixing and matching funnel ordering and funnel viz types
4 participants