: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
fix(insights): re-clamp funnel exclusion step ranges when steps change (#69182)
posthog[bot]629f838291ae
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.tsindex d1215f2fe12d..bfaaf7211c32 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts@@ -126,6 +126,55 @@ describe('insightVizDataLogic', () => {})})+ it('clamps exclusion step ranges when a funnel step is removed', () => {+ const querySource = {+ ...funnelsQueryDefault,+ series: [funnelsQueryDefault.series[0], funnelsQueryDefault.series[0], funnelsQueryDefault.series[0]],+ funnelsFilter: {+ funnelVizType: 'steps',+ exclusions: [+ {+ kind: NodeKind.EventsNode,+ name: '$autocapture',+ event: '$autocapture',+ funnelFromStep: 0,+ funnelToStep: 2,+ },+ ],+ },+ } as FunnelsQuery+ builtInsightVizDataLogic.actions.updateQuerySource(querySource)++ expectLogic(builtInsightDataLogic, () => {+ builtInsightVizDataLogic.actions.updateQuerySource({+ ...querySource,+ series: querySource.series.slice(0, 2),+ } as FunnelsQuery)+ }).toMatchValues({+ query: {+ kind: NodeKind.InsightVizNode,+ source: {+ ...querySource,+ series: querySource.series.slice(0, 2),+ funnelsFilter: {+ funnelVizType: 'steps',+ exclusions: [+ {+ kind: NodeKind.EventsNode,+ name: '$autocapture',+ event: '$autocapture',+ funnelFromStep: 0,+ funnelToStep: 1,+ },+ ],+ },+ trendsFilter: {},+ version: 2,+ },+ },+ })+ })+it('clears a custom lifecycle aggregation target when switching away from a data warehouse series', () => {const lifecycleQuery: LifecycleQuery = {kind: NodeKind.LifecycleQuery,diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.tsindex f2a2229883f8..1e4a7f3a7569 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts@@ -892,20 +892,29 @@ const handleQuerySourceUpdateSideEffects = (}}- // clamp the funnel steps- if (- maybeChangedSeries &&- isFunnelsQuery(currentState) &&- ((insightFilter as FunnelsFilter)?.funnelFromStep != null ||- (insightFilter as FunnelsFilter)?.funnelToStep != null)- ) {- // Filter out GroupNode types as funnels only use AnyEntityNode- const funnelSeries: AnyEntityNode<FunnelsDataWarehouseNode>[] = maybeChangedSeries.filter(- (node): node is AnyEntityNode<FunnelsDataWarehouseNode> => node.kind !== NodeKind.GroupNode- )- ;(mergedUpdate as FunnelsQuery).funnelsFilter = {- ...(insightFilter as FunnelsFilter),- ...getClampedFunnelStepRange(insightFilter as FunnelsFilter, funnelSeries),+ // clamp the funnel conversion window and per-exclusion step ranges against the new series+ if (maybeChangedSeries && isFunnelsQuery(currentState)) {+ const funnelsFilter = insightFilter as FunnelsFilter | undefined+ const hasConversionWindow = funnelsFilter?.funnelFromStep != null || funnelsFilter?.funnelToStep != null+ const hasExclusions = (funnelsFilter?.exclusions?.length ?? 0) > 0++ if (hasConversionWindow || hasExclusions) {+ // Filter out GroupNode types as funnels only use AnyEntityNode+ const funnelSeries: AnyEntityNode<FunnelsDataWarehouseNode>[] = maybeChangedSeries.filter(+ (node): node is AnyEntityNode<FunnelsDataWarehouseNode> => node.kind !== NodeKind.GroupNode+ )+ ;(mergedUpdate as FunnelsQuery).funnelsFilter = {+ ...funnelsFilter,+ ...getClampedFunnelStepRange(funnelsFilter ?? {}, funnelSeries),+ ...(hasExclusions+ ? {+ exclusions: funnelsFilter?.exclusions?.map((exclusion) => ({+ ...exclusion,+ ...getClampedFunnelStepRange(exclusion, funnelSeries),+ })),+ }+ : {}),+ }}}