: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
feat(marketing): group connection problems by integration (#124154)
Javier Bahamondesac3f182412ac
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a86c9bdbcc97..59d51a23025c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13881,9 +13881,9 @@ snapshots:scenes-app-marketing-analytics-source-setup-panel--dismissed-suggestions--light:hash: v1.k794b7964.ffc8c430ea05caddb72061b672439ea70dc112d2f895c53787c361124608e571.nDJqea2Pblrsydv-gbKq_QaZX36jOZkbXu-3f9ZMdf8scenes-app-marketing-analytics-source-setup-panel--grouped-connection-errors--dark:- hash: v1.k794b7964.58406eca76832c792faa22cf846db49e00ff98ffc4ecc380cb27e89fd698496c.Hz5peryxG8f1PucOohQaTe2h_vqMIyfLgC232hAL8go+ hash: v1.k794b7964.68b2e19b64b6b3482b605d965e19d408bdd00aca2de1f9cb853dcad8ed0bd30f.Hc6ivLXj-dyjb0CUNa-EQD4dgji0Z7_ioPqGol-PmkIscenes-app-marketing-analytics-source-setup-panel--grouped-connection-errors--light:- hash: v1.k794b7964.c28f2e8f7855f64c39e9a3956532954a3a137147d169b7c2ed93917551832003.BKiu2w94wqhM9szakLV-25ysRe9NT458zSPMo21pJ-w+ hash: v1.k794b7964.8cf42a35b54033d8c659ee1e76e6fbdffc59ea2840efe0fc17bb7f7b8be940b7.Vsq5TcHrrBplij7oqZuttBR7Tc_sBdn9diwqaiNtyUsscenes-app-marketing-analytics-source-setup-panel--missing-connection-action--dark:hash: v1.k794b7964.82381c943a3afaf4bcd1ac432a9a1c1f4e23b49bf9f097126fa973a7d96ca06c.xtPZUVhPcOse-Kb3u0DCpuiICW2SkFiydtZA6pv4XxEscenes-app-marketing-analytics-source-setup-panel--missing-connection-action--light:@@ -13917,13 +13917,13 @@ snapshots:scenes-app-marketing-analytics-source-setup-panel--syncing--light:hash: v1.k794b7964.26d2bb305834706822eb7537a147d8c462c6101f323bb676cd3b9ddd03206922.3rBhEq__zEDZJcyu61FZSCughF7FB0-jd_CFRl7rCw0scenes-app-marketing-analytics-source-status--connection-already-in-panel--dark:- hash: v1.k794b7964.b4c0bc2c8615a9f1eb803ded13ec684d5a87dbbe9d7c2c80f246dd9752837a97.Tgs6gYhsP2gjy8I_WMmn3tuSp-cCtyOVJFmfEbgNd1M+ hash: v1.k794b7964.42ad088133954bb50c4dc8245b747407db9d22a37370336cd9ddef43e1276967.l3wgjC2b8-2wnXwPl8z5arOy8EsweTVUGQltzxPTfG0scenes-app-marketing-analytics-source-status--connection-already-in-panel--light:- hash: v1.k794b7964.2c5a657394b08029711b2c4d6e6239fd070ee90f71939bb9e35d471799c8406a.pLED3ZeNKP0ktwUdsyURrSb4QPokSrYpSRbiXmBImSk+ hash: v1.k794b7964.03ead1060f01ef891c8168140c59ae404ea5b64527a10ef04ada8c9d56d80a45.XuwRjNmmTxy0lhwdBWMfzQDBxpaFZGP-kN8VxTKg7j8scenes-app-marketing-analytics-source-status--source-issues--dark:- hash: v1.k794b7964.d2057a7b1316abc7100c30b86214f5eb891f35b01c19e899a33a3b9164fc4cc4.YhYj7qFW2Z65don1TkJCwtepa3O1JZOcF3_56hu3Tf0+ hash: v1.k794b7964.ee7b5217582fc29aff8029bdb001535fbddadb47e0f4804d3abedf5d314ff319.EaCh3aR4700yOrjbK3KaXgMQVsvG-ZsD1tuVISai6r0scenes-app-marketing-analytics-source-status--source-issues--light:- hash: v1.k794b7964.4eb5be20ab5424108e909aaa65495dd7a5dfb4f38b029a776b20f342b11b2d80.OuI8j51vqJlLwrue-jStdSchUhd0un0cOQo4GIxQveU+ hash: v1.k794b7964.f0892901fe7d162468fc7d1a74a63399dc8f87554120802c8b21f1b3c45b37aa.hO0Zh17xrOXQz4gG2fEoqvrVH4esn_sh6XvmvITrxQoscenes-app-marketing-analytics-table-scrolling--scrollable-rows--dark:hash: v1.k794b7964.3c54ce90caac67d3ad1d2f7faef547a79f6bbb514ffcda9d610fa3f56e170468.dys_SI3zdCZYMnc4Jt9M45lJxWqvQ-1R-3n550vG9kQscenes-app-marketing-analytics-table-scrolling--scrollable-rows--light:diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsSourceStatusBanner.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsSourceStatusBanner.tsxindex eddd2bd373c8..ec8c1744833d 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsSourceStatusBanner.tsx+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsSourceStatusBanner.tsx@@ -2,11 +2,12 @@ import { useValues } from 'kea'import { LemonBanner } from '@posthog/lemon-ui'-import { Link } from 'lib/lemon-ui/Link/Link'import { urls } from 'scenes/urls'import { ExternalDataSchemaStatus } from '~/types'+import { SourceSetupPanel } from 'products/marketing_analytics/frontend/dashboard/SourceSetupPanel'+import { MarketingSourceStatus, marketingAnalyticsLogic } from '../logic/marketingAnalyticsLogic'import { nativeSourceDisplayLabel } from '../logic/utils'@@ -19,9 +20,9 @@ export const MarketingAnalyticsSourceStatusBanner = ({const sourcesWithIssues = allAvailableSourcesWithStatus.filter((source) => !hiddenSourceIds.includes(source.id))+ // Routine incremental syncs set Running too, and the panel's syncing copy is about the first sync..filter((source) =>- source.status === 'Running' ||source.status === 'Failed' ||source.status === 'Paused' ||source.status === 'Cancelled' ||@@ -33,39 +34,43 @@ export const MarketingAnalyticsSourceStatusBanner = ({return null}- const hasErrors = sourcesWithIssues.some(- ({ status }) => status === ExternalDataSchemaStatus.Failed || status === MarketingSourceStatus.Error- )- const hasWarnings =- sourceValidationError ||- sourcesWithIssues.some(- ({ status }) => status === MarketingSourceStatus.Warning || status === ExternalDataSchemaStatus.Cancelled- )- const bannerType = hasErrors ? 'error' : hasWarnings ? 'warning' : 'info'-return (- <LemonBanner type={bannerType} className="mb-2 mt-4">- <div className="space-y-2 min-w-0 break-words">- {sourceValidationError && (- <div>Could not check source configuration. Reload the dashboard to try again.</div>- )}- {sourcesWithIssues.map((source) => (- <div key={source.id}>- <Link- to={- source.type === 'native'- ? urls.dataWarehouseSource(`managed-${source.id}`)- : urls.settings('environment-marketing-analytics')- }- data-attr="marketing-source-status-settings"- >- {source.type === 'native' ? nativeSourceDisplayLabel(source.source_type) : source.name}- {source.prefix ? ` (${source.prefix})` : ''}- </Link>- <span>{`: ${source.statusMessage}`}</span>- </div>- ))}- </div>- </LemonBanner>+ <div className="mb-2">+ {sourceValidationError && (+ <LemonBanner type="warning" className="mt-4">+ Could not check source configuration. Reload the dashboard to try again.+ </LemonBanner>+ )}+ {sourcesWithIssues.length > 0 && (+ <SourceSetupPanel+ state="waiting"+ compact+ showIllustration={false}+ manageSourceDataAttr="marketing-source-status-settings"+ expansionKey="source-status"+ title="Some connections need attention"+ description="Fix these connections to keep your spend data up to date."+ connections={sourcesWithIssues.map((source) => ({+ id: source.id,+ name:+ source.type === 'native'+ ? source.prefix ||+ `${nativeSourceDisplayLabel(source.source_type)} (${source.id.slice(0, 8)})`+ : source.name,+ sourceType: source.source_type,+ status:+ source.status === ExternalDataSchemaStatus.Failed ||+ source.status === MarketingSourceStatus.Error+ ? 'Sync failed'+ : 'Needs attention',+ detail: source.statusMessage,+ manageUrl:+ source.type === 'native'+ ? urls.dataWarehouseSource(`managed-${source.id}`)+ : urls.settings('environment-marketing-analytics'),+ }))}+ />+ )}+ </div>)}diff --git a/products/marketing_analytics/frontend/dashboard/MarketingAnalyticsSourceStatusBanner.stories.tsx b/products/marketing_analytics/frontend/dashboard/MarketingAnalyticsSourceStatusBanner.stories.tsxindex 08a7d71f344f..6238a996734e 100644--- a/products/marketing_analytics/frontend/dashboard/MarketingAnalyticsSourceStatusBanner.stories.tsx+++ b/products/marketing_analytics/frontend/dashboard/MarketingAnalyticsSourceStatusBanner.stories.tsx@@ -50,7 +50,13 @@ const meta: Meta<typeof MarketingAnalyticsSourceStatusBanner> = {},},],- '/api/projects/:team_id/external_data_sources/wizard/': () => [200, {}],+ '/api/projects/:team_id/external_data_sources/wizard/': () => [+ 200,+ {+ GoogleAds: { iconPath: '/static/services/google-ads.png' },+ OpenAIAds: { iconPath: '/static/services/openai_ads.svg' },+ },+ ],'/api/environments/:team_id/external_data_sources/': () => [200,{diff --git a/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.stories.tsx b/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.stories.tsxindex 732a7b579ff4..b3776f27c0b2 100644--- a/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.stories.tsx+++ b/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.stories.tsx@@ -173,7 +173,7 @@ export const GroupedConnectionErrors: Story = {id: 'example-google-two',name: 'Example search',sourceType: 'GoogleAds',- status: 'Needs attention',+ status: 'Sync failed',detail: 'campaign_overview_stats: sync failed. Review the error in the source’s Schemas tab.',},{diff --git a/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.tsx b/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.tsxindex 55a5ec02c308..e244e481cf2e 100644--- a/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.tsx+++ b/products/marketing_analytics/frontend/dashboard/SourceSetupPanel.tsx@@ -1,4 +1,4 @@-import { useValues } from 'kea'+import { useActions, useValues } from 'kea'import type { ReactNode } from 'react'import * as moneyPng from '@posthog/brand/hoggies/png/money'@@ -14,8 +14,15 @@ import { nativeSourceDisplayLabel } from 'scenes/web-analytics/tabs/marketing-animport { SourceIcon } from 'products/data_warehouse/frontend/shared/components/SourceIcon'+import { expandedSourceTypes, sourceConnectionGroupsLogic } from './sourceConnectionGroupsLogic'+const HedgehogMoney = pngHoggie(moneyPng)+type SourceConnectionStatus = 'Connected' | 'Syncing' | 'Needs attention' | 'Sync failed'++const needsAction = (status: SourceConnectionStatus): boolean =>+ status === 'Needs attention' || status === 'Sync failed'+export interface SourceSetupPanelProps {state: 'checking' | 'scanning' | 'suggestions' | 'empty' | 'error' | 'waiting' | 'dismissed'suggestions?: Suggestion[]@@ -23,10 +30,17 @@ export interface SourceSetupPanelProps {id: stringname: stringsourceType: string- status: 'Connected' | 'Syncing' | 'Needs attention'+ status: SourceConnectionStatusdetail: string+ manageUrl?: string+ action?: ReactNode}[]+ manageSourceDataAttr?: string+ expansionKey?: stringcompact?: boolean+ title?: string+ description?: string+ showIllustration?: booleanfooter?: ReactNodeheaderAction?: ReactNodeonRetry?: () => void@@ -40,9 +54,14 @@ export function SourceSetupPanel({state,suggestions = [],connections = [],+ manageSourceDataAttr = 'marketing-connection-manage-source',+ expansionKey = 'setup',footer,headerAction,compact = false,+ title: titleOverride,+ description: descriptionOverride,+ showIllustration = true,onRetry,rescanLoading = false,rescanDisabledReason,@@ -50,9 +69,23 @@ export function SourceSetupPanel({onRestore,}: SourceSetupPanelProps): JSX.Element {const { featureFlags } = useValues(featureFlagLogic)+ const sourceTypes = Array.from(new Set(connections.map((connection) => connection.sourceType)))+ const sourceTypesNeedingAction = Array.from(+ new Set(+ connections+ .filter((connection) => needsAction(connection.status))+ .map((connection) => connection.sourceType)+ )+ )+ const groupsLogic = sourceConnectionGroupsLogic({ expansionKey })+ const { expansion } = useValues(groupsLogic)+ const expandedGroups = expandedSourceTypes(expansion, sourceTypes, sourceTypesNeedingAction)+ const { setExpandedSourceTypes } = useActions(groupsLogic)+ const hasConnectionsToFix = connections.some((connection) => needsAction(connection.status))const busy = state === 'checking' || state === 'scanning'const title =- state === 'checking'+ titleOverride ??+ (state === 'checking'? 'Checking your connections': state === 'scanning'? 'Finding your ad platforms'@@ -63,12 +96,13 @@ export function SourceSetupPanel({: state === 'error'? 'Could not check your events': state === 'waiting'- ? connections.some((connection) => connection.status === 'Needs attention')+ ? hasConnectionsToFix? 'Some connections need attention': 'Your connections are getting ready'- : 'Connect your ad platforms'+ : 'Connect your ad platforms')const description =- state === 'checking'+ descriptionOverride ??+ (state === 'checking'? 'Looking for connected ad platforms.': state === 'scanning'? 'Checking campaign tracking in events from the last 7 days.'@@ -79,10 +113,10 @@ export function SourceSetupPanel({: state === 'error'? 'Try checking your events again, or choose an integration manually.': state === 'waiting'- ? connections.some((connection) => connection.status === 'Needs attention')+ ? hasConnectionsToFix? 'Check the connections below to finish setting up your spend data.': 'Spend and ad performance will appear after the first sync finishes. You can connect other platforms while you wait.'- : `We found campaign tracking from ${suggestions.length} ${suggestions.length === 1 ? 'platform' : 'platforms'} in your latest event scan.`+ : `We found campaign tracking from ${suggestions.length} ${suggestions.length === 1 ? 'platform' : 'platforms'} in your latest event scan.`)const rescanButton =!busy && onRetry ? (@@ -114,7 +148,9 @@ export function SourceSetupPanel({<h3 className={compact ? 'text-base mb-1' : 'mb-2'}>{title}</h3><p className="text-secondary mb-0 max-w-xl">{description}</p></div>- {!busy && <HedgehogMoney className={compact ? 'w-12 shrink-0' : 'w-20 shrink-0'} />}+ {!busy && showIllustration && (+ <HedgehogMoney className={compact ? 'w-12 shrink-0' : 'w-20 shrink-0'} />+ )}{headerAction}</div>{state === 'empty' && (@@ -141,68 +177,72 @@ export function SourceSetupPanel({<LemonCollapseembeddedmultiple- defaultActiveKeys={[connections[0].sourceType]}- panels={Array.from(new Set(connections.map((connection) => connection.sourceType))).map(- (sourceType) => {- const group = connections.filter((connection) => connection.sourceType === sourceType)- return {- key: sourceType,- header: {- className: 'focus-visible:-outline-offset-2',- children: (- <span className="flex flex-wrap items-center gap-2 min-w-0">- <SourceIcon type={sourceType} size="small" disableTooltip />- <strong>{nativeSourceDisplayLabel(sourceType)}</strong>- <span className="text-secondary">{`${group.length} ${group.length === 1 ? 'connection' : 'connections'}`}</span>- </span>- ),- },- content: (- <div className="divide-y">- {group.map((connection) => (- <div- key={connection.id}- className="flex flex-wrap items-start justify-between gap-3 py-3"- >- <div className="min-w-0 flex-1 basis-64 space-y-2 break-words">- <div className="flex items-center flex-wrap gap-2">- <strong className="break-all">{connection.name}</strong>- <LemonTag- type={- connection.status === 'Needs attention'- ? 'warning'- : 'info'- }- >- {connection.status}- </LemonTag>- </div>- <p className="text-secondary text-sm mb-0 whitespace-pre-line">- {connection.detail}- </p>+ activeKeys={expandedGroups}+ onChange={(expanded) => setExpandedSourceTypes(expanded, sourceTypes)}+ panels={sourceTypes.map((sourceType) => {+ const group = connections.filter((connection) => connection.sourceType === sourceType)+ return {+ key: sourceType,+ header: {+ className: 'focus-visible:-outline-offset-2',+ children: (+ <span className="flex flex-wrap items-center gap-2 min-w-0">+ <SourceIcon type={sourceType} size="small" disableTooltip />+ <strong>{nativeSourceDisplayLabel(sourceType)}</strong>+ <span className="text-secondary">{`${group.length} ${group.length === 1 ? 'connection' : 'connections'}`}</span>+ </span>+ ),+ },+ content: (+ <div className="divide-y">+ {group.map((connection) => (+ <div+ key={connection.id}+ className="flex flex-wrap items-start justify-between gap-3 py-3"+ >+ <div className="min-w-0 flex-1 basis-64 space-y-2 break-words">+ <div className="flex items-center flex-wrap gap-2">+ <strong className="break-all">{connection.name}</strong>+ <LemonTag+ type={+ connection.status === 'Sync failed'+ ? 'danger'+ : connection.status === 'Needs attention'+ ? 'warning'+ : 'info'+ }+ >+ {connection.status}+ </LemonTag></div>- {connection.status === 'Needs attention' && (- <div className="shrink-0 ml-auto">- <LemonButton- type="secondary"- size="small"- to={urls.dataWarehouseSource(- `managed-${connection.id}`- )}- targetBlank- data-attr="marketing-connection-manage-source"- >- Manage source- </LemonButton>- </div>- )}+ <p className="text-secondary text-sm mb-0 whitespace-pre-line">+ {connection.detail}+ </p></div>- ))}- </div>- ),- }+ {connection.action ? (+ <div className="shrink-0 ml-auto">{connection.action}</div>+ ) : needsAction(connection.status) ? (+ <div className="shrink-0 ml-auto">+ <LemonButton+ type="secondary"+ size="small"+ to={+ connection.manageUrl ??+ urls.dataWarehouseSource(`managed-${connection.id}`)+ }+ targetBlank+ data-attr={manageSourceDataAttr}+ >+ Manage source+ </LemonButton>+ </div>+ ) : null}+ </div>+ ))}+ </div>+ ),}- )}+ })}/>)}{suggestions.length > 0 && !busy && (@@ -287,7 +327,7 @@ export function SourceSetupPanel({<span>Spend data appears after the first sync finishes.</span></div>)}- {state === 'waiting' && connections.some((connection) => connection.status !== 'Needs attention') && (+ {state === 'waiting' && connections.some((connection) => !needsAction(connection.status)) && (<div className="flex items-start gap-2 text-secondary text-sm"><IconCheckCircle className="shrink-0 mt-0.5" /><span>You can leave this page. Your import will continue in the background.</span>diff --git a/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.test.ts b/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.test.tsnew file mode 100644index 000000000000..766256e5f2db--- /dev/null+++ b/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.test.ts@@ -0,0 +1,44 @@+import { expandedSourceTypes } from './sourceConnectionGroupsLogic'++describe('expandedSourceTypes', () => {+ it.each([+ ['opens the first group before any toggle', null, ['GoogleAds', 'MetaAds'], [], ['GoogleAds']],+ [+ 'opens every group that needs action before any toggle',+ null,+ ['GoogleAds', 'MetaAds', 'OpenAIAds'],+ ['OpenAIAds', 'MetaAds'],+ ['MetaAds', 'OpenAIAds'],+ ],+ [+ 'opens a new integration when only stale groups were open',+ { expanded: ['BingAds'], seen: ['BingAds'] },+ ['GoogleAds'],+ [],+ ['GoogleAds'],+ ],+ [+ 'opens a new integration after the user collapsed every group',+ { expanded: [], seen: ['BingAds'] },+ ['GoogleAds'],+ [],+ ['GoogleAds'],+ ],+ [+ 'keeps every group closed when the user collapsed them',+ { expanded: [], seen: ['GoogleAds', 'MetaAds'] },+ ['GoogleAds', 'MetaAds'],+ [],+ [],+ ],+ [+ 'drops stale groups and keeps the open ones',+ { expanded: ['BingAds', 'MetaAds'], seen: ['BingAds', 'GoogleAds', 'MetaAds'] },+ ['GoogleAds', 'MetaAds'],+ [],+ ['MetaAds'],+ ],+ ])('%s', (_, expansion, sourceTypes, sourceTypesNeedingAction, expected) => {+ expect(expandedSourceTypes(expansion, sourceTypes, sourceTypesNeedingAction)).toEqual(expected)+ })+})diff --git a/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.ts b/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.tsnew file mode 100644index 000000000000..3c58cdffc590--- /dev/null+++ b/products/marketing_analytics/frontend/dashboard/sourceConnectionGroupsLogic.ts@@ -0,0 +1,42 @@+import { MakeLogicType, actions, kea, key, path, props, reducers } from 'kea'++type SourceConnectionGroupsProps = { expansionKey: string }+export type GroupExpansion = { expanded: string[]; seen: string[] }++export function expandedSourceTypes(+ expansion: GroupExpansion | null,+ sourceTypes: string[],+ sourceTypesNeedingAction: string[]+): string[] {+ if (!expansion) {+ const needingAction = sourceTypes.filter((sourceType) => sourceTypesNeedingAction.includes(sourceType))+ return needingAction.length > 0 ? needingAction : sourceTypes.slice(0, 1)+ }+ // Integrations that appeared after the last toggle open, so a new problem is never hidden.+ const unseen = sourceTypes.filter((sourceType) => !expansion.seen.includes(sourceType))+ return sourceTypes.filter((sourceType) => expansion.expanded.includes(sourceType) || unseen.includes(sourceType))+}++export const sourceConnectionGroupsLogic = kea<+ MakeLogicType<+ { expansion: GroupExpansion | null },+ {+ setExpandedSourceTypes: (expanded: string[], seen: string[]) => GroupExpansion+ },+ SourceConnectionGroupsProps+ >+>([+ props({} as SourceConnectionGroupsProps),+ key((props) => props.expansionKey),+ path((key) => ['products', 'marketingAnalytics', 'sourceConnectionGroups', key]),+ actions({+ setExpandedSourceTypes: (expanded: string[], seen: string[]) => ({ expanded, seen }),+ }),+ reducers({+ expansion: [+ null as GroupExpansion | null,+ { persist: true },+ { setExpandedSourceTypes: (_, expansion) => expansion },+ ],+ }),+])