Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(web-analytics): keep conversion goal queries off the sessions join (#102328)

Javier Bahamondes32e53279383f
diff --git a/docs/internal/web-analytics-query-serving.md b/docs/internal/web-analytics-query-serving.md
index aada1f80104b..34a9308528ae 100644
--- a/docs/internal/web-analytics-query-serving.md
+++ b/docs/internal/web-analytics-query-serving.md
@@ -53,11 +53,15 @@ request
[4] No-join fast path (unfiltered queries)
│ no property filters, no conversion goal, no session-table fields;
│ WEB_ANALYTICS_NO_JOIN_TEAM_IDS + rollout % (100% on Cloud)
+ │ (stats table: any simple or first-pageview breakdown without bounce
+ │ rate or session fields, filters and conversion goals included)
│ needs session fields with filters
▼
[5] Full events↔sessions join (unconditional fallback)
```
+**Conversion goals on the overview** run ahead of this ladder as two independent reads: the goal-less overview (which climbs the ladder above for visitors) plus a scan of goal events only (`web_overview_conversion_goal_query`). The joined shape grouped every pageview session in range to count the goal, so its memory scaled with traffic; the split scales with conversions. Visitors therefore equal the goal-less visitors card, and a session with a goal event but no pageview or screenview no longer counts as a visitor. Legacy sessions v1 and queries with session or cohort filters keep the joined shape.
+
**The one-way rule (#72959):** user-facing reads never build precompute buckets inline — `run_inserts` is true only for background-warming requests.
A miss costs one live-path serve; the background warm makes the next identical request a bucket hit.
The dashboard "enqueues precompute" as a side effect; it never waits on it.
@@ -66,13 +70,14 @@ The dashboard "enqueues precompute" as a side effect; it never waits on it.
### WebOverviewQuery (`web_overview.py`)
-| # | Strategy | Conditions | Tag |
-| --- | -------------------------- | -------------------------------------------------------------------- | ----------------------------------- |
-| 1 | Lazy precompute | Shared gate only — overview has no extra shape restrictions | `web_overview_lazy_query` |
-| 2 | Preaggregated (deprecated) | Modifier on + no conversion goal | `web_overview_preaggregated_query` |
-| 3 | Session-id-set | Filtered + allowlisted + preflight passes (sets `sessionIdPushdown`) | `web_overview_session_id_set_query` |
-| 4 | No-join | Unfiltered, no conversion goal | `web_overview_no_join_query` |
-| 5 | Full join | Fallback | `web_overview_query` |
+| # | Strategy | Conditions | Tag |
+| --- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
+| 0 | Conversion-goal split | Conversion goal + sessions v2/v3 + events-evaluable filters; visitors from the goal-less dispatch below, conversions from goal events | `web_overview_conversion_goal_query` (+ visitors' tag) |
+| 1 | Lazy precompute | Shared gate only — overview has no extra shape restrictions | `web_overview_lazy_query` |
+| 2 | Preaggregated (deprecated) | Modifier on + no conversion goal | `web_overview_preaggregated_query` |
+| 3 | Session-id-set | Filtered + allowlisted + preflight passes (sets `sessionIdPushdown`) | `web_overview_session_id_set_query` |
+| 4 | No-join | Unfiltered, no conversion goal | `web_overview_no_join_query` |
+| 5 | Full join | Fallback (conversion goals with legacy sessions v1, session filters, or cohort filters land here) | `web_overview_query` |
### WebStatsTableQuery (`stats_table.py`) — three lazy families, tried in order
@@ -83,7 +88,7 @@ The dashboard "enqueues precompute" as a side effect; it never waits on it.
| 3 | Simple-breakdown lazy | ~18 supported breakdowns (DeviceType, Browser, OS, Country, Region, City, Viewport, Timezone, Language, ExitPage, InitialChannelType, InitialReferringDomain/URL, InitialUTM\_\*); rejects bounce rate, avg time, scroll depth | `web_stats_lazy_query` |
| 4 | Preaggregated (deprecated) | Modifier on + no avg-time-on-page + no conversion goal | `stats_table_preaggregated*` |
| 5 | Session-id-set | Page breakdown ± avg time, filtered + allowlisted + preflight | `stats_table_session_id_set_path_bounce[_and_avg_time]` |
-| 6 | No-join | Unfiltered: path-bounce, path-bounce+avg-time, or simple breakdown without session fields | `stats_table_no_join_*` |
+| 6 | No-join | Unfiltered path-bounce and path-bounce+avg-time; any simple or first-pageview breakdown without bounce rate or session fields (filters and conversion goals ride the single events scan) | `stats_table_no_join_*` |
| 7 | Full join | Fallback per shape | `stats_table_path_bounce`, `stats_table_entry_bounce`, `stats_table_channel_type`, `stats_table_simple_breakdown`, … |
### Traffic metrics alongside conversion goals
@@ -159,13 +164,13 @@ Four writers keep buckets warm; user reads only ever consume.
Suffix conventions: `*_lazy_query` = bucket read (served from precompute), `*_lazy_insert` = bucket build (background only), `*_preflight` = selectivity probe.
-| Family | Precompute | Live tags |
-| --------------- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| Overview | `web_overview_lazy_query/insert`, `web_overview_preaggregated_query` | `web_overview_no_join_query`, `web_overview_session_id_set_query` (+`_preflight`), `web_overview_query` |
-| Stats table | `web_stats_paths_lazy_*`, `web_stats_frustration_lazy_*`, `web_stats_lazy_*`, `stats_table_preaggregated*` | `stats_table_no_join_*`, `stats_table_session_id_set_*` (+`_preflight`), `stats_table_path_bounce[_and_avg_time]`, `stats_table_entry_bounce`, `stats_table_channel_type`, `stats_table_frustration_metrics`, `stats_table_simple_breakdown` |
-| Goals | `web_goals_lazy_query/insert` | `web_goals_query` |
-| Vitals | `web_vitals_paths_lazy_query/insert` | `web_vitals_path_breakdown_query` |
-| External clicks | — | `external_clicks_query` |
+| Family | Precompute | Live tags |
+| --------------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Overview | `web_overview_lazy_query/insert`, `web_overview_preaggregated_query` | `web_overview_conversion_goal_query`, `web_overview_no_join_query`, `web_overview_session_id_set_query` (+`_preflight`), `web_overview_query` |
+| Stats table | `web_stats_paths_lazy_*`, `web_stats_frustration_lazy_*`, `web_stats_lazy_*`, `stats_table_preaggregated*` | `stats_table_no_join_*` (incl. `stats_table_no_join_first_pageview_attribution`), `stats_table_session_id_set_*` (+`_preflight`), `stats_table_path_bounce[_and_avg_time]`, `stats_table_entry_bounce`, `stats_table_channel_type`, `stats_table_first_pageview_attribution`, `stats_table_frustration_metrics`, `stats_table_simple_breakdown` |
+| Goals | `web_goals_lazy_query/insert` | `web_goals_query` |
+| Vitals | `web_vitals_paths_lazy_query/insert` | `web_vitals_path_breakdown_query` |
+| External clicks | — | `external_clicks_query` |
## Reading a slow tile
diff --git a/products/web_analytics/backend/hogql_queries/query_constants/stats_table_queries.py b/products/web_analytics/backend/hogql_queries/query_constants/stats_table_queries.py
index 669bfe86aa81..0d5bf14810a3 100644
--- a/products/web_analytics/backend/hogql_queries/query_constants/stats_table_queries.py
+++ b/products/web_analytics/backend/hogql_queries/query_constants/stats_table_queries.py
@@ -219,12 +219,47 @@ FROM (
)
"""
+# No-join variant of FIRST_PAGEVIEW_INNER_QUERY. The join path reads only
+# `session.session_id` and `session.$start_timestamp` from the sessions side
+# when bounce rate is off, and {session_id_present} already restricts the scan
+# to UUID session ids, so both come from the UUIDv7 id as in
+# NO_JOIN_MAIN_INNER_QUERY. Non-v7 ids collapse into one NULL session with a
+# NULL start timestamp, exactly as the join leaves them (raw_sessions is v7-only).
+NO_JOIN_FIRST_PAGEVIEW_INNER_QUERY = """
+SELECT
+ filtered_person_id,
+ filtered_pageview_count,
+ {breakdown_value} AS breakdown_value,
+ session_id,
+ start_timestamp
+FROM (
+ SELECT
+ {filtered_person_id} AS filtered_person_id,
+ {filtered_pageview_count} AS filtered_pageview_count,
+ {first_pageview_properties} AS first_pageview_properties,
+ if(
+ equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7),
+ events.$session_id,
+ NULL
+ ) AS session_id,
+ any(if(
+ equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7),
+ fromUnixTimestamp(intDiv(toInt(bitShiftRight(events.$session_id_uuid, 80)), 1000)),
+ NULL
+ )) AS start_timestamp
+ FROM events
+ WHERE and({inside_periods}, {event_where}, {all_properties}, {session_id_present})
+ GROUP BY session_id
+)
+"""
+
# No-join variant of MAIN_INNER_QUERY for simple breakdowns that display no
-# session-derived column (no bounce, no conversion goal, event-property
-# breakdown value). The sessions join above contributes only `session_id`
-# (grouping) and `$start_timestamp` (period attribution) in that case — both
-# recoverable from the UUIDv7 session id itself, so the join is pure overhead
-# (prod-measured 10x wall / ~400x memory on DeviceType for a large team).
+# session-derived column (no bounce, event-property breakdown value). The
+# sessions join above contributes only `session_id` (grouping) and
+# `$start_timestamp` (period attribution) in that case — both recoverable from
+# the UUIDv7 session id itself, so the join is pure overhead (prod-measured 10x
+# wall / ~400x memory on DeviceType for a large team). Conversion-goal columns
+# aggregate event fields only, so they ride the same scan.
# Sessionless and malformed-session-id events still count — the join keeps
# them too (NULL session row). Non-UUIDv7 ids are lumped under a NULL
# `session_id` (raw_sessions is v7-only, so the join's `session.session_id`
diff --git a/products/web_analytics/backend/hogql_queries/stats_table.py b/products/web_analytics/backend/hogql_queries/stats_table.py
index 6818be858afd..9b621db54bf0 100644
--- a/products/web_analytics/backend/hogql_queries/stats_table.py
+++ b/products/web_analytics/backend/hogql_queries/stats_table.py
@@ -44,6 +44,7 @@ from products.web_analytics.backend.hogql_queries.stats_table_strategies import
ChannelTypeStrategy,
FirstPageviewAttributionStrategy,
FrustrationMetricsStrategy,
+ NoJoinFirstPageviewAttributionStrategy,
NoJoinPathBounceAvgTimeStrategy,
NoJoinPathBounceStrategy,
NoJoinSimpleBreakdownStrategy,
@@ -181,6 +182,8 @@ class WebStatsTableQueryRunner(WebAnalyticsQueryRunner[WebStatsTableQueryRespons
# ChannelTypeStrategy must be checked before SimpleBreakdownStrategy since it's a subclass.
if isinstance(strategy, ChannelTypeStrategy):
return "stats_table_channel_type"
+ if isinstance(strategy, NoJoinFirstPageviewAttributionStrategy):
+ return "stats_table_no_join_first_pageview_attribution"
if isinstance(strategy, FirstPageviewAttributionStrategy):
return "stats_table_first_pageview_attribution"
# NoJoinSimpleBreakdownStrategy is also a SimpleBreakdownStrategy subclass.
@@ -240,16 +243,18 @@ class WebStatsTableQueryRunner(WebAnalyticsQueryRunner[WebStatsTableQueryRespons
if breakdown == WebStatsBreakdown.INITIAL_CHANNEL_TYPE:
return ChannelTypeStrategy(self)
+ # Breakdowns whose displayed columns are all event-derived don't need
+ # the events↔sessions join at all — the join only supplies the session
+ # grouping key and start timestamp, both recoverable from the UUIDv7
+ # session id. Conversion-goal columns are event-derived too.
+ # Session-entry breakdowns (Initial*), session-property filters, and
+ # bounce variants keep the join.
+ no_join = not self.query.includeBounceRate and not self._uses_session_fields()
+
if breakdown in FIRST_PAGEVIEW_BREAKDOWNS:
- return FirstPageviewAttributionStrategy(self)
-
- # Simple breakdowns whose displayed columns are all event-derived don't
- # need the events↔sessions join at all — the join only supplies the
- # session grouping key and start timestamp, both recoverable from the
- # UUIDv7 session id. Session-entry breakdowns (Initial*),
- # session-property filters, and bounce/conversion variants keep
- # the join.
- if self.query.conversionGoal is None and not self.query.includeBounceRate and not self._uses_session_fields():
+ return NoJoinFirstPageviewAttributionStrategy(self) if no_join else FirstPageviewAttributionStrategy(self)
+
+ if no_join:
return NoJoinSimpleBreakdownStrategy(self)
return SimpleBreakdownStrategy(self)
@@ -398,6 +403,8 @@ class WebStatsTableQueryRunner(WebAnalyticsQueryRunner[WebStatsTableQueryRespons
visitor = Visitor()
visitor.visit(self._counts_breakdown_value())
visitor.visit(self.all_properties())
+ if self.conversion_goal_expr is not None:
+ visitor.visit(self.conversion_goal_expr)
return found
def _period_comparison_tuple(self, column, alias, function_name):
diff --git a/products/web_analytics/backend/hogql_queries/stats_table_strategies.py b/products/web_analytics/backend/hogql_queries/stats_table_strategies.py
index 706722d33a6a..1c258cb56cd4 100644
--- a/products/web_analytics/backend/hogql_queries/stats_table_strategies.py
+++ b/products/web_analytics/backend/hogql_queries/stats_table_strategies.py
@@ -10,6 +10,7 @@ from products.web_analytics.backend.hogql_queries.query_constants.stats_table_qu
FIRST_PAGEVIEW_INNER_QUERY,
FRUSTRATION_METRICS_INNER_QUERY,
MAIN_INNER_QUERY,
+ NO_JOIN_FIRST_PAGEVIEW_INNER_QUERY,
NO_JOIN_MAIN_INNER_QUERY,
NO_JOIN_PATH_BOUNCE_AND_AVG_TIME_QUERY,
NO_JOIN_PATH_BOUNCE_QUERY,
@@ -233,32 +234,20 @@ class NoJoinSimpleBreakdownStrategy(SimpleBreakdownStrategy):
"""Simple breakdown without the events↔sessions join.
Eligible when the tile displays no session-derived column (no bounce
- rate, no conversion goal) and the breakdown value is computed from event
- columns — the join then contributes only the session grouping key and the
- session-start timestamp, both recoverable from the UUIDv7 session id.
+ rate) and the breakdown value is computed from event columns — the join
+ then contributes only the session grouping key and the session-start
+ timestamp, both recoverable from the UUIDv7 session id. Conversion-goal
+ columns aggregate event fields, so a goal keeps the query eligible.
The outer query is inherited unchanged; only the inner scan differs.
Filters (user + test account) apply inline to the single events scan, so
filtered and unfiltered queries are equally eligible."""
+ INNER_QUERY = NO_JOIN_MAIN_INNER_QUERY
+
def build_query(self) -> ast.SelectQuery:
WEB_ANALYTICS_NO_JOIN_SERVED.labels(family="stats_table_simple_breakdown").inc()
return super().build_query()
- def _inner_query(self, breakdown: ast.Expr) -> ast.SelectQuery:
- query = parse_select(
- NO_JOIN_MAIN_INNER_QUERY,
- timings=self.runner.timings,
- placeholders={
- **self._event_aggregation_placeholders(),
- "breakdown_value": breakdown,
- "event_where": self.runner.event_type_expr,
- "all_properties": self.runner.all_properties(),
- "inside_periods": self.runner._periods_expression(),
- },
- )
- assert isinstance(query, ast.SelectQuery)
- return query
-
class ChannelTypeStrategy(SimpleBreakdownStrategy):
"""INITIAL_CHANNEL_TYPE breakdown.
@@ -321,6 +310,21 @@ class FirstPageviewAttributionStrategy(SimpleBreakdownStrategy):
return query
+class NoJoinFirstPageviewAttributionStrategy(FirstPageviewAttributionStrategy):
+ """First-pageview attribution without the events↔sessions join.
+
+ The per-session level of ``FIRST_PAGEVIEW_INNER_QUERY`` reads the sessions
+ side only for the grouping key and the start timestamp once bounce rate is
+ off; both come from the UUIDv7 session id here. Same eligibility as
+ ``NoJoinSimpleBreakdownStrategy``."""
+
+ INNER_QUERY = NO_JOIN_FIRST_PAGEVIEW_INNER_QUERY
+
+ def build_query(self) -> ast.SelectQuery:
+ WEB_ANALYTICS_NO_JOIN_SERVED.labels(family="stats_table_first_pageview_attribution").inc()
+ return super().build_query()
+
+
class PathBounceStrategy(StatsTableQueryStrategy):
"""PAGE breakdown with bounce rate (no scroll depth or avg time)."""
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_sample_web_analytics_queries.hogql.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_sample_web_analytics_queries.hogql.ambr
index 7791da057bf5..70bff054f75e 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_sample_web_analytics_queries.hogql.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_sample_web_analytics_queries.hogql.ambr
@@ -376,6 +376,45 @@
LIMIT 50000
'''
+# ---
+# name: TestSampleWebAnalyticsQueries.test_web_overview_with_conversion_goal_snapshot
+ '''
+ SELECT uniq(session_person_id) AS unique_users,
+ NULL AS previous_unique_users,
+ sum(filtered_pageview_count) AS total_filtered_pageview_count,
+ NULL AS previous_total_filtered_pageview_count,
+ uniq(session_id) AS unique_sessions,
+ NULL AS previous_unique_sessions,
+ avg(session_duration) AS avg_duration_s,
+ NULL AS previous_avg_duration_s,
+ avg(is_bounce) AS bounce_rate,
+ NULL AS previous_bounce_rate
+ FROM
+ (SELECT any(events.person_id) AS session_person_id,
+ session.session_id AS session_id,
+ min(session.$start_timestamp) AS start_timestamp,
+ any(session.$session_duration) AS session_duration,
+ countIf(or(equals(event, '$pageview'), equals(event, '$screen'))) AS filtered_pageview_count,
+ any(session.$is_bounce) AS is_bounce
+ FROM events
+ WHERE and(notEquals(events.$session_id, NULL), or(equals(event, '$pageview'), equals(event, '$screen')), or(and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59')))), false), 1)
+ GROUP BY session_id
+ HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59')))), false))
+ LIMIT 50000
+ '''
+
+# ---
+# name: TestSampleWebAnalyticsQueries.test_web_overview_with_conversion_goal_snapshot.1
+ '''
+ SELECT countIf(and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59'))))) AS total_conversion_count,
+ NULL AS previous_total_conversion_count,
+ uniqIf(events.person_id, and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59'))))) AS unique_conversions,
+ NULL AS previous_unique_conversions
+ FROM events
+ WHERE and(notEquals(events.$session_id_uuid, NULL), equals(events.event, 'signup'), or(and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59')))), false), 1)
+ LIMIT 50000
+ '''
+
# ---
# name: TestSampleWebAnalyticsQueries.test_web_overview_with_event_filter_snapshot
'''
@@ -1083,6 +1122,85 @@
LIMIT 50000
'''
+# ---
+# name: TestSampleWebAnalyticsQueries.test_web_stats_first_pageview_channel_type_with_conversion_goal_snapshot
+ '''
+ SELECT breakdown_value AS `context.columns.breakdown_value`,
+ tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
+ tuple(uniqIf(session_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.sessions`,
+ tuple(sum(filtered_pageview_count), NULL) AS `context.columns.views`,
+ tuple(sum(conversion_count), NULL) AS `context.columns.total_conversions`,
+ tuple(uniq(conversion_person_id), NULL) AS `context.columns.unique_conversions`,
+ tuple(if(equals(`context.columns.visitors`.1, 0), NULL, divide(`context.columns.unique_conversions`.1, `context.columns.visitors`.1)), if(equals(`context.columns.visitors`.2, 0), NULL, divide(`context.columns.unique_conversions`.2, `context.columns.visitors`.2))) AS `context.columns.conversion_rate`,
+ divide(`context.columns.unique_conversions`.1, sum(`context.columns.unique_conversions`.1) OVER ()) AS `context.columns.ui_fill_fraction`
+ FROM
+ (SELECT filtered_person_id,
+ filtered_pageview_count,
+ multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), notEquals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), NULL)), coalesce(lookupPaidSourceType(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), lookupPaidMediumType(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), lookupPaidSourceType(nullIf(tupleElement(first_pageview_properties, 5), '')), multiIf(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), equals(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), NULL), or(equals(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), NULL), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(lookupOrganicSourceType(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), lookupOrganicMediumType(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), lookupOrganicSourceType(nullIf(tupleElement(first_pageview_properties, 5), '')), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 'Direct', notEquals(nullIf(tupleElement(first_pageview_properties, 5), ''), NULL), 'Referral', 'Unknown'))) AS breakdown_value,
+ session_id,
+ start_timestamp,
+ conversion_count,
+ conversion_person_id
+ FROM
+ (SELECT anyIf(events.person_id, or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_person_id,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ argMinIf(tuple(events.properties.utm_campaign, events.properties.utm_medium, events.properties.utm_source, events.properties.$current_url, events.properties.$referring_domain, events.properties.gclid, events.properties.fbclid, events.properties.gad_source), events.timestamp, in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
+ if(equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7), events.$session_id, NULL) AS session_id,
+ any(if(equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7), fromUnixTimestamp(intDiv(toInt(bitShiftRight(events.$session_id_uuid, 80)), 1000)), NULL)) AS start_timestamp,
+ countIf(equals(events.event, 'signup')) AS conversion_count,
+ any(if(equals(events.event, 'signup'), events.person_id, NULL)) AS conversion_person_id
+ FROM events
+ WHERE and(or(and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59')))), false), or(equals(event, '$pageview'), equals(event, '$screen'), equals(events.event, 'signup')), 1, notEquals(events.$session_id_uuid, NULL))
+ GROUP BY session_id))
+ GROUP BY `context.columns.breakdown_value`
+ HAVING and(notEquals(`context.columns.breakdown_value`, NULL), notEquals(`context.columns.breakdown_value`, ''))
+ ORDER BY `context.columns.unique_conversions` DESC,
+ `context.columns.total_conversions` DESC,
+ `context.columns.visitors` DESC,
+ `context.columns.views` DESC,
+ `context.columns.breakdown_value` ASC
+ LIMIT 50000
+ '''
+
+# ---
+# name: TestSampleWebAnalyticsQueries.test_web_stats_first_pageview_referring_domain_with_conversion_goal_snapshot
+ '''
+ SELECT breakdown_value AS `context.columns.breakdown_value`,
+ tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
+ tuple(uniqIf(session_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.sessions`,
+ tuple(sum(filtered_pageview_count), NULL) AS `context.columns.views`,
+ tuple(sum(conversion_count), NULL) AS `context.columns.total_conversions`,
+ tuple(uniq(conversion_person_id), NULL) AS `context.columns.unique_conversions`,
+ tuple(if(equals(`context.columns.visitors`.1, 0), NULL, divide(`context.columns.unique_conversions`.1, `context.columns.visitors`.1)), if(equals(`context.columns.visitors`.2, 0), NULL, divide(`context.columns.unique_conversions`.2, `context.columns.visitors`.2))) AS `context.columns.conversion_rate`,
+ divide(`context.columns.unique_conversions`.1, sum(`context.columns.unique_conversions`.1) OVER ()) AS `context.columns.ui_fill_fraction`
+ FROM
+ (SELECT filtered_person_id,
+ filtered_pageview_count,
+ nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
+ session_id,
+ start_timestamp,
+ conversion_count,
+ conversion_person_id
+ FROM
+ (SELECT anyIf(events.person_id, or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_person_id,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ argMinIf(tuple(events.properties.$referring_domain), events.timestamp, in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
+ if(equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7), events.$session_id, NULL) AS session_id,
+ any(if(equals(bitAnd(bitShiftRight(events.$session_id_uuid, 76), 15), 7), fromUnixTimestamp(intDiv(toInt(bitShiftRight(events.$session_id_uuid, 80)), 1000)), NULL)) AS start_timestamp,
+ countIf(equals(events.event, 'signup')) AS conversion_count,
+ any(if(equals(events.event, 'signup'), events.person_id, NULL)) AS conversion_person_id
+ FROM events
+ WHERE and(or(and(greaterOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00'))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-01-31 23:59:59')))), false), or(equals(event, '$pageview'), equals(event, '$screen'), equals(events.event, 'signup')), 1, notEquals(events.$session_id_uuid, NULL))
+ GROUP BY session_id))
+ GROUP BY `context.columns.breakdown_value`
+ ORDER BY `context.columns.unique_conversions` DESC,
+ `context.columns.total_conversions` DESC,
+ `context.columns.visitors` DESC,
+ `context.columns.views` DESC,
+ `context.columns.breakdown_value` ASC
+ LIMIT 50000
+ '''
+
# ---
# name: TestSampleWebAnalyticsQueries.test_web_stats_initial_page_with_bounce_rate_snapshot
'''
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr
index 56b0e710b17e..c4c909cddb1d 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr
@@ -129,24 +129,27 @@
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/bar'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/bar')))) AS conversion_count,
- any(if(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/bar'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/bar'))), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -158,8 +161,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/bar'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/bar')))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -176,26 +178,61 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_goal_no_conversions.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/bar'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
+ and isNull('https://www.example.com/bar'))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_conversion_goal_one_autocapture_conversion
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$autocapture'), match(events.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), events.elements_chain_texts))) AS conversion_count,
- any(if(and(equals(events.event, '$autocapture'), match(events.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), events.elements_chain_texts)), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -207,7 +244,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$autocapture'), match(events.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), events.elements_chain_texts))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -224,26 +261,60 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_goal_one_autocapture_conversion.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$autocapture'), match(events.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), events.elements_chain_texts)), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_conversion_goal_one_custom_action_conversion
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(equals(events.event, 'custom_event')) AS conversion_count,
- any(if(equals(events.event, 'custom_event'), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -255,7 +326,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), equals(events.event, 'custom_event')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -272,26 +343,60 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_goal_one_custom_action_conversion.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), equals(events.event, 'custom_event'), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_conversion_goal_one_custom_event_conversion
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(equals(events.event, 'custom_event')) AS conversion_count,
- any(if(equals(events.event, 'custom_event'), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -303,7 +408,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), equals(events.event, 'custom_event')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -320,28 +425,60 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_goal_one_custom_event_conversion.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), equals(events.event, 'custom_event'), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_conversion_goal_one_pageview_conversion
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))) AS conversion_count,
- any(if(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo'))), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -353,8 +490,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -371,28 +507,61 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_goal_one_pageview_conversion.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
+ and isNull('https://www.example.com/foo'))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_conversion_rate
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))) AS conversion_count,
- any(if(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo'))), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -404,8 +573,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -422,6 +590,36 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_conversion_rate.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
+ and isNull('https://www.example.com/foo'))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-28 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_convertToProjectTimezone_date_range_sql_snapshot
'''
SELECT uniq(session_person_id) AS unique_users,
@@ -969,22 +1167,27 @@
'''
SELECT uniq(session_person_id) AS unique_users,
NULL AS previous_unique_users,
- sum(conversion_count) AS total_conversion_count,
- NULL AS previous_total_conversion_count,
- uniq(conversion_person_id) AS unique_conversions,
- NULL AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- NULL AS previous_conversion_rate
+ sum(filtered_pageview_count) AS total_filtered_pageview_count,
+ NULL AS previous_total_filtered_pageview_count,
+ uniq(session_id) AS unique_sessions,
+ NULL AS previous_unique_sessions,
+ avg(session_duration) AS avg_duration_s,
+ NULL AS previous_avg_duration_s,
+ avg(is_bounce) AS bounce_rate,
+ NULL AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0))) AS conversion_count,
- any(if(and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0)), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3))))
@@ -996,7 +1199,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0))
LIMIT 100 SETTINGS readonly=2,
@@ -1014,6 +1217,35 @@
'''
# ---
# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ NULL AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ NULL AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0)), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.2
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
@@ -1074,7 +1306,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.2
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.3
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
@@ -1128,7 +1360,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.3
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_0_event.4
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniq(filtered_person_id), NULL) AS `context.columns.visitors`,
@@ -1190,22 +1422,27 @@
'''
SELECT uniq(session_person_id) AS unique_users,
NULL AS previous_unique_users,
- sum(conversion_count) AS total_conversion_count,
- NULL AS previous_total_conversion_count,
- uniq(conversion_person_id) AS unique_conversions,
- NULL AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- NULL AS previous_conversion_rate
+ sum(filtered_pageview_count) AS total_filtered_pageview_count,
+ NULL AS previous_total_filtered_pageview_count,
+ uniq(session_id) AS unique_sessions,
+ NULL AS previous_unique_sessions,
+ avg(session_duration) AS avg_duration_s,
+ NULL AS previous_avg_duration_s,
+ avg(is_bounce) AS bounce_rate,
+ NULL AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0))) AS conversion_count,
- any(if(and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0)), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3))))
@@ -1217,7 +1454,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0))
LIMIT 100 SETTINGS readonly=2,
@@ -1235,6 +1472,35 @@
'''
# ---
# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ NULL AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ NULL AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, 'customer_created'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0)), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.2
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
@@ -1295,7 +1561,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.2
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.3
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniqIf(filtered_person_id, greater(filtered_pageview_count, 0)), NULL) AS `context.columns.visitors`,
@@ -1349,7 +1615,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.3
+# name: TestWebOverviewQueryRunner.test_goal_properties_preserve_visitors_and_deduplicate_customers_1_action.4
'''
SELECT breakdown_value AS `context.columns.breakdown_value`,
tuple(uniq(filtered_person_id), NULL) AS `context.columns.visitors`,
@@ -1676,24 +1942,27 @@
'''
SELECT uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS unique_users,
uniqIf(session_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_unique_users,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS total_conversion_count,
- sumIf(conversion_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS unique_conversions,
- uniqIf(conversion_person_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- divide(previous_unique_conversions, previous_unique_users) AS previous_conversion_rate
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS total_filtered_pageview_count,
+ sumIf(filtered_pageview_count, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_total_filtered_pageview_count,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS unique_sessions,
+ uniqIf(session_id, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_unique_sessions,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS avg_duration_s,
+ avgIf(session_duration, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_avg_duration_s,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS bounce_rate,
+ avgIf(is_bounce, and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))) AS conversion_count,
- any(if(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo'))), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC')), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC')), toIntervalDay(3))))))
@@ -1705,8 +1974,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC')))), and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))))
LIMIT 100 SETTINGS readonly=2,
@@ -1723,28 +1991,61 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_no_crash_when_no_data.3
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS total_conversion_count,
+ countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC'))))) AS unique_conversions,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))) AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
+ and isNull('https://www.example.com/foo'))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-15 23:59:59', 'UTC')))), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-11-30 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewQueryRunner.test_no_previous_when_comparison_disabled_but_conversion_goal_enabled
'''
SELECT uniq(session_person_id) AS unique_users,
NULL AS previous_unique_users,
- sum(conversion_count) AS total_conversion_count,
- NULL AS previous_total_conversion_count,
- uniq(conversion_person_id) AS unique_conversions,
- NULL AS previous_unique_conversions,
- divide(unique_conversions, unique_users) AS conversion_rate,
- NULL AS previous_conversion_rate
+ sum(filtered_pageview_count) AS total_filtered_pageview_count,
+ NULL AS previous_total_filtered_pageview_count,
+ uniq(session_id) AS unique_sessions,
+ NULL AS previous_unique_sessions,
+ avg(session_duration) AS avg_duration_s,
+ NULL AS previous_avg_duration_s,
+ avg(is_bounce) AS bounce_rate,
+ NULL AS previous_bounce_rate
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS session_person_id,
events__session.session_id AS session_id,
min(events__session.`$start_timestamp`) AS start_timestamp,
- countIf(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))) AS conversion_count,
- any(if(and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo'))), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
+ any(events__session.`$session_duration`) AS session_duration,
+ countIf(or(equals(events.event, '$pageview'), equals(events.event, '$screen'))) AS filtered_pageview_count,
+ any(events__session.`$is_bounce`) AS is_bounce
FROM events
LEFT JOIN
(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
+ dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,
+ if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
raw_sessions.session_id_v7 AS session_id_v7
FROM raw_sessions
WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')), toIntervalDay(3))))
@@ -1756,8 +2057,7 @@
WHERE equals(person_distinct_id_overrides.team_id, 99999)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
- and isNull('https://www.example.com/foo')))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id`), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
GROUP BY session_id
HAVING or(and(greaterOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(start_timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0))
LIMIT 100 SETTINGS readonly=2,
@@ -1774,6 +2074,36 @@
use_hive_partitioning=0
'''
# ---
+# name: TestWebOverviewQueryRunner.test_no_previous_when_comparison_disabled_but_conversion_goal_enabled.1
+ '''
+ SELECT countIf(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS total_conversion_count,
+ NULL AS previous_total_conversion_count,
+ uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))) AS unique_conversions,
+ NULL AS previous_unique_conversions
+ FROM events
+ LEFT OUTER JOIN
+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id, 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
+ WHERE and(equals(events.team_id, 99999), and(isNotNull(events.`$session_id_uuid`), and(equals(events.event, '$pageview'), ifNull(match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'https://www.example.com/foo'), isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''))
+ and isNull('https://www.example.com/foo'))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC')))), 0), 1))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestWebOverviewSessionIdSetFastPath.test_session_id_set_pushes_id_filter_below_session_aggregation
'SELECT events_agg.unique_users AS unique_users, events_agg.previous_unique_users AS previous_unique_users, events_agg.total_filtered_pageview_count AS total_filtered_pageview_count, events_agg.previous_total_filtered_pageview_count AS previous_total_filtered_pageview_count, sessions_agg.unique_sessions AS unique_sessions, sessions_agg.previous_unique_sessions AS previous_unique_sessions, sessions_agg.avg_duration_s AS avg_duration_s, sessions_agg.previous_avg_duration_s AS previous_avg_duration_s, sessions_agg.bounce_rate AS bounce_rate, sessions_agg.previous_bounce_rate AS previous_bounce_rate FROM (SELECT uniqIf(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), and(greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_0)s), assumeNotNull(toDateTime(%(hogql_val_1)s, %(hogql_val_2)s))), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_3)s), assumeNotNull(toDateTime(%(hogql_val_4)s, %(hogql_val_5)s))))) AS unique_users, NULL AS previous_unique_users, countIf(and(greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_6)s), assumeNotNull(toDateTime(%(hogql_val_7)s, %(hogql_val_8)s))), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_9)s), assumeNotNull(toDateTime(%(hogql_val_10)s, %(hogql_val_11)s))))) AS total_filtered_pageview_count, NULL AS previous_total_filtered_pageview_count FROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id FROM person_distinct_id_overrides WHERE equals(person_distinct_id_overrides.team_id, <TEAM_ID>) GROUP BY person_distinct_id_overrides.distinct_id HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) WHERE and(equals(events.team_id, <TEAM_ID>), and(isNotNull(events.`$session_id_uuid`), or(equals(events.event, %(hogql_val_12)s), equals(events.event, %(hogql_val_13)s)), or(and(greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_14)s), assumeNotNull(toDateTime(%(hogql_val_15)s, %(hogql_val_16)s))), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_17)s), assumeNotNull(toDateTime(%(hogql_val_18)s, %(hogql_val_19)s)))), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_20)s), \'\'), \'null\'), \'^"|"$\', \'\'), %(hogql_val_21)s), 0)))) AS events_agg CROSS JOIN (SELECT uniqIf(sessions.session_id, and(greaterOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_43)s, %(hogql_val_44)s))), lessOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_45)s, %(hogql_val_46)s))))) AS unique_sessions, NULL AS previous_unique_sessions, avgIf(sessions.`$session_duration`, and(greaterOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_47)s, %(hogql_val_48)s))), lessOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_49)s, %(hogql_val_50)s))))) AS avg_duration_s, NULL AS previous_avg_duration_s, avgIf(sessions.`$is_bounce`, and(greaterOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_51)s, %(hogql_val_52)s))), lessOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_53)s, %(hogql_val_54)s))))) AS bounce_rate, NULL AS previous_bounce_rate FROM (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_22)s)) AS `$start_timestamp`, dateDiff(%(hogql_val_23)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_24)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_25)s))) AS `$session_duration`, if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff(%(hogql_val_26)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_27)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_28)s))), 10)))) AS `$is_bounce`, uniqMerge(raw_sessions.pageview_uniq) AS `$pageview_count`, uniqMerge(raw_sessions.screen_uniq) AS `$screen_count`, raw_sessions.session_id_v7 AS session_id_v7 FROM raw_sessions WHERE and(equals(raw_sessions.team_id, <TEAM_ID>), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime(%(hogql_val_29)s, %(hogql_val_30)s)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime(%(hogql_val_31)s, %(hogql_val_32)s)), toIntervalDay(3)))), globalIn(raw_sessions.session_id_v7, (SELECT session_id_uuid AS session_id_uuid FROM (SELECT DISTINCT events.`$session_id_uuid` AS session_id_uuid FROM events WHERE and(equals(events.team_id, <TEAM_ID>), and(isNotNull(events.`$session_id_uuid`), or(equals(events.event, %(hogql_val_33)s), equals(events.event, %(hogql_val_34)s)), or(and(greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_35)s), assumeNotNull(toDateTime(%(hogql_val_36)s, %(hogql_val_37)s))), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_38)s), assumeNotNull(toDateTime(%(hogql_val_39)s, %(hogql_val_40)s)))), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_41)s), \'\'), \'null\'), \'^"|"$\', \'\'), %(hogql_val_42)s), 0))))))) GROUP BY raw_sessions.session_id_v7) AS sessions WHERE and(or(and(greaterOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_55)s, %(hogql_val_56)s))), lessOrEquals(sessions.`$start_timestamp`, assumeNotNull(toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)))), 0), or(greater(sessions.`$pageview_count`, 0), greater(sessions.`$screen_count`, 0)), 1)) AS sessions_agg LIMIT 50000'
# ---
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr
index e8ab6ebee7a8..c53528d8f799 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr
@@ -1978,24 +1978,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2036,24 +2026,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2113,24 +2093,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2295,24 +2265,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2352,24 +2312,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2432,7 +2382,6 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp,
conversion_count AS conversion_count,
conversion_person_id AS conversion_person_id
@@ -2440,20 +2389,11 @@
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp,
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp,
countIf(equals(events.event, 'custom_event')) AS conversion_count,
any(if(equals(events.event, 'custom_event'), if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), NULL)) AS conversion_person_id
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2619,24 +2559,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2676,24 +2606,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2754,24 +2674,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -2892,24 +2802,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3028,24 +2928,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3164,24 +3054,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3248,24 +3128,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3332,24 +3202,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3416,24 +3276,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3493,24 +3343,14 @@
filtered_pageview_count AS filtered_pageview_count,
nullIf(tupleElement(first_pageview_properties, 1), '') AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3577,24 +3417,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3655,24 +3485,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
@@ -3733,24 +3553,14 @@
filtered_pageview_count AS filtered_pageview_count,
multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'paid'), isNotNull(nullIf(tupleElement(first_pageview_properties, 6), '')), isNotNull(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'))), coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_paid', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(ifNull(equals(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 8), ''), ''), 'null'), '1'), 0), 'Paid Search', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Paid Video', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Paid Social', 'Paid Unknown')), and(ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null'))), or(isNull(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null'))), in(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')))), 'Direct', coalesce(coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 3), ''), ''), 'null')), '')), 'source'))), if(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), ''), 'medium')), coalesce(dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), ''), 'source')), dictGetOrNull('posthog_test.channel_definition_dict', 'type_if_organic', (cutToFirstSignificantSubdomain(coalesce(nullIf(tupleElement(first_pageview_properties, 5), ''), '')), 'source'))), multiIf(match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 1), ''), ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf(nullIf(tupleElement(first_pageview_properties, 2), ''), ''), 'null')), 'push$'), 'Push', isNotNull(nullIf(tupleElement(first_pageview_properties, 7), '')), 'Organic Social', ifNull(equals(nullIf(tupleElement(first_pageview_properties, 5), ''), '$direct'), 0), 'Direct', isNotNull(nullIf(tupleElement(first_pageview_properties, 5), '')), 'Referral', 'Unknown'))) AS breakdown_value,
session_id AS session_id,
- is_bounce AS is_bounce,
start_timestamp AS start_timestamp
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
argMinIf(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_campaign'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_medium'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'utm_source'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$referring_domain'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'fbclid'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'gad_source'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), in(events.event, tuple('$pageview', '$screen'))) AS first_pageview_properties,
- events__session.session_id AS session_id,
- any(events__session.`$is_bounce`) AS is_bounce,
- min(events__session.`$start_timestamp`) AS start_timestamp
+ if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), events.`$session_id`, NULL) AS session_id,
+ any(if(ifNull(equals(bitAnd(bitShiftRight(events.`$session_id_uuid`, 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(events.`$session_id_uuid`, 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events
- LEFT JOIN
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- if(equals(uniqMerge(raw_sessions.pageview_uniq), 0), NULL, not(or(greater(uniqMerge(raw_sessions.pageview_uniq), 1), greater(uniqMerge(raw_sessions.autocapture_uniq), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))), 10)))) AS `$is_bounce`,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(assumeNotNull(toDateTime('2024-06-26 10:00:00', 'UTC')), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2024-06-27 23:59:59', 'UTC')), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.`$session_id_uuid`, events__session.session_id_v7)
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
person_distinct_id_overrides.distinct_id AS distinct_id
diff --git a/products/web_analytics/backend/hogql_queries/test/test_sample_web_analytics_queries.py b/products/web_analytics/backend/hogql_queries/test/test_sample_web_analytics_queries.py
index 47641a33d872..087f83f8af3e 100644
--- a/products/web_analytics/backend/hogql_queries/test/test_sample_web_analytics_queries.py
+++ b/products/web_analytics/backend/hogql_queries/test/test_sample_web_analytics_queries.py
@@ -320,6 +320,53 @@ class TestSampleWebAnalyticsQueries(ClickhouseTestMixin, APIBaseTest):
runner = WebStatsTableQueryRunner(team=self.team, query=query)
runner.calculate()
+ def test_web_overview_with_conversion_goal_snapshot(self):
+ """
+ Overview query with a conversion goal, as sent by the marketing dashboard's
+ customer summary. Pins the shape of the conversion-goal path, which cannot
+ use the pre-aggregated or lazily precomputed overview tables.
+ """
+ query = WebOverviewQuery(
+ dateRange=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
+ properties=[],
+ conversionGoal=CustomEventConversionGoal(customEventName="signup"),
+ )
+ runner = WebOverviewQueryRunner(team=self.team, query=query)
+ runner.calculate()
+
+ def test_web_stats_first_pageview_channel_type_with_conversion_goal_snapshot(self):
+ """
+ First-pageview channel type breakdown with a conversion goal and traffic
+ metrics, as sent by the marketing dashboard's acquisition table.
+ """
+ query = WebStatsTableQuery(
+ dateRange=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
+ properties=[],
+ breakdownBy=WebStatsBreakdown.FIRST_PAGEVIEW_CHANNEL_TYPE,
+ conversionGoal=CustomEventConversionGoal(customEventName="signup"),
+ includeTrafficMetrics=True,
+ limit=10,
+ )
+ runner = WebStatsTableQueryRunner(team=self.team, query=query)
+ runner.calculate()
+
+ def test_web_stats_first_pageview_referring_domain_with_conversion_goal_snapshot(self):
+ """
+ First-pageview referring domain breakdown with a conversion goal and
+ traffic metrics. Same shape as the channel type variant without the
+ channel classifier, so the two snapshots isolate the classifier's cost.
+ """
+ query = WebStatsTableQuery(
+ dateRange=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
+ properties=[],
+ breakdownBy=WebStatsBreakdown.FIRST_PAGEVIEW_REFERRING_DOMAIN,
+ conversionGoal=CustomEventConversionGoal(customEventName="signup"),
+ includeTrafficMetrics=True,
+ limit=10,
+ )
+ runner = WebStatsTableQueryRunner(team=self.team, query=query)
+ runner.calculate()
+
def test_web_trends_unique_users_snapshot(self):
"""
Web analytics trends query for unique visitors over time.
diff --git a/products/web_analytics/backend/hogql_queries/test/test_web_overview.py b/products/web_analytics/backend/hogql_queries/test/test_web_overview.py
index db07c11de39c..c401fcb4b518 100644
--- a/products/web_analytics/backend/hogql_queries/test/test_web_overview.py
+++ b/products/web_analytics/backend/hogql_queries/test/test_web_overview.py
@@ -43,7 +43,7 @@ from posthog.hogql.printer import prepare_and_print_ast
from posthog.hogql.query import execute_hogql_query
from posthog.clickhouse.client.execute import sync_execute
-from posthog.models import Element
+from posthog.models import Element, Team
from posthog.models.utils import uuid7
from posthog.settings import HOGQL_INCREASED_MAX_EXECUTION_TIME
@@ -638,12 +638,8 @@ class TestWebOverviewQueryRunner(FirstPageviewAttributionTestMixin, ClickhouseTe
def test_conversion_goal_one_custom_event_conversion(self):
s1 = str(uuid7("2023-12-01"))
- self._create_events(
- [
- ("p1", [("2023-12-01", s1, "https://www.example.com/foo")]),
- ],
- event="custom_event",
- )
+ self._create_events([("p1", [("2023-12-01", s1, "https://www.example.com/foo")])])
+ self._create_events([("p1", [("2023-12-01", s1)])], event="custom_event")
results = self._run_web_overview_query("2023-12-01", "2023-12-03", custom_event="custom_event").results
@@ -661,12 +657,8 @@ class TestWebOverviewQueryRunner(FirstPageviewAttributionTestMixin, ClickhouseTe
def test_conversion_goal_one_custom_action_conversion(self):
s1 = str(uuid7("2023-12-01"))
- self._create_events(
- [
- ("p1", [("2023-12-01", s1)]),
- ],
- event="custom_event",
- )
+ self._create_events([("p1", [("2023-12-01", s1, "https://www.example.com/foo")])])
+ self._create_events([("p1", [("2023-12-01", s1)])], event="custom_event")
action = Action.objects.create(
team=self.team,
@@ -694,6 +686,7 @@ class TestWebOverviewQueryRunner(FirstPageviewAttributionTestMixin, ClickhouseTe
def test_conversion_goal_one_autocapture_conversion(self):
s1 = str(uuid7("2023-12-01"))
+ self._create_events([("p1", [("2023-12-01", s1, "https://www.example.com/foo")])])
self._create_events(
[
("p1", [("2023-12-01", s1, [Element(nth_of_type=1, nth_child=0, tag_name="button", text="Pay $10")])]),
@@ -1189,6 +1182,45 @@ class TestWebOverviewQueryRunner(FirstPageviewAttributionTestMixin, ClickhouseTe
class TestWebOverviewNoJoinFastPath(ClickhouseTestMixin, APIBaseTest):
QUERY_TIMESTAMP = "2025-01-29"
+ @override_settings(WEB_ANALYTICS_NO_JOIN_TEAM_IDS=[], WEB_ANALYTICS_NO_JOIN_ROLLOUT_PERCENT=0)
+ @time_machine.travel(QUERY_TIMESTAMP, tick=False)
+ def test_conversion_goal_with_legacy_session_id(self) -> None:
+ team, _ = Team.objects.get_or_create(
+ id=2, defaults={"organization": self.organization, "project": self.team.project}
+ )
+ test_run_id = str(uuid7())
+ _create_person(team_id=team.pk, distinct_ids=[test_run_id])
+ for event in ["$pageview", "signup"]:
+ _create_event(
+ team=team,
+ event=event,
+ distinct_id=test_run_id,
+ timestamp="2025-01-10T12:00:00Z",
+ properties={
+ "$session_id": f"legacy-{test_run_id}",
+ "$current_url": "https://example.com/",
+ "test_run_id": test_run_id,
+ },
+ )
+
+ response = WebOverviewQueryRunner(
+ team=team,
+ query=WebOverviewQuery(
+ dateRange=DateRange(date_from="2025-01-08", date_to="2025-01-15"),
+ properties=[EventPropertyFilter(key="test_run_id", value=test_run_id, operator=PropertyOperator.EXACT)],
+ filterTestAccounts=False,
+ conversionGoal=CustomEventConversionGoal(customEventName="signup"),
+ modifiers=HogQLQueryModifiers(sessionTableVersion=SessionTableVersion.V1),
+ ),
+ ).calculate()
+
+ assert {item.key: item.value for item in response.results} == {
+ "visitors": 1,
+ "total conversions": 1,
+ "unique conversions": 1,
+ "conversion rate": 100,
+ }
+
def _create_pageviews(self):
s1, s2, s3 = str(uuid7("2025-01-10")), str(uuid7("2025-01-11")), str(uuid7("2025-01-12"))
for distinct_id, session_id, timestamps in [
diff --git a/products/web_analytics/backend/hogql_queries/web_overview.py b/products/web_analytics/backend/hogql_queries/web_overview.py
index c5afa8c8a4cf..7e2d5c9bde02 100644
--- a/products/web_analytics/backend/hogql_queries/web_overview.py
+++ b/products/web_analytics/backend/hogql_queries/web_overview.py
@@ -5,7 +5,10 @@ import structlog
from posthog.schema import (
CachedWebOverviewQueryResponse,
+ EventPropertyFilter,
HogQLQueryModifiers,
+ PersonPropertyFilter,
+ SessionTableVersion,
WebAnalyticsPreComputeStrategy,
WebOverviewQuery,
WebOverviewQueryResponse,
@@ -324,7 +327,118 @@ CROSS JOIN {sessions_agg} AS sessions_agg
preComputeStrategy=WebAnalyticsPreComputeStrategy.LAZY_PRECOMPUTE,
)
+ @cached_property
+ def should_split_conversion_goal(self) -> bool:
+ """Whether a conversion-goal overview can run as visitors + a goal-only scan.
+
+ The joined shape groups every pageview session in range to count a handful
+ of conversions, so its memory scales with total traffic rather than with the
+ goal. Splitting keeps visitors on the goal-less path (precompute,
+ pre-aggregated or two-scan) and reads only goal events for conversions.
+ Filters must be events-evaluable for the goal scan; session and cohort
+ filters keep the joined shape.
+ """
+ if not self.query.conversionGoal:
+ return False
+ if self.modifiers.sessionTableVersion == SessionTableVersion.V1:
+ return False
+ if not all(isinstance(p, EventPropertyFilter | PersonPropertyFilter) for p in self.effective_query_properties):
+ return False
+ return all(f.get("type") in ("event", "person") for f in self._test_account_filters)
+
+ def _conversion_goal_select(self) -> ast.SelectQuery:
+ has_comparison = bool(self.query_compare_to_date_range)
+ current = self._current_period_expression("timestamp")
+ previous = self._previous_period_expression("timestamp")
+ query = parse_select(
+ """
+SELECT
+ countIf({current}) AS total_conversion_count,
+ {previous_total} AS previous_total_conversion_count,
+ uniqIf(events.person_id, {current}) AS unique_conversions,
+ {previous_unique} AS previous_unique_conversions
+FROM events
+WHERE and(
+ {events_session_id_present},
+ {conversion_goal},
+ {inside_timestamp_period},
+ {all_properties},
+)
+ """,
+ placeholders={
+ "current": current,
+ "previous_total": (
+ parse_expr("countIf({previous})", placeholders={"previous": previous})
+ if has_comparison
+ else ast.Constant(value=None)
+ ),
+ "previous_unique": (
+ parse_expr("uniqIf(events.person_id, {previous})", placeholders={"previous": previous})
+ if has_comparison
+ else ast.Constant(value=None)
+ ),
+ "events_session_id_present": self.events_session_id_present,
+ "conversion_goal": self.conversion_goal_expr or ast.Constant(value=False),
+ "inside_timestamp_period": self._periods_expression("timestamp"),
+ "all_properties": self.all_properties(),
+ },
+ )
+ assert isinstance(query, ast.SelectQuery)
+ return query
+
+ def _calculate_split_conversion_goal(self) -> WebOverviewQueryResponse:
+ visitors_runner = WebOverviewQueryRunner(
+ query=self.query.model_copy(update={"conversionGoal": None}),
+ team=self.team,
+ timings=self.timings,
+ modifiers=self.modifiers,
+ limit_context=self.limit_context,
+ user=self.user,
+ )
+ visitors_response = visitors_runner._calculate()
+ visitors = next(item for item in visitors_response.results if item.key == "visitors")
+
+ conversions_response = execute_hogql_query(
+ query_type="web_overview_conversion_goal_query",
+ query=self._conversion_goal_select(),
+ team=self.team,
+ user=self.user,
+ timings=self.timings,
+ modifiers=self.modifiers,
+ limit_context=self.limit_context,
+ )
+ row = conversions_response.results[0] if conversions_response.results else [None] * 4
+ include_previous = bool(self.query.compareFilter and self.query.compareFilter.compare)
+
+ def rate(unique_conversions: Optional[float], unique_visitors: Optional[float]) -> Optional[float]:
+ if unique_conversions is None or not unique_visitors:
+ return None
+ return unique_conversions / unique_visitors
+
+ results = [
+ to_data("visitors", "unit", visitors.value, visitors.previous if include_previous else None),
+ to_data("total conversions", "unit", row[0], row[1] if include_previous else None),
+ to_data("unique conversions", "unit", row[2], row[3] if include_previous else None),
+ to_data(
+ "conversion rate",
+ "percentage",
+ rate(row[2], visitors.value),
+ rate(row[3], visitors.previous) if include_previous else None,
+ ),
+ ]
+ return WebOverviewQueryResponse(
+ results=results,
+ modifiers=self.modifiers,
+ dateFrom=self.query_date_range.date_from_str,
+ dateTo=self.query_date_range.date_to_str,
+ preComputeStrategy=visitors_response.preComputeStrategy,
+ preComputeIneligibleReason=visitors_response.preComputeIneligibleReason,
+ )
+
def _calculate(self) -> WebOverviewQueryResponse:
+ if self.should_split_conversion_goal:
+ return self._calculate_split_conversion_goal()
+
lazy_row = self.get_lazy_precomputed_row()
if lazy_row is not None:
return self._build_response_from_row(lazy_row)