: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(experiments): add experiment actors query to the exposure event on funnel metrics. (#62294)
Rodrigo Iloro239b62926a1d
diff --git a/frontend/src/scenes/experiments/charts/funnel/FunnelBarVertical.tsx b/frontend/src/scenes/experiments/charts/funnel/FunnelBarVertical.tsxindex 91acc6fd5e6a..04c9674ac878 100644--- a/frontend/src/scenes/experiments/charts/funnel/FunnelBarVertical.tsx+++ b/frontend/src/scenes/experiments/charts/funnel/FunnelBarVertical.tsx@@ -14,7 +14,7 @@ import { StepBars } from './StepBars'import { StepLegend } from './StepLegend'interface TooltipContext {- showTooltip: (rect: [number, number, number], stepIndex: number, series: any, hasSessionData?: boolean) => void+ showTooltip: (rect: [number, number, number], stepIndex: number, series: any) => voidhideTooltip: () => void}diff --git a/frontend/src/scenes/experiments/charts/funnel/FunnelTooltip.tsx b/frontend/src/scenes/experiments/charts/funnel/FunnelTooltip.tsxindex 5e6bbc595b06..1f148147c62c 100644--- a/frontend/src/scenes/experiments/charts/funnel/FunnelTooltip.tsx+++ b/frontend/src/scenes/experiments/charts/funnel/FunnelTooltip.tsx@@ -25,15 +25,9 @@ interface FunnelTooltipProps {stepIndex: numberseries: FunnelStepWithConversionMetricsembedded?: boolean- hasSessionData?: boolean}-function FunnelTooltipContent({- stepIndex,- series,- embedded = false,- hasSessionData = false,-}: FunnelTooltipProps): JSX.Element {+function FunnelTooltipContent({ stepIndex, series, embedded = false }: FunnelTooltipProps): JSX.Element {return (<divclassName={clsx('FunnelTooltip InsightTooltip', {@@ -93,24 +87,16 @@ function FunnelTooltipContent({)}</tbody></table>- {hasSessionData && (- <>- <LemonDivider className="my-2" />- <ClickToInspectActors groupTypeLabel="persons" />- </>- )}++ <LemonDivider className="my-2" />+ <ClickToInspectActors groupTypeLabel="persons" /></div>)}export function useFunnelTooltip(): {vizRef: React.RefObject<HTMLDivElement>- showTooltip: (- rect: [number, number, number],- stepIndex: number,- series: FunnelStepWithConversionMetrics,- hasSessionData?: boolean- ) => void+ showTooltip: (rect: [number, number, number], stepIndex: number, series: FunnelStepWithConversionMetrics) => voidhideTooltip: () => void} {const vizRef = useRef<HTMLDivElement>(null)@@ -119,18 +105,15 @@ export function useFunnelTooltip(): {const [isTooltipShown, setIsTooltipShown] = useState(false)const [currentTooltip, setCurrentTooltip] = useState<FunnelTooltipData | null>(null)const [tooltipOrigin, setTooltipOrigin] = useState<[number, number, number] | null>(null)- const [hasSessionData, setHasSessionData] = useState(false)const showTooltip = (rect: [number, number, number],stepIndex: number,- series: FunnelStepWithConversionMetrics,- hasSessionData: boolean = false+ series: FunnelStepWithConversionMetrics): void => {setIsTooltipShown(true)setCurrentTooltip({ stepIndex, series })setTooltipOrigin(rect)- setHasSessionData(hasSessionData)}const hideTooltip = (): void => {@@ -147,11 +130,7 @@ export function useFunnelTooltip(): {if (tooltipOrigin && currentTooltip) {tooltipRoot.render(- <FunnelTooltipContent- stepIndex={currentTooltip.stepIndex}- series={currentTooltip.series}- hasSessionData={hasSessionData}- />+ <FunnelTooltipContent stepIndex={currentTooltip.stepIndex} series={currentTooltip.series} />)// Put the tooltip to the bottom right of the cursor, but flip to left if tooltip doesn't fitdiff --git a/frontend/src/scenes/experiments/charts/funnel/StepBar.tsx b/frontend/src/scenes/experiments/charts/funnel/StepBar.tsxindex 99b5c0e39d03..e14edb259db1 100644--- a/frontend/src/scenes/experiments/charts/funnel/StepBar.tsx+++ b/frontend/src/scenes/experiments/charts/funnel/StepBar.tsx@@ -64,15 +64,16 @@ function openExperimentPersonsModalForSeries({order_type: experimentQuery.metric.funnel_order_type,})- // IMPORTANT: For experiment funnels, the frontend adds an "Experiment exposure" step at index 0- // But the backend actors query funnel doesn't include this - it only has the actual metric events+ // IMPORTANT: For experiment funnels, the frontend adds an "Experiment exposure" step at index 0.+ // The backend actors query treats exposure as step 0 (returning all exposed actors) and the+ // actual metric events as steps 1..N, so frontend step indices map directly to backend steps.// Frontend: Step 0=Exposure, Step 1=$pageview, Step 2=click- // Backend: Step 1=$pageview, Step 2=click- // So we map frontend step indices to backend step numbers directly (stepIndex = backendStepNo)+ // Backend: Step 0=Exposure, Step 1=$pageview, Step 2=clickconst backendStepNo = stepIndex- // Skip if trying to query the "Experiment exposure" step (stepIndex 0, doesn't exist in backend)- if (backendStepNo < 1) {+ // The exposure step (step 0) only supports conversions ("all exposed actors").+ // A drop-off "before exposure" is not a meaningful query.+ if (backendStepNo === 0 && !converted) {return}@@ -173,12 +174,7 @@ export function StepBar({ step, stepIndex }: StepBarProps): JSX.Element | null {onMouseEnter={() => {if (ref.current) {const rect = ref.current.getBoundingClientRect()- // Only show "Click to inspect actors" hint when clicking will actually work:- // - Step 0 (exposure): can't use actors query (returns early), so don't show hint- // - Step 1 (first metric) drop-offs: can't query (no exposure in backend funnel), conversions work- // - Step 2+: both conversions and drop-offs work- const hasClickableData = stepIndex > 0- showTooltip([rect.x, rect.y, rect.width], stepIndex, step, hasClickableData)+ showTooltip([rect.x, rect.y, rect.width], stepIndex, step)}}}onMouseLeave={() => hideTooltip()}@@ -194,7 +190,7 @@ export function StepBar({ step, stepIndex }: StepBarProps): JSX.Element | null {className="StepBar__fill"onClick={handleConversionClick}style={{- cursor: stepIndex > 0 ? 'pointer' : 'default',+ cursor: 'pointer',}}/></div>diff --git a/products/experiments/backend/hogql_queries/experiment_funnel_actors_query_builder.py b/products/experiments/backend/hogql_queries/experiment_funnel_actors_query_builder.pyindex 80c940f0e8c4..af02193a9b6b 100644--- a/products/experiments/backend/hogql_queries/experiment_funnel_actors_query_builder.py+++ b/products/experiments/backend/hogql_queries/experiment_funnel_actors_query_builder.py@@ -88,6 +88,46 @@ class ExperimentFunnelActorsQueryBuilder:return query+ def build_exposure_actors_query(self) -> ast.SelectQuery:+ """+ Build actors query for the exposure step (funnel step 0).++ Unlike the metric-step actors query, this needs no funnel evaluation: the+ exposure bar counts everyone who was exposed to a variant, so we select+ straight from the exposures CTE. Recordings, when requested, point at the+ first exposure event.+ """+ exposure_select_query = self._query_builder._exposure_query_builder().select_query()++ query = cast(+ ast.SelectQuery,+ parse_select(+ "WITH exposures AS ({exposure_query}) SELECT * FROM exposures",+ placeholders={"exposure_query": exposure_select_query},+ ),+ )++ select_exprs: list[ast.Expr] = [+ ast.Alias(alias="actor_id", expr=ast.Field(chain=["entity_id"])),+ ast.Alias(alias="variant", expr=ast.Field(chain=["variant"])),+ ]++ if self.include_recordings:+ # Mirror the (timestamp, uuid, $session_id, $window_id) tuple shape the+ # actors runner expects, sourced from the first exposure event.+ select_exprs.append(+ ast.Alias(+ alias="matching_events",+ expr=parse_expr("array(tuple(first_exposure_time, exposure_event_uuid, exposure_session_id, ''))"),+ )+ )++ query.select = select_exprs+ query.where = self._build_variant_filter()+ query.order_by = [ast.OrderExpr(expr=ast.Field(chain=["actor_id"]))]++ return query+def _build_base_query_with_ctes(self) -> ast.SelectQuery:"""Build query with exposures, metric_events, and entity_metrics CTEs.@@ -369,18 +409,24 @@ class ExperimentFunnelActorsQueryBuilder:)# Filter by variant (skip if empty string or None)- if self.funnel_step_breakdown:- if isinstance(self.funnel_step_breakdown, int | float):- variant_value = str(int(self.funnel_step_breakdown))- else:- variant_value = self.funnel_step_breakdown-- conditions.append(- parse_expr(- "variant = {variant}",- {"variant": ast.Constant(value=variant_value)},- )- )+ variant_filter = self._build_variant_filter()+ if variant_filter is not None:+ conditions.append(variant_filter)query.where = ast.And(exprs=conditions) if conditions else Nonereturn query++ def _build_variant_filter(self) -> ast.Expr | None:+ """Build a `variant = ...` filter, or None when no variant is requested."""+ if not self.funnel_step_breakdown:+ return None++ if isinstance(self.funnel_step_breakdown, int | float):+ variant_value = str(int(self.funnel_step_breakdown))+ else:+ variant_value = self.funnel_step_breakdown++ return parse_expr(+ "variant = {variant}",+ {"variant": ast.Constant(value=variant_value)},+ )diff --git a/products/experiments/backend/hogql_queries/experiment_query_runner.py b/products/experiments/backend/hogql_queries/experiment_query_runner.pyindex e1d915bf00cf..4c12f0cf306a 100644--- a/products/experiments/backend/hogql_queries/experiment_query_runner.py+++ b/products/experiments/backend/hogql_queries/experiment_query_runner.py@@ -889,12 +889,6 @@ class ExperimentQueryRunner(QueryRunner):f"Valid drop-off steps: -2 (dropped after first metric step) to -{num_metric_steps + 1}.")- if funnel_step == 0:- raise ValidationError(- "Funnel steps are 1-indexed. Step 0 does not exist. "- f"Valid conversion steps: 1 (first metric step) to {num_metric_steps}."- )-if funnel_step < -1:max_drop_off = -(num_metric_steps + 1)if funnel_step < max_drop_off:@@ -988,6 +982,11 @@ class ExperimentQueryRunner(QueryRunner):include_recordings=self.actors_query.includeRecordings or False,)+ # Step 0 is the exposure step: return everyone exposed to the variant,+ # without funnel evaluation.+ if funnel_step == 0:+ return builder.build_exposure_actors_query()+return builder.build_actors_query()def to_query(self) -> ast.SelectQuery:diff --git a/products/experiments/backend/hogql_queries/test/__snapshots__/test_experiment_actors_query.ambr b/products/experiments/backend/hogql_queries/test/__snapshots__/test_experiment_actors_query.ambrindex 37e9eaebd21c..35440be9046b 100644--- a/products/experiments/backend/hogql_queries/test/__snapshots__/test_experiment_actors_query.ambr+++ b/products/experiments/backend/hogql_queries/test/__snapshots__/test_experiment_actors_query.ambr@@ -1,5 +1,166 @@# serializer version: 1-# name: TestExperimentActorsQuery.test_experiment_funnel_actors_0_conversions_step1_control+# name: TestExperimentActorsQuery.test_experiment_exposure_actors_with_recordings+ '''+ SELECT source.id,+ source.id AS id,+ source.matching_events AS matching_events+ FROM+ (WITH exposures AS+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,+ if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id+ 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), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))+ GROUP BY entity_id) SELECT exposures.entity_id AS actor_id,+ exposures.variant AS variant,+ array(tuple(toTimeZone(exposures.first_exposure_time, 'UTC'), exposures.exposure_event_uuid, exposures.exposure_session_id, '')) AS matching_events,+ actor_id AS id+ FROM exposures+ WHERE ifNull(equals(variant, 'control'), 0)+ ORDER BY actor_id ASC) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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: TestExperimentActorsQuery.test_experiment_exposure_actors_with_recordings.1+ '''+ SELECT session_replay_events.session_id AS session_id,+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,+ max(session_replay_events.retention_period_days) AS retention_period_days,+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time+ FROM session_replay_events+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))+ GROUP BY session_replay_events.session_id+ HAVING and(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), equals(max(session_replay_events.is_deleted), 0))+ 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: TestExperimentActorsQuery.test_experiment_funnel_actors_0_exposure_control+ '''+ SELECT source.id,+ source.id AS id+ FROM+ (WITH exposures AS+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,+ if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id+ 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), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))+ GROUP BY entity_id) SELECT exposures.entity_id AS actor_id,+ exposures.variant AS variant,+ actor_id AS id+ FROM exposures+ WHERE ifNull(equals(variant, 'control'), 0)+ ORDER BY actor_id ASC) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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: TestExperimentActorsQuery.test_experiment_funnel_actors_1_exposure_test+ '''+ SELECT source.id,+ source.id AS id+ FROM+ (WITH exposures AS+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,+ if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,+ min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,+ max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,+ argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,+ argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id+ 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), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))+ GROUP BY entity_id) SELECT exposures.entity_id AS actor_id,+ exposures.variant AS variant,+ actor_id AS id+ FROM exposures+ WHERE ifNull(equals(variant, 'test'), 0)+ ORDER BY actor_id ASC) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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: TestExperimentActorsQuery.test_experiment_funnel_actors_2_conversions_step1_control'''SELECT source.id,source.id AS id@@ -71,7 +232,7 @@use_hive_partitioning=0'''# ----# name: TestExperimentActorsQuery.test_experiment_funnel_actors_1_conversions_step2_control+# name: TestExperimentActorsQuery.test_experiment_funnel_actors_3_conversions_step2_control'''SELECT source.id,source.id AS id@@ -143,7 +304,7 @@use_hive_partitioning=0'''# ----# name: TestExperimentActorsQuery.test_experiment_funnel_actors_2_dropoffs_control+# name: TestExperimentActorsQuery.test_experiment_funnel_actors_4_dropoffs_control'''SELECT source.id,source.id AS id@@ -215,7 +376,7 @@use_hive_partitioning=0'''# ----# name: TestExperimentActorsQuery.test_experiment_funnel_actors_3_conversions_step1_test+# name: TestExperimentActorsQuery.test_experiment_funnel_actors_5_conversions_step1_test'''SELECT source.id,source.id AS id@@ -287,7 +448,7 @@use_hive_partitioning=0'''# ----# name: TestExperimentActorsQuery.test_experiment_funnel_actors_4_conversions_step2_test+# name: TestExperimentActorsQuery.test_experiment_funnel_actors_6_conversions_step2_test'''SELECT source.id,source.id AS id@@ -359,7 +520,7 @@use_hive_partitioning=0'''# ----# name: TestExperimentActorsQuery.test_experiment_funnel_actors_5_dropoffs_test+# name: TestExperimentActorsQuery.test_experiment_funnel_actors_7_dropoffs_test'''SELECT source.id,source.id AS iddiff --git a/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py b/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.pyindex 5f828969350b..82a5d1bec5a2 100644--- a/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py+++ b/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py@@ -147,6 +147,8 @@ class TestExperimentActorsQuery(ExperimentQueryRunnerBaseTest, ClickhouseTestMix@parameterized.expand([+ ("exposure_control", 0, "control", 10), # Step 0 = all exposed actors (control)+ ("exposure_test", 0, "test", 10), # Step 0 = all exposed actors (test)("conversions_step1_control", 1, "control", 6), # Step 1 conversions (signup)("conversions_step2_control", 2, "control", 4), # Step 2 conversions (purchase)("dropoffs_control", -2, "control", 2), # Step 2 drop-offs (signup but no purchase)@@ -315,6 +317,38 @@ class TestExperimentActorsQuery(ExperimentQueryRunnerBaseTest, ClickhouseTestMix# matched_recordings should be a list (may be empty if no actual recordings exist)assert isinstance(response.results[0][2], list)+ @freeze_time("2020-01-01T12:00:00Z")+ @snapshot_clickhouse_queries+ def test_experiment_exposure_actors_with_recordings(self):+ """+ Step 0 (exposure) actors query should still expose matched_recordings,+ sourced from the first exposure event rather than a metric step.+ """+ feature_flag, _experiment, experiment_query = self._create_experiment_with_funnel()+ feature_flag_property = f"$feature/{feature_flag.key}"++ self._create_funnel_data_both_variants(feature_flag_property)+ flush_persons_and_events()++ experiment_actors_query = ExperimentActorsQuery(+ kind="ExperimentActorsQuery",+ source=experiment_query,+ funnelStep=0,+ funnelStepBreakdown="control",+ includeRecordings=True,+ )++ actors_query = ActorsQuery(+ source=experiment_actors_query,+ select=["id", "person", "matched_recordings"],+ )++ response = ActorsQueryRunner(query=actors_query, team=self.team).calculate()++ assert len(response.results) == 10+ assert len(response.results[0]) == 3+ assert isinstance(response.results[0][2], list)+@freeze_time("2020-01-01T12:00:00Z")def test_experiment_funnel_actors_invalid_steps(self):"""@@ -327,9 +361,8 @@ class TestExperimentActorsQuery(ExperimentQueryRunnerBaseTest, ClickhouseTestMix4. Use clear, actionable languageExperiment funnels have unique constraints:- - Exposure is step 0 in main query but excluded from actors query+ - Exposure is step 0 in main query and queryable via the actors query (returns all exposed actors)- funnelStep=-1 is invalid (would mean "exposed but never entered funnel")- - funnelStep=0 is invalid (steps are 1-indexed)- Out-of-range steps should be rejected"""feature_flag, experiment, experiment_query = self._create_experiment_with_funnel()@@ -362,30 +395,6 @@ class TestExperimentActorsQuery(ExperimentQueryRunnerBaseTest, ClickhouseTestMixself.assertIn("Valid drop-off steps: -2", error_message) # Shows valid rangeself.assertIn("-3", error_message) # Shows upper bound of valid range- # Test 0: Invalid step (steps are 1-indexed)- # Error message should explain that step 0 doesn't exist and show valid range- experiment_actors_query_zero = ExperimentActorsQuery(- kind="ExperimentActorsQuery",- source=experiment_query,- funnelStep=0,- funnelStepBreakdown="control",- includeRecordings=False,- )-- actors_query_zero = ActorsQuery(- source=experiment_actors_query_zero,- select=["id", "person"],- )-- with self.assertRaises(Exception) as context:- ActorsQueryRunner(query=actors_query_zero, team=self.team).calculate()-- error_message = str(context.exception)- self.assertIn("Funnel steps are 1-indexed", error_message)- self.assertIn("Step 0 does not exist", error_message)- self.assertIn("Valid conversion steps: 1", error_message) # Shows start of valid range- self.assertIn("2", error_message) # Shows end of valid range (2 metric steps)-# Test out-of-range drop-off (2-step funnel, so -3 is last valid, -4 is invalid)# Error message should show the invalid step, number of metric steps, and valid rangeexperiment_actors_query_out_of_range = ExperimentActorsQuery(