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

fix: first time for user with filters #26858

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion posthog/hogql_queries/insights/funnels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ def _build_step_query(
first_time_filter = parse_expr("e.uuid IN {subquery}", placeholders={"subquery": subquery})
return ast.And(exprs=[*filters, first_time_filter])
elif entity.math == FunnelMathType.FIRST_TIME_FOR_USER_WITH_FILTERS:
subquery = FirstTimeForUserAggregationQuery(self.context, ast.Constant(value=1), filter_expr).to_query()
subquery = FirstTimeForUserAggregationQuery(
self.context, ast.Constant(value=1), ast.And(exprs=filters)
).to_query()
first_time_filter = parse_expr("e.uuid IN {subquery}", placeholders={"subquery": subquery})
return ast.And(exprs=[*filters, first_time_filter])
elif len(filters) > 1:
Expand Down
14 changes: 14 additions & 0 deletions posthog/hogql_queries/insights/funnels/test/test_funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4429,6 +4429,20 @@ def test_first_time_for_user_funnel_person_properties(self):
# classic and udf funnels handle no events differently
assert len(results) == 0 or results[0]["count"] == 0

_create_event(
team=self.team,
event="event2",
distinct_id="user_1",
timestamp="2024-03-19T13:00:00Z",
properties={"property": "woah"},
)
query.series[0].math = FunnelMathType.FIRST_TIME_FOR_USER_WITH_FILTERS
assert query.dateRange is not None
query.dateRange.date_from = "2024-03-19"
results = FunnelsQueryRunner(query=query, team=self.team).calculate().results
self.assertEqual(results[0]["count"], 1)
self.assertEqual(results[1]["count"], 1)

def test_funnel_personless_events_are_supported(self):
user_id = uuid.uuid4()
_create_event(
Expand Down
Loading