Skip to content

: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.

fix(marketing): wait for source loading before conversion scan (#122364)

Javier Bahamondesda71722513d4
diff --git a/docs/internal/marketing-conversion-setup-ai-plan.md b/docs/internal/marketing-conversion-setup-ai-plan.md
index c5e8b3aec8d0..4b69cefa9686 100644
--- a/docs/internal/marketing-conversion-setup-ai-plan.md
+++ b/docs/internal/marketing-conversion-setup-ai-plan.md
@@ -13,6 +13,8 @@ The existing Marketing analytics setup flag must also be enabled.
## Analysis lifecycle
The first visit to Setup or the source onboarding dashboard starts an analysis once, after loading the saved state and checking permission to generate.
+The dashboard waits for the project settings and source connections to load successfully before mounting recommendations or starting the first scan.
+Background source refreshes keep the recommendations visible while the last successful source response remains available.
Analyses use a 30-day catalog recency cutoff until one completes successfully; later analyses use 14 days and require an explicit **Scan again** action.
The cutoff uses the catalog’s last-seen timestamp when available; it does not query or count events in that period.
Definitions with no last-seen timestamp remain eligible.
diff --git a/products/marketing_analytics/frontend/setup/DashboardConversionRecommendations.tsx b/products/marketing_analytics/frontend/setup/DashboardConversionRecommendations.tsx
index a88905ff5f4c..e7591b12766a 100644
--- a/products/marketing_analytics/frontend/setup/DashboardConversionRecommendations.tsx
+++ b/products/marketing_analytics/frontend/setup/DashboardConversionRecommendations.tsx
@@ -6,6 +6,8 @@ import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
import { marketingAnalyticsLogic } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic'
+import { sourcesDataLogic } from 'products/data_warehouse/frontend/shared/logics/sourcesDataLogic'
+
import { conversionGoalFormLogic } from './conversionGoalFormLogic'
import { ConversionGoalRecommendations } from './ConversionGoalRecommendations'
import { DashboardSetupPrompt } from './DashboardSetupPrompt'
@@ -13,7 +15,8 @@ import { dashboardSetupPromptsLogic } from './dashboardSetupPromptsLogic'
export function DashboardConversionRecommendations(): JSX.Element | null {
const { setupEnabled } = useValues(marketingAnalyticsLogic)
- const { currentTeamId } = useValues(teamLogic)
+ const { currentTeamId, currentTeam, currentTeamLoading } = useValues(teamLogic)
+ const { dataWarehouseSources, sourcesLoadError } = useValues(sourcesDataLogic)
const { user } = useValues(userLogic)
const { featureFlags } = useValues(featureFlagLogic)
const { openSetup } = useActions(dashboardSetupPromptsLogic({ projectId: currentTeamId ?? -1, userId: user?.uuid }))
@@ -21,7 +24,14 @@ export function DashboardConversionRecommendations(): JSX.Element | null {
conversionGoalFormLogic({ projectId: currentTeamId ?? -1 })
)
- if (!setupEnabled || !featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_CONVERSION_SETUP_AI]) {
+ if (
+ !setupEnabled ||
+ !featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_CONVERSION_SETUP_AI] ||
+ !currentTeam ||
+ currentTeamLoading ||
+ !dataWarehouseSources ||
+ sourcesLoadError
+ ) {
return null
}
diff --git a/products/marketing_analytics/frontend/setup/SetupConversionFlag.test.tsx b/products/marketing_analytics/frontend/setup/SetupConversionFlag.test.tsx
index 8537fb1064f0..56da043d4883 100644
--- a/products/marketing_analytics/frontend/setup/SetupConversionFlag.test.tsx
+++ b/products/marketing_analytics/frontend/setup/SetupConversionFlag.test.tsx
@@ -11,6 +11,8 @@ import { userLogic } from 'scenes/userLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { sourcesDataLogic } from 'products/data_warehouse/frontend/shared/logics/sourcesDataLogic'
+
import { ConversionGoalRecommendations } from './ConversionGoalRecommendations'
import { DashboardConversionRecommendations } from './DashboardConversionRecommendations'
import { DashboardSetupPrompt } from './DashboardSetupPrompt'
@@ -80,11 +82,41 @@ describe('conversion setup feature flag', () => {
[FEATURE_FLAGS.MARKETING_ANALYTICS_CONVERSION_SETUP_AI]: ai,
[FEATURE_FLAGS.MARKETING_ANALYTICS_SOURCE_ONBOARDING]: true,
})
+ sourcesDataLogic.mount()
+ sourcesDataLogic.actions.loadSourcesSuccess({ count: 0, next: null, previous: null, results: [] })
render(<DashboardConversionRecommendations />)
expect(!!screen.queryByText('Review recommendations')).toBe(visible)
expect(!!jest.mocked(ConversionGoalRecommendations).mock.calls.length).toBe(visible)
})
+ it('waits for sources and project settings before mounting the dashboard scan', () => {
+ featureFlagLogic.actions.setFeatureFlags([], {
+ [FEATURE_FLAGS.MARKETING_ANALYTICS_SETUP]: true,
+ [FEATURE_FLAGS.MARKETING_ANALYTICS_CONVERSION_SETUP_AI]: true,
+ })
+ sourcesDataLogic.mount()
+ const currentTeam = teamLogic.values.currentTeam!
+ const { rerender } = render(<DashboardConversionRecommendations />)
+ expect(ConversionGoalRecommendations).not.toHaveBeenCalled()
+
+ act(() => sourcesDataLogic.actions.loadSourcesFailure('Could not load sources'))
+ expect(screen.queryByText('Review recommendations')).not.toBeInTheDocument()
+
+ act(() => {
+ teamLogic.actions.loadCurrentTeam()
+ sourcesDataLogic.actions.loadSourcesSuccess({ count: 0, next: null, previous: null, results: [] })
+ })
+ expect(ConversionGoalRecommendations).not.toHaveBeenCalled()
+
+ act(() => teamLogic.actions.loadCurrentTeamSuccess(currentTeam))
+ expect(screen.getByText('Review recommendations')).toBeVisible()
+
+ jest.clearAllMocks()
+ act(() => sourcesDataLogic.actions.loadSources())
+ rerender(<DashboardConversionRecommendations />)
+ expect(screen.getByText('Review recommendations')).toBeVisible()
+ })
+
it('keeps dismissed sources accessible without Setup and restores them from Setup', () => {
featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.MARKETING_ANALYTICS_SETUP]: true })
render(