: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(experiments): handle missing metric on legacy experiments page (#58813)
posthog[bot]2fb9e51ffccb
diff --git a/frontend/src/scenes/experiments/legacy/legacyUtils.ts b/frontend/src/scenes/experiments/legacy/legacyUtils.tsindex 3644d4ae0f07..a168fdaecdcd 100644--- a/frontend/src/scenes/experiments/legacy/legacyUtils.ts+++ b/frontend/src/scenes/experiments/legacy/legacyUtils.ts@@ -21,8 +21,10 @@ import { legacyGetSignificanceDetails } from './calculations/legacyExperimentCal* @deprecated* Use the getInsightType function from the experimentLogic instead.*/-export const getInsightType = (metric: ExperimentTrendsQuery | ExperimentFunnelsQuery): InsightType => {- return metric.kind === NodeKind.ExperimentTrendsQuery ? InsightType.TRENDS : InsightType.FUNNELS+export const getInsightType = (+ metric: ExperimentTrendsQuery | ExperimentFunnelsQuery | undefined | null+): InsightType => {+ return metric?.kind === NodeKind.ExperimentTrendsQuery ? InsightType.TRENDS : InsightType.FUNNELS}/**@@ -44,7 +46,7 @@ export const getTabularExperimentResults =| CachedExperimentTrendsQueryResponse| null)[],- getInsightType: (metric: ExperimentTrendsQuery | ExperimentFunnelsQuery) => InsightType+ getInsightType: (metric: ExperimentTrendsQuery | ExperimentFunnelsQuery | undefined | null) => InsightType) =>(metricIdentifier: number | string = 0, isSecondary: boolean = false): any[] => {let index: number@@ -61,9 +63,11 @@ export const getTabularExperimentResults =const tabularResults = []const metricType = isSecondary- ? getInsightType(experiment.metrics_secondary[index] as ExperimentTrendsQuery | ExperimentFunnelsQuery)- : getInsightType(experiment.metrics[index] as ExperimentTrendsQuery | ExperimentFunnelsQuery)- const result = isSecondary ? legacySecondaryMetricsResults[index] : legacyPrimaryMetricsResults[index]+ ? getInsightType(+ experiment.metrics_secondary?.[index] as ExperimentTrendsQuery | ExperimentFunnelsQuery | undefined+ )+ : getInsightType(experiment.metrics?.[index] as ExperimentTrendsQuery | ExperimentFunnelsQuery | undefined)+ const result = isSecondary ? legacySecondaryMetricsResults?.[index] : legacyPrimaryMetricsResults?.[index]if (result) {for (const variantObj of result.variants) {