Skip to content

Commit

Permalink
fix(web-analytics): Fix more instances where count() should have been…
Browse files Browse the repository at this point in the history
… uniq() (#24081)
  • Loading branch information
robbie-c authored Jul 30, 2024
1 parent 33b664e commit fb8219d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions posthog/hogql_queries/web_analytics/stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def to_path_scroll_bounce_query(self) -> ast.SelectQuery:
FROM (
SELECT
breakdown_value,
count(person_id) AS visitors,
uniq(person_id) AS visitors,
sum(filtered_pageview_count) AS views
FROM (
SELECT
Expand Down Expand Up @@ -301,7 +301,7 @@ def to_path_bounce_query(self) -> ast.SelectQuery:
FROM (
SELECT
breakdown_value,
count(person_id) AS visitors,
uniq(person_id) AS visitors,
sum(filtered_pageview_count) AS views
FROM (
SELECT
Expand Down
33 changes: 21 additions & 12 deletions posthog/hogql_queries/web_analytics/test/test_web_stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,36 +909,45 @@ def test_same_user_multiple_sessions(self):
team=self.team,
event="$pageview",
distinct_id=d1,
timestamp="2024-06-26",
timestamp="2024-07-30",
properties={"$session_id": s1, "utm_source": "google", "$pathname": "/path"},
)
_create_event(
team=self.team,
event="$pageview",
distinct_id=d1,
timestamp="2024-06-26",
timestamp="2024-07-30",
properties={"$session_id": s2, "utm_source": "google", "$pathname": "/path"},
)

# Try this with a query that uses session properties
results_session = self._run_web_stats_table_query(
"all",
"2024-06-27",
"2024-07-31",
breakdown_by=WebStatsBreakdown.INITIAL_UTM_SOURCE,
).results
self.assertEqual(
[["google", 1, 2]],
results_session,
)
assert [["google", 1, 2]] == results_session

# Try this with a query that uses event properties
results_event = self._run_web_stats_table_query(
"all",
"2024-06-27",
"2024-07-31",
breakdown_by=WebStatsBreakdown.PAGE,
).results
assert [["/path", 1, 2]] == results_event

self.assertEqual(
[["/path", 1, 2]],
results_event,
)
# Try this with a query using the bounce rate
results_event = self._run_web_stats_table_query(
"all", "2024-07-31", breakdown_by=WebStatsBreakdown.PAGE, include_bounce_rate=True
).results
assert [["/path", 1, 2, None]] == results_event

# Try this with a query using the scroll depth
results_event = self._run_web_stats_table_query(
"all",
"2024-07-31",
breakdown_by=WebStatsBreakdown.PAGE,
include_bounce_rate=True,
include_scroll_depth=True,
).results
assert [["/path", 1, 2, None, None, None]] == results_event

0 comments on commit fb8219d

Please sign in to comment.