: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(marketing): avoid global reloads from source health checks (#120727)
Javier Bahamondes49189e27574e
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.mdindex 4e7055a25e2f..63f6e873f20a 100644--- a/docs/internal/marketing-source-suggestions.md+++ b/docs/internal/marketing-source-suggestions.md@@ -11,6 +11,12 @@ It ranks below a source with 25 paid events, regardless of that source's total tThese counts guide connection suggestions; they do not change report attribution or connected-source sync checks.+## Background source checks++Source health checks run when the window regains focus and every 30 seconds while a source is syncing.+These checks update source metadata and validation without forcing all dashboard queries to refresh.+Queries reload when their inputs change or when the user refreshes the dashboard.+## MCP setup recommendationsThe `marketing-analytics-setup-plan-mcp` feature flag controls whether the MCP server exposes the read-only `marketing-analytics-setup-plan` tool.diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.tsindex 5c02994267ec..df7f3190b1f3 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts@@ -13,6 +13,7 @@ import { urls } from 'scenes/urls'import { getNewInsightUrlFactory } from 'scenes/web-analytics/insightsUtils'import { useMocks } from '~/mocks/jest'+import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import {ConversionGoalFilter,@@ -55,7 +56,10 @@ import {} from './marketingAnalyticsLogic'import { marketingAnalyticsSettingsLogic } from './marketingAnalyticsSettingsLogic'import { marketingAnalyticsTableLogic } from './marketingAnalyticsTableLogic'-import { marketingAnalyticsTilesLogic } from './marketingAnalyticsTilesLogic'+import {+ MARKETING_ANALYTICS_DATA_COLLECTION_NODE_ID,+ marketingAnalyticsTilesLogic,+} from './marketingAnalyticsTilesLogic'jest.mock('posthog-js')@@ -752,7 +756,7 @@ describe('marketingAnalyticsLogic', () => {})- it('does not reload analytics queries when polling only changes sync status', async () => {+ it('keeps analytics queries during background source changes and supports manual refresh', async () => {const source = {id: 'meta-health',source_type: 'MetaAds',@@ -761,7 +765,7 @@ describe('marketingAnalyticsLogic', () => {id: name,name,should_sync: true,- last_synced_at: dayjs(),+ last_synced_at: undefined,})),} as ExternalDataSourcelet results = [source]@@ -775,9 +779,23 @@ describe('marketingAnalyticsLogic', () => {})logic = marketingAnalyticsLogic()logic.mount()- await expectLogic(logic).toDispatchActions(['reloadAll']).toFinishAllListeners()+ await expectLogic(logic).toNotHaveDispatchedActions(['reloadAll']).toFinishAllListeners()+ const collection = dataNodeCollectionLogic({ key: MARKETING_ANALYTICS_DATA_COLLECTION_NODE_ID })+ const loadData = jest.fn()+ collection.actions.mountDataNode('marketing-cost', { id: 'marketing-cost', loadData, cancelQuery: jest.fn() })await expectLogic(logic, () => logic.actions.loadSources()).toFinishAllListeners()- results = [{ ...source, status: ExternalDataJobStatus.Completed }]+ results = [+ {+ ...source,+ status: ExternalDataJobStatus.Completed,+ schemas: source.schemas.map((schema) => ({ ...schema, last_synced_at: dayjs() })),+ },+ ]+ await expectLogic(logic, () => logic.actions.loadSources())+ .toFinishAllListeners()+ .toNotHaveDispatchedActions(['reloadAll'])+ .toDispatchActions(['loadDatabase', 'loadSourceValidation'])+ results = [{ ...source, schemas: source.schemas.map((schema) => ({ ...schema, should_sync: false })) }]await expectLogic(logic, () => logic.actions.loadSources()).toFinishAllListeners().toNotHaveDispatchedActions(['reloadAll'])@@ -785,7 +803,11 @@ describe('marketingAnalyticsLogic', () => {results = []await expectLogic(logic, () => logic.actions.loadSources()).toFinishAllListeners()- .toDispatchActions(['reloadAll'])+ .toNotHaveDispatchedActions(['reloadAll'])+ expect(loadData).not.toHaveBeenCalled()+ await expectLogic(logic, () => logic.actions.reloadAll()).toFinishAllListeners()+ expect(loadData).toHaveBeenCalledWith('force_async')+ collection.actions.unmountDataNode('marketing-cost')})it.each([diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.tsindex 54d9979b3581..6bc83d7c4fbc 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts@@ -1879,7 +1879,7 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([if (cache.sourceConfigurationKey !== sourceConfigurationKey) {cache.sourceConfigurationKey = sourceConfigurationKeyactions.loadDatabase()- actions.reloadAll()+ actions.loadSourceValidation()} else if (cache.sourceSyncKey !== sourceSyncKey) {actions.loadDatabase()actions.loadSourceValidation()