: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(frontend): load bi worksheet analytics only for bi insights (#126936)
Paul D'Ambra69b17aa6776b
diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txtindex 55766ef648da..4f549564e7a3 100644--- a/frontend/bin/layer-baseline.txt+++ b/frontend/bin/layer-baseline.txt@@ -361,7 +361,6 @@ frontend/src/lib/utils/eventUsageLogic.ts -> frontend/src/lib/logic/preflightLogfrontend/src/lib/utils/eventUsageLogic.ts -> frontend/src/queries/utils.tsfrontend/src/lib/utils/eventUsageLogic.ts -> frontend/src/scenes/product-tours/constants.tsfrontend/src/lib/utils/eventUsageLogic.ts -> frontend/src/scenes/userLogic.ts-frontend/src/lib/utils/eventUsageLogic.ts -> products/business_intelligence/frontend/biEditorAnalytics.tsfrontend/src/lib/utils/eventUsageLogic.ts -> products/experiments/frontend/experimentStatus.tsfrontend/src/lib/utils/events.ts -> frontend/src/taxonomy/taxonomy.tsxfrontend/src/loadPostHogJS.tsx -> products/webmcp/frontend/webmcpToolError.tsdiff --git a/frontend/src/lib/utils/eventUsageLogic.test.ts b/frontend/src/lib/utils/eventUsageLogic.test.tsindex 833309477af0..c1bf4b947d8f 100644--- a/frontend/src/lib/utils/eventUsageLogic.test.ts+++ b/frontend/src/lib/utils/eventUsageLogic.test.ts@@ -1,3 +1,4 @@+import { expectLogic } from 'kea-test-utils'import posthog from 'posthog-js'import { NodeKind } from '~/queries/schema/schema-general'@@ -16,10 +17,13 @@ import {ChartDisplayType,FilterLogicalOperator,FunnelVizType,+ InsightModel,PropertyFilterType,StepOrderValue,} from '~/types'+import { DEFAULT_BI_CONFIG } from 'products/business_intelligence/frontend/biEditorTypes'+import { eventUsageLogic, getEventPropertiesForMetric, sanitizeQuery } from './eventUsageLogic'describe('eventUsageLogic', () => {@@ -47,6 +51,50 @@ describe('eventUsageLogic', () => {})})+ describe('saved insight to dashboard', () => {+ const biQuery = {+ kind: NodeKind.BIVisualizationNode,+ source: { kind: NodeKind.HogQLQuery, query: 'select 1' },+ config: DEFAULT_BI_CONFIG,+ }++ afterEach(() => {+ jest.dontMock('products/business_intelligence/frontend/biEditorAnalytics')+ })++ it.each([+ ['a BI insight', biQuery, false, ['saved insight to dashboard', 'bi-worksheet-action']],+ [+ 'a BI insight when the BI chunk fails',+ biQuery,+ true,+ ['saved insight to dashboard', 'bi-worksheet-action'],+ ],+ [+ 'a trends insight',+ { kind: NodeKind.InsightVizNode, source: { kind: NodeKind.TrendsQuery, series: [] } },+ false,+ ['saved insight to dashboard'],+ ],+ ])('captures the dashboard events for %s', async (_, query, chunkFails, expectedEvents) => {+ if (chunkFails) {+ jest.doMock('products/business_intelligence/frontend/biEditorAnalytics', () => {+ throw new Error('chunk failed to load')+ })+ }+ initKeaTests()+ eventUsageLogic.mount()+ const capture = jest.spyOn(posthog, 'capture').mockImplementation()++ await expectLogic(eventUsageLogic, () => {+ eventUsageLogic.actions.reportSavedInsightToDashboard({ id: 1, query } as Partial<InsightModel>, 2)+ }).toFinishAllListeners()++ expect(capture.mock.calls.map(([event]) => event)).toEqual(expectedEvents)+ capture.mockRestore()+ })+ })+describe('ExperimentMetric (new format)', () => {it('extracts funnel metric properties', () => {const metric: ExperimentFunnelMetric = {diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex a64ceeeddd6a..111ce2e02003 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -6,6 +6,7 @@ import type { IntegrationConnectSurface, IntegrationLinkExistingCounts } from 'limport { TimeToSeeDataPayload } from 'lib/internalMetrics'import { preflightLogic } from 'lib/logic/preflightLogic'import { objectClean } from 'lib/utils/objects'+import { retryImport } from 'lib/utils/retryImport'import { BillingUsageInteractionProps } from 'scenes/billing/types'import type { ExperimentWizardStepNavigation } from 'scenes/experiments/ExperimentWizard/experimentWizardLogic'import { SharedMetric } from 'scenes/experiments/SharedMetrics/sharedMetricLogic'@@ -64,7 +65,6 @@ import {type SDK,} from '~/types'-import { captureBIWorksheetAction } from 'products/business_intelligence/frontend/biEditorAnalytics'import { getExperimentStatus } from 'products/experiments/frontend/experimentStatus'import type { ExperimentMetricUnion } from '../../queries/schema/schema-general'@@ -2024,13 +2024,23 @@ export const eventUsageLogic = kea<eventUsageLogicType>([posthog.capture('created new dashboard from modal')},reportSavedInsightToDashboard: async ({ insight, dashboardId }) => {- if (isBIVisualizationNode(insight?.query)) {- captureBIWorksheetAction('added_to_dashboard', insight.query.config, { insight_id: insight.id })- }posthog.capture('saved insight to dashboard', {insight: sanitizeInsight(insight),dashboard_id: dashboardId,})+ if (isBIVisualizationNode(insight?.query)) {+ // Dynamic import keeps the BI editor runtime out of the eager shell bundle+ const biEditorAnalytics = await retryImport(+ () => import('products/business_intelligence/frontend/biEditorAnalytics')+ ).catch(() => null)+ if (biEditorAnalytics) {+ biEditorAnalytics.captureBIWorksheetAction('added_to_dashboard', insight.query.config, {+ insight_id: insight.id,+ })+ } else {+ posthog.capture('bi-worksheet-action', { action: 'added_to_dashboard', insight_id: insight.id })+ }+ }},reportRemovedInsightFromDashboard: async ({ insight, dashboardId }) => {posthog.capture('removed insight from dashboard', {