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(experiments): Support same-day repeat-behavior retention metrics (#64289)

Marcel Poelker4a60123e3860
diff --git a/products/experiments/backend/hogql_queries/experiment_retention_query_builder.py b/products/experiments/backend/hogql_queries/experiment_retention_query_builder.py
index 85eedc523dd6..85513da84e3e 100644
--- a/products/experiments/backend/hogql_queries/experiment_retention_query_builder.py
+++ b/products/experiments/backend/hogql_queries/experiment_retention_query_builder.py
@@ -130,7 +130,8 @@ class RetentionQueryBuilder:
start_events AS (
SELECT
exposures.entity_id AS entity_id,
- {start_timestamp_expr} AS start_timestamp
+ {start_timestamp_expr} AS start_timestamp,
+ {start_uuid_expr} AS start_uuid
FROM events
INNER JOIN exposures ON {entity_key} = exposures.entity_id
WHERE {start_event_predicate}
@@ -141,6 +142,7 @@ class RetentionQueryBuilder:
completion_events AS (
SELECT
{entity_key} AS entity_id,
+ uuid AS completion_uuid,
timestamp AS completion_timestamp
FROM events
WHERE {completion_event_predicate}
@@ -163,6 +165,12 @@ class RetentionQueryBuilder:
LEFT JOIN completion_events
ON exposures.entity_id = completion_events.entity_id
AND {completion_retention_window_predicate}
+ -- A completion must be a distinct event from the start occurrence.
+ -- Without this, a metric whose start and completion events are the
+ -- same would have every start trivially count as its own completion
+ -- (100% retention); event uuids are unique, so this is a no-op when
+ -- the two events differ.
+ AND completion_events.completion_uuid != start_events.start_uuid
GROUP BY exposures.entity_id, exposures.variant
)
"""
@@ -171,6 +179,7 @@ class RetentionQueryBuilder:
"exposure_select_query": self._b._get_exposure_query(),
"entity_key": parse_expr(self._b.entity_key),
"start_timestamp_expr": self.build_start_event_timestamp_expr(),
+ "start_uuid_expr": self.build_start_event_uuid_expr(),
"start_event_predicate": self.build_start_event_predicate(),
"completion_event_predicate": self.build_completion_event_predicate(),
"retention_window_start_interval": self.build_retention_window_interval(
@@ -239,6 +248,19 @@ class RetentionQueryBuilder:
else: # LAST_SEEN
return parse_expr("max(timestamp)")
+ def build_start_event_uuid_expr(self) -> ast.Expr:
+ """
+ Returns the uuid of the start occurrence chosen by start_handling, so it can
+ be excluded from its own completion window. Mirrors build_start_event_timestamp_expr:
+ FIRST_SEEN picks the earliest occurrence, LAST_SEEN the latest.
+ """
+ assert isinstance(self._b.metric, ExperimentRetentionMetric)
+
+ if self._b.metric.start_handling == StartHandling.FIRST_SEEN:
+ return parse_expr("argMin(uuid, timestamp)")
+ else: # LAST_SEEN
+ return parse_expr("argMax(uuid, timestamp)")
+
def get_retention_window_truncation_expr(self, timestamp_expr: ast.Expr) -> ast.Expr:
"""
Returns truncated timestamp expression for retention window comparisons.
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
index 51d3947c17e7..798e39606f76 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
@@ -1704,7 +1704,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1718,6 +1719,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1735,7 +1737,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant,
exposures.breakdown_value_1)
@@ -1798,7 +1800,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1812,6 +1815,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1829,7 +1833,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant,
exposures.breakdown_value_1)
@@ -1892,7 +1896,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1906,6 +1911,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1924,7 +1930,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant,
exposures.breakdown_value_1,
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr
index 8cfe043d6913..8ecd2ce5388c 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr
@@ -30,7 +30,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -44,6 +45,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -60,7 +62,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -101,7 +103,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -115,6 +118,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -131,7 +135,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -190,7 +194,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -205,6 +210,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -221,7 +227,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -262,7 +268,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -277,6 +284,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -293,7 +301,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -352,7 +360,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -367,6 +376,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -383,7 +393,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -424,7 +434,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -439,6 +450,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -455,7 +467,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -514,7 +526,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -529,6 +542,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -545,7 +559,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -586,7 +600,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -601,6 +616,7 @@
HAVING lessOrEquals(plus(min(toTimeZone(events.timestamp, 'UTC')), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-25 12:00:00', 6, 'UTC'))),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -617,7 +633,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -676,7 +692,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -690,6 +707,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -706,7 +724,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(0))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(0)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(86400)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(86400)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -747,7 +765,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -761,6 +780,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -777,7 +797,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(0))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(0)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(86400)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(86400)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -836,7 +856,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -850,6 +871,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -866,7 +888,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -924,7 +946,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- max(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ max(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMax(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -938,6 +961,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -954,7 +978,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1012,7 +1036,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1026,6 +1051,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1042,7 +1068,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1100,7 +1126,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- max(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ max(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMax(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1114,6 +1141,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1130,7 +1158,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1188,7 +1216,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1202,6 +1231,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1218,7 +1248,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfHour(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfHour(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalHour(0))), lessOrEquals(toStartOfHour(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfHour(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalHour(0)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(3600)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(3600)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1259,7 +1289,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1273,6 +1304,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1289,7 +1321,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfHour(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfHour(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalHour(0))), lessOrEquals(toStartOfHour(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfHour(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalHour(0)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(3600)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(3600)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1348,7 +1380,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1362,6 +1395,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1378,7 +1412,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1419,7 +1453,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1433,6 +1468,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1449,7 +1485,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1508,7 +1544,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1522,6 +1559,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1538,7 +1576,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1579,7 +1617,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1593,6 +1632,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1609,7 +1649,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1668,7 +1708,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1682,6 +1723,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1698,7 +1740,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1739,7 +1781,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1753,6 +1796,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1769,7 +1813,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1828,7 +1872,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1842,6 +1887,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1858,7 +1904,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -1916,7 +1962,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -1930,6 +1977,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -1946,7 +1994,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2004,7 +2052,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2018,6 +2067,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2034,7 +2084,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2075,7 +2125,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2089,6 +2140,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2105,7 +2157,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2164,7 +2216,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2178,6 +2231,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2194,7 +2248,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(14)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(1296000)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(1296000)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2235,7 +2289,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2249,6 +2304,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2265,7 +2321,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(14)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(1296000)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(1296000)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2324,7 +2380,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2338,6 +2395,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2354,7 +2412,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(3)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(345600)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(345600)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
@@ -2395,7 +2453,8 @@
GROUP BY entity_id),
start_events AS
(SELECT exposures.entity_id AS entity_id,
- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp
+ min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,
+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid
FROM events
LEFT OUTER JOIN
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
@@ -2409,6 +2468,7 @@
GROUP BY exposures.entity_id),
completion_events AS
(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
+ events.uuid AS completion_uuid,
toTimeZone(events.timestamp, 'UTC') AS completion_timestamp
FROM events
LEFT OUTER JOIN
@@ -2425,7 +2485,7 @@
max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(1))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(3)))), 1, 0)) AS value
FROM exposures
INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)
- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(345600)))))
+ LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(345600)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))
GROUP BY exposures.entity_id,
exposures.variant)
SELECT entity_metrics.variant AS variant,
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py
index e91baf98d568..ed33a6e93e55 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py
@@ -1029,6 +1029,140 @@ class TestExperimentRetentionMetric(ExperimentQueryRunnerBaseTest):
self.assertEqual(test_variant.denominator_sum_squares, 4)
self.assertEqual(test_variant.numerator_denominator_sum_product, 2)
+ # Retention where the start event and completion event are the same. The
+ # qualifying start occurrence must not count as its own completion, otherwise
+ # every user is trivially retained at 100%; the metric should measure "did the
+ # user fire this event again within the window?", so only a *distinct* later
+ # occurrence counts.
+ @parameterized.expand(
+ [
+ # [0,0] FIRST_SEEN anchors on the first occurrence, so a distinct
+ # same-day repeat after it counts as "did it again".
+ ("first_seen_same_day_direct", False, StartHandling.FIRST_SEEN, 0, 0, 1, 1),
+ ("first_seen_same_day_precomputed", True, StartHandling.FIRST_SEEN, 0, 0, 1, 1),
+ # [0,0] LAST_SEEN anchors on the last occurrence; nothing distinct can
+ # come after it within the same day, so no user is ever retained. This
+ # also guards that start_uuid is paired with the *last* occurrence
+ # (argMax): were it the first, the last occurrence would falsely self-count.
+ ("last_seen_same_day_direct", False, StartHandling.LAST_SEEN, 0, 0, 0, 0),
+ ("last_seen_same_day_precomputed", True, StartHandling.LAST_SEEN, 0, 0, 0, 0),
+ # [1,1] regression: the self occurrence is already outside the window
+ # (day 0, window starts day 1), so the new uuid clause is a no-op here.
+ # Only the distinct next-day repeat counts, exactly as before the change.
+ ("first_seen_window_start_one_direct", False, StartHandling.FIRST_SEEN, 1, 1, 1, 0),
+ ("first_seen_window_start_one_precomputed", True, StartHandling.FIRST_SEEN, 1, 1, 1, 0),
+ ]
+ )
+ @freeze_time("2024-01-01T12:00:00Z")
+ def test_retention_same_start_and_completion_event_excludes_self(
+ self,
+ name,
+ use_precomputation,
+ start_handling,
+ window_start,
+ window_end,
+ expected_control_retained,
+ expected_test_retained,
+ ):
+ self._setup_precomputation_test(use_precomputation)
+
+ feature_flag = self.create_feature_flag()
+ experiment = self.create_experiment(feature_flag=feature_flag)
+ experiment.stats_config = {"method": "frequentist"}
+ experiment.save()
+
+ ff_property = f"$feature/{feature_flag.key}"
+
+ metric = ExperimentRetentionMetric(
+ start_event=EventsNode(
+ event="page_view",
+ math=ExperimentMetricMathType.TOTAL,
+ ),
+ completion_event=EventsNode(
+ event="page_view",
+ math=ExperimentMetricMathType.TOTAL,
+ ),
+ retention_window_start=window_start,
+ retention_window_end=window_end,
+ retention_window_unit=FunnelConversionWindowTimeUnit.DAY,
+ start_handling=start_handling,
+ )
+
+ experiment_query = ExperimentQuery(
+ experiment_id=experiment.id,
+ kind="ExperimentQuery",
+ metric=metric,
+ )
+
+ experiment.metrics = [metric.model_dump(mode="json")]
+ self._save_experiment_with_precomputation(experiment, use_precomputation)
+
+ def _exposure(variant: str) -> dict:
+ return {
+ "event": "$feature_flag_called",
+ "timestamp": "2024-01-02T09:00:00",
+ "properties": {
+ "$feature_flag_response": variant,
+ ff_property: variant,
+ "$feature_flag": feature_flag.key,
+ },
+ }
+
+ def _page_view(variant: str, timestamp: str) -> dict:
+ return {"event": "page_view", "timestamp": timestamp, "properties": {ff_property: variant}}
+
+ # 3 control + 2 test users start; whether each is retained depends on the
+ # window. A distinct same-day repeat counts only for [0,0]; a distinct
+ # next-day repeat counts only for [1,1]. A single occurrence never counts.
+ journeys_for(
+ {
+ "control_repeat_same_day": [
+ _exposure("control"),
+ _page_view("control", "2024-01-02T10:00:00"),
+ _page_view("control", "2024-01-02T14:00:00"),
+ ],
+ "control_single": [
+ _exposure("control"),
+ _page_view("control", "2024-01-02T10:00:00"),
+ ],
+ "control_repeat_next_day": [
+ _exposure("control"),
+ _page_view("control", "2024-01-02T10:00:00"),
+ _page_view("control", "2024-01-03T10:00:00"),
+ ],
+ "test_repeat_same_day": [
+ _exposure("test"),
+ _page_view("test", "2024-01-02T10:00:00"),
+ _page_view("test", "2024-01-02T11:00:00"),
+ ],
+ "test_single": [
+ _exposure("test"),
+ _page_view("test", "2024-01-02T10:00:00"),
+ ],
+ },
+ self.team,
+ )
+
+ flush_persons_and_events()
+
+ query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)
+ result = cast(ExperimentQueryResponse, query_runner.calculate())
+
+ assert result.baseline is not None
+ assert result.variant_results is not None
+ self.assertEqual(len(result.variant_results), 1)
+
+ control_variant = result.baseline
+ test_variant = result.variant_results[0]
+
+ # Control: 3 users started; retention depends on start_handling
+ self.assertEqual(control_variant.number_of_samples, 3)
+ self.assertEqual(control_variant.sum, expected_control_retained)
+
+ # Test: 2 users started; retention depends on start_handling
+ self.assertEqual(test_variant.number_of_samples, 2)
+ self.assertEqual(test_variant.sum, expected_test_retained)
+
@parameterized.expand(
[
("direct", False),
diff --git a/products/experiments/skills/configuring-experiment-analytics/SKILL.md b/products/experiments/skills/configuring-experiment-analytics/SKILL.md
index 198043b4877f..f3d651ab0139 100644
--- a/products/experiments/skills/configuring-experiment-analytics/SKILL.md
+++ b/products/experiments/skills/configuring-experiment-analytics/SKILL.md
@@ -123,11 +123,12 @@ Both can reference the same event — the difference is whether you care about c
**Retention: same vs different start/completion event**
The retention window is measured from the start event, so the events you pick decide what's measured:
+The start occurrence never counts as its own completion (only a distinct later event does), so both shapes are valid:
-- **Different** start and completion events → conversion-style retention ("did they reach the target action within the window?"). `retention_window_start: 0` is fine — same-day completions count.
-- **Same** start and completion event → repeat retention ("did they do it _again_ later?"). This **requires `retention_window_start` ≥ 1** with `start_handling: "first_seen"`. With `From 0` the start occurrence is its own completion, so the metric is always 100%. When a user says "retention of <event>" they usually mean repeat retention, so default to `From 1`.
+- **Different** start and completion events → conversion-style retention ("did they reach the target action within the window?").
+- **Same** event → repeat retention ("did they fire it _again_?"). `From 0` counts a repeat from the same period onward (same-day repeats included); `From ≥ 1` requires an occurrence later. Use `start_handling: "first_seen"`. When a user says "retention of `<event>`" they usually mean repeat retention.
-See `references/metric-configuration.md` for the full rendered `ExperimentMetric` schema (all four metric types, with required fields per type) plus WRONG/RIGHT JSON pairs for the failure modes that come up most often (ratio with `is_set` filter instead of `math: "sum"` + `math_property`; retention without `retention_window_start` / `start_handling`; retention with the same start and completion event and `retention_window_start: 0`, which always reads 100%). Read it before assembling a ratio or retention payload — the required fields are authoritative.
+See `references/metric-configuration.md` for the full rendered `ExperimentMetric` schema (all four metric types, with required fields per type) plus WRONG/RIGHT JSON pairs for the failure modes that come up most often (ratio with `is_set` filter instead of `math: "sum"` + `math_property`; retention without `retention_window_start` / `start_handling`). Read it before assembling a ratio or retention payload — the required fields are authoritative.
### Step 3: Primary vs secondary
diff --git a/products/experiments/skills/configuring-experiment-analytics/references/metric-configuration.md.j2 b/products/experiments/skills/configuring-experiment-analytics/references/metric-configuration.md.j2
index ec2f3851c4b7..8f2b4bc503ac 100644
--- a/products/experiments/skills/configuring-experiment-analytics/references/metric-configuration.md.j2
+++ b/products/experiments/skills/configuring-experiment-analytics/references/metric-configuration.md.j2
@@ -160,25 +160,20 @@ required and controls how users with multiple start events are anchored:
recent).
The window is measured **from the start event** and bucketed by
-`retention_window_unit`, which is `"day"` or `"hour"` (start of day / start of
-hour; the examples below use days). `From 0` includes the start period itself (a
-same-period completion counts); `From N` (N ≥ 1) only counts a completion in a
-later period. So the relationship between the two events is the choice that
-matters:
-
-- **Different events** (e.g. `$pageview` → `uploaded_file`) — conversion-style
- retention: "did the user reach the target action within the window?" `From 0`
- is correct (same-day conversions should count).
+`retention_window_unit`, which is `"day"` or `"hour"`. The start occurrence never
+counts as its own completion — only a *distinct* later event does — so the start
+and completion events may be the same:
+
+- **Different events** (e.g. `$pageview` → `uploaded_file`) — conversion retention:
+ "did the user reach the target action within the window?"
- **Same event** (e.g. `promoted_product_clicked` → `promoted_product_clicked`) —
- repeat retention: "did the user do it _again_ later?" This **requires
- `retention_window_start` ≥ 1**. With `From 0` the qualifying start occurrence is
- itself a completion on day 0, so every user is trivially retained and the metric
- always reads 100%. Use `start_handling: "first_seen"` so the anchor is the user's
- first occurrence and later repeats fall inside the window — `last_seen` anchors on
- the most recent occurrence, which by construction has no same-event activity after
- it inside the experiment window.
+ repeat retention: "did the user fire it _again_ within the window?" `From 0`
+ counts a repeat from the same period onward (same-day/same-hour repeats count);
+ `From N` (N ≥ 1) requires the repeat in a later period. Use `start_handling: "first_seen"`
+ so in-experiment repeats fall after the anchor — `last_seen` anchors on the user's
+ final occurrence, which has no in-experiment activity after it.
-### Right — conversion retention (different events, `From 0`)
+### Right — conversion retention (different events)
```json
{
@@ -200,7 +195,7 @@ matters:
}
```
-### Right — repeat retention (same event, `From 1`)
+### Right — repeat retention (same event)
```json
{
@@ -215,22 +210,6 @@ matters:
"kind": "EventsNode",
"event": "promoted_product_clicked"
},
- "retention_window_start": 1,
- "retention_window_end": 7,
- "retention_window_unit": "day",
- "start_handling": "first_seen"
-}
-```
-
-### Wrong — same start/completion event with `retention_window_start: 0` (always 100%)
-
-```json
-{
- "kind": "ExperimentMetric",
- "metric_type": "retention",
- "name": "7-day repeat-click retention",
- "start_event": { "kind": "EventsNode", "event": "promoted_product_clicked" },
- "completion_event": { "kind": "EventsNode", "event": "promoted_product_clicked" },
"retention_window_start": 0,
"retention_window_end": 7,
"retention_window_unit": "day",
@@ -238,10 +217,10 @@ matters:
}
```
-The start occurrence is its own completion on day 0, so every user is retained and
-the metric always reads 100%. Fix it by setting `retention_window_start` ≥ 1
-(repeat retention) or choosing a different `completion_event` (conversion
-retention).
+Measures "of users who clicked the promoted product, how many clicked it again
+within 7 days". The first click anchors the window and never counts as its own
+completion — only a later distinct click does, so a one-time clicker is correctly
+counted as not retained.
### Wrong — missing `retention_window_start` and `start_handling`