Skip to content

Commit

Permalink
fix: first time for user with filters (#26858)
Browse files Browse the repository at this point in the history
  • Loading branch information
aspicer authored Dec 12, 2024
1 parent 1379f65 commit a7194a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit a7194a4

Please sign in to comment.