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.

feat(marketing-analytics): show the product empty state until a source exists (#90663)

Rafael Audibert6145870a6a0e
diff --git a/docs/internal/product-empty-state-adoption.md b/docs/internal/product-empty-state-adoption.md
index 5bb5db4fd786..5f0b14d01f95 100644
--- a/docs/internal/product-empty-state-adoption.md
+++ b/docs/internal/product-empty-state-adoption.md
@@ -59,7 +59,7 @@ Rows marked "in review" are not on `master` yet. See "Regenerating the lists" fo
| Web vitals | `frontend/src/scenes/web-analytics/WebAnalyticsScene.tsx` | on master |
| Data warehouse sources | `products/data_warehouse/frontend/scenes/SourcesScene/SourcesScene.tsx` | on master |
| Workflows | `products/workflows/frontend/WorkflowsScene.tsx` | on master |
-| Marketing analytics | `frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx` | in review |
+| Marketing analytics | `frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx` | on master |
| Customer analytics | `products/customer_analytics/frontend/CustomerAnalyticsScene.tsx` | in review |
| Actions | `products/actions/frontend/pages/Actions.tsx` | on master |
| Annotations | `frontend/src/scenes/annotations/Annotations.tsx` | on master |
diff --git a/frontend/package.json b/frontend/package.json
index f89185eb7352..6d13290b388f 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -117,6 +117,7 @@
"@posthog/products-live-debugger": "workspace:*",
"@posthog/products-logs": "workspace:*",
"@posthog/products-managed-migrations": "workspace:*",
+ "@posthog/products-marketing-analytics": "workspace:*",
"@posthog/products-mcp-analytics": "workspace:*",
"@posthog/products-mcp-store": "workspace:*",
"@posthog/products-messaging": "workspace:*",
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 1a7a8609ad5b..274d192472ff 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1836,6 +1836,10 @@ snapshots:
hash: v1.k794b7964.96e30395bc4290ad188a84e94f5d40d46f545a3223e4d13fe44737d322129e2f.kj5dwA7EuPOvu6YfDc2jc2s38u8BfXT1EcfPAMPztuM
components-product-empty-state--logs-needs-setup--light:
hash: v1.k794b7964.e48c85227bbcc871026a1cdf096c1cf21ab5a0504983d138048258516841b153.p74Gybn8AxHmoKKMNcSfmx6gTus5K56ARAEhsPYcxDY
+ components-product-empty-state--marketing-analytics-needs-setup--dark:
+ hash: v1.k794b7964.ce0aac7a759743749623867c4cea9529ecb3738a6f43eec92e962b4f6c1f1564.EM_vzdZrvKmEbge1FryouAY6DqEN4P1sL_eBrOWTZcY
+ components-product-empty-state--marketing-analytics-needs-setup--light:
+ hash: v1.k794b7964.0d1f0a6d68cc64cc406dbc57510707e9fcafd6a315193e6345e7168e9a38fe24.SeOl-kOg6cQqIgJKNCTRiXiSRvIv-2KHhg6y5hzhMe4
components-product-empty-state--mcp-analytics-needs-setup--dark:
hash: v1.k794b7964.96d4c2d4afe9d7834d3667aa266bafdcb7f8192e4c51927b7661824c9f982d97.leY0JcEWIDNFZQl9s4uuj96BWBHxb3cYGMaU3rJ0g0k
components-product-empty-state--mcp-analytics-needs-setup--light:
diff --git a/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx b/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx
index b5c14c42bc3c..5f18b597b97d 100644
--- a/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx
+++ b/frontend/src/layout/panel-layout/ProjectTree/defaultTree.tsx
@@ -112,7 +112,7 @@ const iconTypes: Record<FileSystemIconType, { icon: JSX.Element; iconColor?: Fil
},
marketing_analytics: {
icon: <IconMegaphone />,
- iconColor: ['var(--color-product-marketing-analytics-light)'],
+ iconColor: ['var(--color-product-marketing-analytics-light)', 'var(--color-product-marketing-analytics-dark)'],
},
managed_viewsets: {
icon: <IconDatabase />,
diff --git a/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx b/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
index a5242bd1be86..33116b4ba209 100644
--- a/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
+++ b/frontend/src/lib/components/ProductEmptyState/ProductEmptyState.stories.tsx
@@ -18,6 +18,7 @@ import { experimentsEmptyState } from 'products/experiments/frontend/emptyState/
import { featureFlagsEmptyState } from 'products/feature_flags/frontend/emptyState/featureFlagsEmptyState'
import { linksEmptyState } from 'products/links/frontend/emptyState/linksEmptyState'
import { logsEmptyState } from 'products/logs/frontend/emptyState/logsEmptyState'
+import { marketingAnalyticsEmptyState } from 'products/marketing_analytics/frontend/emptyState/marketingAnalyticsEmptyState'
import { mcpAnalyticsEmptyState } from 'products/mcp_analytics/frontend/emptyState/mcpAnalyticsEmptyState'
import { metricsEmptyState } from 'products/metrics/frontend/emptyState/metricsEmptyState'
import { productAnalyticsEmptyState } from 'products/product_analytics/frontend/emptyState/productAnalyticsEmptyState'
@@ -323,3 +324,18 @@ export const DataWarehouseNeedsSetup: ProductEmptyStateStory = productEmptyState
export const WorkflowsNeedsSetup: ProductEmptyStateStory = productEmptyStateStory(workflowsEmptyState, 'needs-setup', {
mocks: { get: { '/api/projects/:team_id/hog_flows/': [200, { count: 0, results: [] }] } },
})
+
+// Marketing analytics detection mirrors the scene logic's sources check; the
+// default query mocks answer its source queries with empty results.
+export const MarketingAnalyticsNeedsSetup: ProductEmptyStateStory = productEmptyStateStory(
+ marketingAnalyticsEmptyState,
+ 'needs-setup',
+ {
+ mocks: {
+ get: {
+ // nosemgrep: no-environments-api-urls-frontend -- the sources API is env-scoped, so the msw mock must match /api/environments to intercept it
+ '/api/environments/:team_id/external_data_sources/': [200, { results: [] }],
+ },
+ },
+ }
+)
diff --git a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
index 7e4c9ef494e2..31ed73fafd64 100644
--- a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
+++ b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx
@@ -25,6 +25,7 @@ import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollec
import { ProductKey } from '~/queries/schema/schema-general'
import { sourcesDataLogic } from 'products/data_warehouse/frontend/shared/logics/sourcesDataLogic'
+import { marketingAnalyticsEmptyState } from 'products/marketing_analytics/frontend/emptyState/marketingAnalyticsEmptyState'
import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
import { LegacyOAuthReconnectBanner } from '../web-analytics/tabs/marketing-analytics/frontend/components/LegacyOAuthReconnectBanner'
@@ -49,6 +50,7 @@ export const scene: SceneExport = {
component: MarketingAnalyticsScene,
logic: marketingAnalyticsLogic,
productKey: ProductKey.MARKETING_ANALYTICS,
+ emptyState: marketingAnalyticsEmptyState,
}
const QueryTileItem = ({ tile }: { tile: QueryTile }): JSX.Element => {
diff --git a/frontend/src/styles/base.scss b/frontend/src/styles/base.scss
index 114f207923f9..f0983198acb1 100644
--- a/frontend/src/styles/base.scss
+++ b/frontend/src/styles/base.scss
@@ -327,6 +327,7 @@
--color-product-logs-light: rgb(214 37 123);
--color-product-logs-dark: rgb(240 92 161);
--color-product-marketing-analytics-light: rgb(214 37 123);
+ --color-product-marketing-analytics-dark: rgb(240 92 161);
--color-product-live-debugger-light: rgb(76 14 200);
--color-product-feature-flags-light: rgb(48 171 198);
--color-product-experiments-light: rgb(182 42 217);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ca99c1026517..d88427f5bc3b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -428,7 +428,7 @@ importers:
version: 0.25.12
jest:
specifier: ^29.7.0
puppeteer:
specifier: 19.0.0
version: 19.0.0([email protected])
@@ -740,6 +740,9 @@ importers:
'@posthog/products-managed-migrations':
specifier: workspace:*
version: link:../products/managed_migrations
+ '@posthog/products-marketing-analytics':
+ specifier: workspace:*
+ version: link:../products/marketing_analytics
'@posthog/products-mcp-analytics':
specifier: workspace:*
version: link:../products/mcp_analytics
@@ -3774,7 +3777,29 @@ importers:
products/managed_warehouse: {}
- products/marketing_analytics: {}
+ products/marketing_analytics:
+ dependencies:
+ '@posthog/brand':
+ specifier: 'catalog:'
+ version: 0.10.0([email protected])
+ '@posthog/icons':
+ specifier: 'catalog:'
+ '@types/react':
+ specifier: 18.3.27
+ version: 18.3.27
+ clsx:
+ specifier: '*'
+ version: 2.1.1
+ kea:
+ specifier: 'catalog:'
+ version: 4.0.0-pre.6(patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected])
+ kea-subscriptions:
+ specifier: 'catalog:'
+ version: 3.0.1([email protected](patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected]))
+ react:
+ specifier: 18.3.1
+ version: 18.3.1
products/mcp_analytics:
dependencies:
diff --git a/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.scss b/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.scss
new file mode 100644
index 000000000000..2d32ac815ed4
--- /dev/null
+++ b/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.scss
@@ -0,0 +1,210 @@
+@import '../../../../frontend/src/lib/components/ProductEmptyState/previewMixins';
+
+.MarketingPreview {
+ --marketing-preview-accent: var(--empty-state-accent, var(--color-primary-500));
+
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+
+ // Hidden goal state. A direct child of .MarketingPreview so `:checked ~` reaches both cards.
+ &__checkbox {
+ position: absolute;
+ width: 0;
+ height: 0;
+ pointer-events: none;
+ opacity: 0;
+ }
+
+ &__channels,
+ &__stat {
+ overflow: hidden;
+ background: var(--color-bg-surface-primary);
+ border: 1px solid var(--color-border-primary);
+ border-radius: var(--radius);
+ }
+
+ &__stat {
+ padding: 0.5rem 0.75rem 0.625rem;
+ }
+
+ // Goal pairs are stacked on one grid cell and crossfaded, so swapping the
+ // goal never changes any element's size (no layout shift).
+ &__swap {
+ display: grid;
+ }
+
+ &__swap > * {
+ grid-area: 1 / 1;
+ min-width: 0;
+ }
+
+ &__when-purchases {
+ @include preview-swap-hidden;
+ }
+
+ &__when-signups {
+ @include preview-swap-visible;
+ }
+
+ &__head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0.5rem 0.75rem;
+ border-bottom: 1px solid var(--color-border-primary);
+ }
+
+ &__title {
+ display: flex;
+ gap: 0.375rem;
+ align-items: center;
+ font-size: 0.75rem;
+ font-weight: 600;
+ }
+
+ &__live-dot {
+ width: 7px;
+ height: 7px;
+ background: var(--marketing-preview-accent);
+ border-radius: 50%;
+ animation: MarketingPreview__pulse 2s ease-in-out infinite;
+ }
+
+ &__goal-bar {
+ display: flex;
+ gap: 0.5rem;
+ align-items: center;
+ padding: 0.4375rem 0.75rem;
+ border-bottom: 1px solid var(--color-border-primary);
+ }
+
+ &__goal-label {
+ font-size: 0.625rem;
+ color: var(--color-text-secondary);
+ }
+
+ &__goal-chip {
+ padding: 0.0625rem 0.4375rem;
+ font-family: var(--font-mono);
+ font-size: 0.625rem;
+ font-weight: 600;
+ cursor: pointer;
+ user-select: none;
+ background: color-mix(in oklab, var(--marketing-preview-accent) 10%, var(--color-bg-surface-primary));
+ border: 1px solid color-mix(in oklab, var(--marketing-preview-accent) 35%, transparent);
+ border-radius: 999px;
+ transition: background-color 150ms ease;
+
+ @include preview-accent-text(var(--marketing-preview-accent));
+ }
+
+ &__goal-chip:hover {
+ background: color-mix(in oklab, var(--marketing-preview-accent) 18%, var(--color-bg-surface-primary));
+ }
+
+ // Channels table
+
+ &__rows {
+ display: flex;
+ flex-direction: column;
+ padding: 0.25rem 0.5rem 0.375rem;
+ }
+
+ &__row {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) 4rem 3rem 3rem;
+ gap: 0.5rem;
+ padding: 0.3125rem 0.5rem;
+ font-size: 0.6875rem;
+ font-variant-numeric: tabular-nums;
+ text-align: right;
+ border-radius: var(--radius);
+ }
+
+ &__row > :first-child {
+ text-align: left;
+ }
+
+ &__row--header {
+ font-size: 0.5625rem;
+ font-weight: 700;
+ color: var(--color-text-tertiary);
+ text-transform: uppercase;
+ }
+
+ &__channel {
+ overflow: hidden;
+ font-weight: 600;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &__hint {
+ padding: 0.25rem 0.75rem 0.5rem;
+ font-size: 0.625rem;
+ color: var(--color-text-tertiary);
+ text-align: left;
+ }
+
+ // Stat card
+
+ &__spark-sub {
+ font-size: 0.6875rem;
+ font-weight: 400;
+ color: var(--color-text-secondary);
+ }
+
+ @include preview-sparkline;
+}
+
+// Purchases goal selected (user clicked the goal chip)
+
+.MarketingPreview__checkbox:checked ~ * .MarketingPreview__when-purchases {
+ @include preview-swap-visible;
+}
+
+.MarketingPreview__checkbox:checked ~ * .MarketingPreview__when-signups {
+ @include preview-swap-hidden;
+}
+
+// The checkbox stays keyboard-focusable while visually hidden, so the chip it labels
+// needs a visible focus indicator (WCAG 2.4.7).
+.MarketingPreview__checkbox:focus-visible ~ .MarketingPreview__channels .MarketingPreview__goal-chip {
+ outline: 2px solid var(--marketing-preview-accent);
+ outline-offset: 1px;
+}
+
+// Nudge attention at the goal chip until it's flipped.
+.MarketingPreview:not(.MarketingPreview--static)
+ .MarketingPreview__checkbox:not(:checked)
+ ~ .MarketingPreview__channels
+ .MarketingPreview__goal-chip {
+ animation: MarketingPreview__nudge 2.4s ease-in-out infinite;
+}
+
+@keyframes MarketingPreview__nudge {
+ 0%,
+ 100% {
+ box-shadow: 0 0 0 0 color-mix(in oklab, var(--marketing-preview-accent) 45%, transparent);
+ }
+
+ 50% {
+ box-shadow: 0 0 0 4px color-mix(in oklab, var(--marketing-preview-accent) 20%, transparent);
+ }
+}
+
+@keyframes MarketingPreview__pulse {
+ 0%,
+ 100% {
+ opacity: 1;
+ }
+
+ 50% {
+ opacity: 0.35;
+ }
+}
+
+// Storybook snapshots and reduced motion drop all ambient motion; clicking the
+// goal chip still flips the state (transitions only).
+@include preview-motion-guards('MarketingPreview');
diff --git a/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.tsx b/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.tsx
new file mode 100644
index 000000000000..2119d0649e85
--- /dev/null
+++ b/products/marketing_analytics/frontend/emptyState/MarketingAnalyticsPreview.tsx
@@ -0,0 +1,111 @@
+import './MarketingAnalyticsPreview.scss'
+
+import { LemonTag } from 'lib/lemon-ui/LemonTag'
+import { cn } from 'lib/utils/css-classes'
+import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
+
+/**
+ * Example-data preview for the marketing analytics empty state: ad channels with
+ * spend joined to a conversion goal. Clicking the goal chip swaps the goal from
+ * signups to purchases, and every conversion and ROAS figure follows. One hidden
+ * checkbox drives it via `:checked ~` styles - no timers or state, per the
+ * preview rules in the `building-product-empty-states` skill. Goal pairs are
+ * stacked in `__swap` grids, so nothing shifts.
+ */
+export function MarketingAnalyticsPreview(): JSX.Element {
+ const isStatic = inStorybook() || inStorybookTestRunner()
+
+ return (
+ <div className={cn('MarketingPreview', isStatic && 'MarketingPreview--static')}>
+ {/* Goal state, before both cards so `:checked ~` can style them. */}
+ <input type="checkbox" id="marketing-preview-goal" className="MarketingPreview__checkbox" />
+
+ <div className="MarketingPreview__channels">
+ <div className="MarketingPreview__head">
+ <span className="MarketingPreview__title">
+ <span className="MarketingPreview__live-dot" aria-hidden="true" />
+ Channels · 30 days
+ </span>
+ <LemonTag size="small">example data</LemonTag>
+ </div>
+ <div className="MarketingPreview__goal-bar">
+ <span className="MarketingPreview__goal-label">Conversion goal</span>
+ <label htmlFor="marketing-preview-goal" className="MarketingPreview__goal-chip">
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">signed_up</span>
+ <span className="MarketingPreview__when-purchases">purchase_completed</span>
+ </span>
+ </label>
+ </div>
+ <div className="MarketingPreview__rows">
+ <div className="MarketingPreview__row MarketingPreview__row--header">
+ <span>Channel</span>
+ <span>Spend</span>
+ <span>Conv.</span>
+ <span>ROAS</span>
+ </div>
+ <div className="MarketingPreview__row">
+ <span className="MarketingPreview__channel">Google Ads</span>
+ <span>$4,120</span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">311</span>
+ <span className="MarketingPreview__when-purchases">64</span>
+ </span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">3.4×</span>
+ <span className="MarketingPreview__when-purchases">2.2×</span>
+ </span>
+ </div>
+ <div className="MarketingPreview__row">
+ <span className="MarketingPreview__channel">Meta Ads</span>
+ <span>$2,860</span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">402</span>
+ <span className="MarketingPreview__when-purchases">38</span>
+ </span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">4.1×</span>
+ <span className="MarketingPreview__when-purchases">1.3×</span>
+ </span>
+ </div>
+ <div className="MarketingPreview__row">
+ <span className="MarketingPreview__channel">LinkedIn Ads</span>
+ <span>$1,240</span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">57</span>
+ <span className="MarketingPreview__when-purchases">21</span>
+ </span>
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">1.1×</span>
+ <span className="MarketingPreview__when-purchases">2.6×</span>
+ </span>
+ </div>
+ </div>
+ <div className="MarketingPreview__hint MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">
+ Click the goal to judge the same spend by purchases.
+ </span>
+ <span className="MarketingPreview__when-purchases">
+ Meta wins signups, Google wins revenue. Click to flip back.
+ </span>
+ </div>
+ </div>
+
+ <div className="MarketingPreview__stat">
+ <div className="MarketingPreview__spark-head">
+ <span className="MarketingPreview__spark-title MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">Cost per signup · blended</span>
+ <span className="MarketingPreview__when-purchases">Cost per purchase · blended</span>
+ </span>
+ </div>
+ <div className="MarketingPreview__spark-value">
+ <span className="MarketingPreview__swap">
+ <span className="MarketingPreview__when-signups">$10.67</span>
+ <span className="MarketingPreview__when-purchases">$66.83</span>
+ </span>
+ <span className="MarketingPreview__spark-sub">$8,220 spend</span>
+ </div>
+ </div>
+ </div>
+ )
+}
diff --git a/products/marketing_analytics/frontend/emptyState/marketingAnalyticsEmptyState.tsx b/products/marketing_analytics/frontend/emptyState/marketingAnalyticsEmptyState.tsx
new file mode 100644
index 000000000000..502f272e2c39
--- /dev/null
+++ b/products/marketing_analytics/frontend/emptyState/marketingAnalyticsEmptyState.tsx
@@ -0,0 +1,47 @@
+import * as megaphonePng from '@posthog/brand/hoggies/png/megaphone'
+import { IconMegaphone } from '@posthog/icons'
+
+import { pngHoggie } from 'lib/brand/hoggies'
+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
+import type { SceneProductEmptyState } from 'lib/components/ProductEmptyState/types'
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { ProductKey } from '~/queries/schema/schema-general'
+
+import { MarketingAnalyticsPreview } from './MarketingAnalyticsPreview'
+import { marketingAnalyticsSetupLogic } from './marketingAnalyticsSetupLogic'
+
+const HedgehogMegaphone = pngHoggie(megaphonePng)
+
+export const marketingAnalyticsEmptyState: SceneProductEmptyState = {
+ statusLogic: marketingAnalyticsSetupLogic,
+ // The whole product is behind this flag; its in-scene banner handles the flag-off case.
+ featureFlag: FEATURE_FLAGS.WEB_ANALYTICS_MARKETING,
+ config: {
+ productKey: ProductKey.MARKETING_ANALYTICS,
+ productName: 'Marketing analytics',
+ icon: <IconMegaphone />,
+ accentColor: 'var(--color-product-marketing-analytics-light)',
+ accentColorDark: 'var(--color-product-marketing-analytics-dark)',
+ hedgehog: HedgehogMegaphone,
+ text: {
+ 'needs-setup': {
+ headline: 'See which ad spend actually converts',
+ lead: 'Pull spend from Google Ads, Meta, LinkedIn, and your other ad platforms, join it with conversions you define, and compare cost per conversion and ROAS across channels and campaigns.',
+ },
+ },
+ primaryAction: {
+ label: 'Connect your ad platforms',
+ onClick: () => {
+ // The connect flow is the scene's own step-by-step setup, so
+ // dismiss the gate and let it take over.
+ productSetupStatusLogic
+ .findMounted({ productKey: ProductKey.MARKETING_ANALYTICS })
+ ?.actions.skipEmptyState()
+ },
+ },
+ docsUrl: 'https://posthog.com/docs/web-analytics/marketing-analytics',
+ previewLabel: 'Your channels, once connected',
+ Preview: MarketingAnalyticsPreview,
+ },
+}
diff --git a/products/marketing_analytics/frontend/emptyState/marketingAnalyticsSetupLogic.ts b/products/marketing_analytics/frontend/emptyState/marketingAnalyticsSetupLogic.ts
new file mode 100644
index 000000000000..e4eaeae2f2e8
--- /dev/null
+++ b/products/marketing_analytics/frontend/emptyState/marketingAnalyticsSetupLogic.ts
@@ -0,0 +1,80 @@
+import { MakeLogicType, afterMount, connect, kea, path } from 'kea'
+import { subscriptions } from 'kea-subscriptions'
+
+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
+import type { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'
+import { marketingAnalyticsLogic } from 'scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic'
+
+import { ProductKey } from '~/queries/schema/schema-general'
+
+// If the sources never finish loading, fail open to the scene rather than
+// stranding the gate on its spinner.
+const LOADING_FALLBACK_MS = 10000
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface marketingAnalyticsSetupLogicValues {
+ hasSources: boolean // marketingAnalyticsLogic
+ loading: boolean // marketingAnalyticsLogic
+ setupStatus: ProductSetupStatus // productSetupStatusLogic
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface marketingAnalyticsSetupLogicActions {
+ setDetectedStatus: (status: ProductSetupStatus) => {
+ status: ProductSetupStatus
+ } // productSetupStatusLogic
+}
+
+export type marketingAnalyticsSetupLogicType = MakeLogicType<
+ marketingAnalyticsSetupLogicValues,
+ marketingAnalyticsSetupLogicActions
+>
+
+/**
+ * Setup detection for the marketing analytics empty state. "Set up" means at
+ * least one valid ad source (a native integration, or a warehouse table with
+ * its UTM columns mapped) - the same `hasSources` the scene's own onboarding
+ * keys off. The value comes from the scene logic (which sceneLogic keeps
+ * mounted while the gate renders), so this logic just waits for its sources
+ * to finish loading and mirrors the verdict.
+ */
+export const marketingAnalyticsSetupLogic = kea<marketingAnalyticsSetupLogicType>([
+ path(['products', 'marketing_analytics', 'frontend', 'emptyState', 'marketingAnalyticsSetupLogic']),
+ connect(() => ({
+ logic: [marketingAnalyticsLogic],
+ values: [
+ productSetupStatusLogic({ productKey: ProductKey.MARKETING_ANALYTICS }),
+ ['status as setupStatus'],
+ marketingAnalyticsLogic,
+ ['hasSources', 'loading'],
+ ],
+ actions: [productSetupStatusLogic({ productKey: ProductKey.MARKETING_ANALYTICS }), ['setDetectedStatus']],
+ })),
+ subscriptions(({ actions, values }) => ({
+ loading: (loading: boolean) => {
+ if (!loading) {
+ actions.setDetectedStatus(values.hasSources ? 'has-data' : 'needs-setup')
+ }
+ },
+ hasSources: (hasSources: boolean) => {
+ // Covers a source configured from the wizard while this stays mounted.
+ if (!values.loading) {
+ actions.setDetectedStatus(hasSources ? 'has-data' : 'needs-setup')
+ }
+ },
+ })),
+ afterMount(({ actions, values, cache }) => {
+ if (!values.loading) {
+ actions.setDetectedStatus(values.hasSources ? 'has-data' : 'needs-setup')
+ return
+ }
+ cache.disposables.add(() => {
+ const id = window.setTimeout(() => {
+ if (values.setupStatus === 'loading') {
+ actions.setDetectedStatus('unknown')
+ }
+ }, LOADING_FALLBACK_MS)
+ return () => clearTimeout(id)
+ }, 'loading-fallback')
+ }),
+])
diff --git a/products/marketing_analytics/package.json b/products/marketing_analytics/package.json
index fc8dd560dbe3..b49cf96a5d8c 100644
--- a/products/marketing_analytics/package.json
+++ b/products/marketing_analytics/package.json
@@ -2,5 +2,16 @@
"name": "@posthog/products-marketing-analytics",
"scripts": {
"backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short"
+ },
+ "dependencies": {
+ "kea": "catalog:",
+ "kea-subscriptions": "catalog:"
+ },
+ "peerDependencies": {
+ "@posthog/brand": "catalog:",
+ "@posthog/icons": "catalog:",
+ "@types/react": "*",
+ "clsx": "*",
+ "react": "*"
}
}