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): keep ad performance tiles mounted while sources refresh (#118506)

Javier Bahamondesf3ef5919700f
diff --git a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
index e63e20270e9d..f3b4a4131467 100644
--- a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
+++ b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
@@ -262,8 +262,14 @@ const MarketingAnalyticsDashboardSkeleton = (): JSX.Element => (
const LegacyMarketingAnalyticsDashboard = (): JSX.Element => {
const { featureFlags } = useValues(featureFlagLogic)
- const { hasSources, hasNoConfiguredSources, loading, isAdPerformance, includeConversionGoals } =
- useValues(marketingAnalyticsLogic)
+ const {
+ hasSources,
+ hasNoConfiguredSources,
+ loading,
+ sourcesInitialLoading,
+ isAdPerformance,
+ includeConversionGoals,
+ } = useValues(marketingAnalyticsLogic)
const { setAdPerformanceConversionGoals } = useActions(marketingAnalyticsLogic)
const { loadSources } = useActions(sourcesDataLogic)
const { conversion_goals } = useValues(marketingAnalyticsSettingsLogic)
@@ -326,7 +332,9 @@ const LegacyMarketingAnalyticsDashboard = (): JSX.Element => {
)
}
- if (loading) {
+ // Only the first load gets the skeleton: a background refresh (window focus, sync polling)
+ // also sets `loading`, and swapping the tiles for the skeleton would remount and refetch them.
+ if (sourcesInitialLoading) {
return (
<>
{feedbackBanner}
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.ts
index c99b2d24d336..760748db69fa 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
@@ -93,6 +93,27 @@ describe('marketingAnalyticsLogic', () => {
})
})
+ it('keeps the campaign breakdown query while sources refresh in the background', async () => {
+ logic = marketingAnalyticsLogic()
+ logic.mount()
+ const tiles = marketingAnalyticsTilesLogic()
+ tiles.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ const breakdown = tiles.values.campaignCostsBreakdown
+ expect(breakdown).not.toBeNull()
+
+ // A window focus or sync poll reloads sources. The table must not be dropped
+ // (and remounted) while the refresh is in flight.
+ logic.actions.loadSources()
+ expect(logic.values.loading).toBe(true)
+ expect(tiles.values.campaignCostsBreakdown).toBe(breakdown)
+
+ await expectLogic(logic).toFinishAllListeners()
+ // Deep-equal so dataNodeLogic sees the same query and doesn't refetch.
+ expect(tiles.values.campaignCostsBreakdown).toEqual(breakdown)
+ tiles.unmount()
+ })
+
it('keeps a connected Search Console integration selected after refreshing sources', async () => {
logic = marketingAnalyticsLogic()
logic.mount()
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.ts
index f4b9ba4421a3..64b7d3e51cfc 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
@@ -421,6 +421,7 @@ export interface marketingAnalyticsLogicValues {
sourceValidationError: string | null
sourceValidationErrors: SourceValidationApi['errors_by_source']
sourceValidationLoading: boolean
+ sourcesInitialLoading: boolean
tileColumnSelection: validColumnsForTiles
unconfiguredNativeSources: ExternalDataSource[]
uniqueConversionGoalName: string
@@ -701,6 +702,10 @@ export interface marketingAnalyticsLogicMeta {
) => string
nativeSourcesHierarchyStatus: (validNativeSources: NativeSource[]) => NativeSourceHierarchyStatus[]
loading: (dataWarehouseSourcesLoading: boolean) => boolean
+ sourcesInitialLoading: (
+ dataWarehouseSourcesLoading: boolean,
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null
+ ) => boolean
allAvailableSources: (
validExternalTables: ExternalTable[],
validNativeSources: NativeSource[]
@@ -1353,6 +1358,16 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
(s) => [s.dataWarehouseSourcesLoading],
(dataWarehouseSourcesLoading: boolean) => dataWarehouseSourcesLoading,
],
+ // `loading` is also true while sources refresh in the background (window focus, sync
+ // polling). Views that would unmount their content on `loading` should gate on this
+ // instead, so only the first load shows a placeholder and refreshes keep the data in place.
+ sourcesInitialLoading: [
+ (s) => [s.dataWarehouseSourcesLoading, s.dataWarehouseSources],
+ (
+ dataWarehouseSourcesLoading: boolean,
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null
+ ): boolean => dataWarehouseSourcesLoading && !dataWarehouseSources,
+ ],
allAvailableSources: [
(s) => [s.validExternalTables, s.validNativeSources],
(validExternalTables: ExternalTable[], validNativeSources: NativeSource[]) => {
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTilesLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTilesLogic.ts
index 001b765f9c00..585e053bb297 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTilesLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsTilesLogic.ts
@@ -87,6 +87,7 @@ export interface marketingAnalyticsTilesLogicValues {
integrationFilter: IntegrationFilter // marketingAnalyticsLogic
loading: boolean // marketingAnalyticsLogic
shouldFilterTestAccounts: boolean // marketingAnalyticsLogic
+ sourcesInitialLoading: boolean // marketingAnalyticsLogic
tileColumnSelection: validColumnsForTiles // marketingAnalyticsLogic
defaultColumns: string[] // marketingAnalyticsTableLogic
query: DataTableNode | null // marketingAnalyticsTableLogic
@@ -136,7 +137,7 @@ export interface marketingAnalyticsTilesLogicMeta {
campaignBreakdownTile: QueryTile | null
) => QueryTile[]
campaignCostsBreakdown: (
- loading: boolean,
+ sourcesInitialLoading: boolean,
query: DataTableNode | null,
dateFilter: {
dateFrom: string | null
@@ -171,6 +172,7 @@ export const marketingAnalyticsTilesLogic = kea<marketingAnalyticsTilesLogicType
'dateFilter',
'createMarketingDataWarehouseNodes',
'loading',
+ 'sourcesInitialLoading',
'draftConversionGoal',
'chartDisplayType',
'tileColumnSelection',
@@ -404,7 +406,9 @@ export const marketingAnalyticsTilesLogic = kea<marketingAnalyticsTilesLogicType
],
campaignCostsBreakdown: [
(s) => [
- s.loading,
+ // Not `loading`: nulling the query on every background refresh unmounts the
+ // table and refetches it each time the user returns to the tab.
+ s.sourcesInitialLoading,
s.query,
s.dateFilter,
s.draftConversionGoal,
@@ -416,7 +420,7 @@ export const marketingAnalyticsTilesLogic = kea<marketingAnalyticsTilesLogicType
s.includeConversionGoals,
],
(
- loading: boolean,
+ sourcesInitialLoading: boolean,
query: DataTableNode,
dateFilter: { dateFrom: string; dateTo: string; interval: IntervalType },
draftConversionGoal: ConversionGoalFilter | null,
@@ -427,7 +431,7 @@ export const marketingAnalyticsTilesLogic = kea<marketingAnalyticsTilesLogicType
shouldFilterTestAccounts: boolean,
includeConversionGoals: boolean
): DataTableNode | null => {
- if (loading) {
+ if (sourcesInitialLoading) {
return null
}
let marketingQuery = query?.source as MarketingAnalyticsTableQuery | undefined