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(insights): complete sample data on the home dashboard (#116784)

Daniel Parkerb47c06a8ed4a
diff --git a/docs/published/handbook/engineering/conventions/frontend-coding.md b/docs/published/handbook/engineering/conventions/frontend-coding.md
index f2d0b43e87c5..47de6f8fc0d5 100644
--- a/docs/published/handbook/engineering/conventions/frontend-coding.md
+++ b/docs/published/handbook/engineering/conventions/frontend-coding.md
@@ -40,7 +40,7 @@ Hence the explicit separation between the data and view layers.
- Reach for an existing design-system component (Lemon/quill) before hand-rolling markup — reuse is how new UI stays on-brand. When you genuinely need a custom component, build it from the system's tokens and primitives and match the surrounding scene's density; avoid the generic AI-generated look (purple gradients, glassmorphism, gradient text, icon-tile card grids, decorative motion).
- Before building new UI, read a few comparable scenes or components and model yours on the ones that follow these conventions. The codebase contains legacy that predates them — an existing violation is not license to repeat it. Conventions outrank precedent, and compliant precedent outranks invention.
- Extract a shared component once the same shape appears in several places and the call sites read as content, not markup. Keep new generics next to the feature that uses them, and promote to `lib/` only when a second feature needs them. Don't build wrappers with a single consumer, and don't add boolean variant props so one caller can switch half the component off — that's two components.
- - Analytics overview cards in the LemonUI web app share `lib/components/AnalyticsMetricCard/AnalyticsMetricCard`. It wraps the chart library metric content with a consistent surface and loading, error, and empty states. Supply `data` and `theme` for a sparkline, `showChange` for comparisons, and `onClick` for a native button with a visible interaction cue. `selected` highlights a card that controls the displayed chart. Quill surfaces can compose `Metric` with `Card` instead.
+ - Analytics overview cards in the LemonUI web app share `lib/components/AnalyticsMetricCard/AnalyticsMetricCard`. It wraps the chart library metric content with a consistent surface and loading, error, and empty states. Supply `data` and `theme` for a sparkline, `showChange` for comparisons, and `onClick` for a native button with a navigation chevron. `selected` highlights a card that controls the displayed chart and removes the navigation chevron. The hover border and focus ring show that the card is interactive. Quill surfaces can compose `Metric` with `Card` instead.
- Interactive elements are real `<button>`/`<a>` elements (`LemonButton` renders one) — never `onClick` on a `<div>`.
- With `focusBasedKeyboardNavigation` enabled, `LemonMenu` moves focus between its trigger and menu items with the arrow keys, including after the menu reopens. Custom triggers must forward `onFocus` and `onKeyDown` to preserve keyboard navigation and focus return.
- Loading, empty, and error are three different screens. Never show an empty state from data that hasn't resolved yet — branch on the loading state first.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 24fb392b866e..251d2dbbb70f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -13507,21 +13507,21 @@ snapshots:
scenes-app-product-analytics-home-dashboard-starter--with-custom-dashboard--light:
hash: v1.k794b7964.3955f90c8826d28cbc8ea87ae21c2736e2ff3b67999586e1901969a2a11a7acb.YjXt5UQ0a2xK9iFx0IGxA9lIQFU4q66REMcDhWsHAXs
scenes-app-product-analytics-home-overview--before-ingestion--dark:
- hash: v1.k794b7964.5c36b1b0d87d73dfcfea7bcb2fe8cd15a04686439f90cda7745b7b082594084e.zrTwy8dlOOfkqeuaHrtsMrWuzISvRfirpNwEGucFQjY
+ hash: v1.k794b7964.48b65f3dbe882c551df657d0b9a78332819528de6691037310e456bdf6e0b71a.JmauGDlQzy9IlkbJbj6jdII20poToLzHc7PUreuu7hc
scenes-app-product-analytics-home-overview--before-ingestion--light:
- hash: v1.k794b7964.1592f53eebdac858bb95c394a03ed074b82fbf6ad4e066ced25894138efba2b4.zlvZTFmxl2PnEPVKSMYNB_ilmXSAzojEMT3JhBZWicE
+ hash: v1.k794b7964.2321ed939beecdb0220b228d4adf80ec5bd5cd0a2317116c7a32c503dacb1dcd.r7oXDGw5c-_yRvT4Q66seo1sfW7h1e_GZY9NK5VYANM
scenes-app-product-analytics-home-overview--empty--dark:
hash: v1.k794b7964.803d51407dca494e41d04f4cb5fb324abd193b22d9cad2b60b92087ec1bf76b5.nESq7Ay6ngu1UriAYHASMUKdnt6lU8FQZwgXkFcizKw
scenes-app-product-analytics-home-overview--empty--light:
hash: v1.k794b7964.bbc8f2807fbdbb994335bd45527ec76fae3715471ee2e97663b08bcc9fd6f622.UW0QtE1YywbSW_gQEL4Gq1k7rRkBXYQQtsxiE3GNf4I
scenes-app-product-analytics-home-overview--narrow--dark:
- hash: v1.k794b7964.33165b83457dd1f05b9ac7f75b92fd8a2e75080fb3588073c42b7081d8a96d6a.tysblZb844c6zcKE6OzrOIFB6_4oQ2fEZ-UxxDNI2ag
+ hash: v1.k794b7964.44f80fde56cf29a09546851fb2f27bed7803b762555ae0fa6b8e92fdd0f3ae09.a3zvScGEYFpMUHLf-K4kLXwOxgGtePOEHhstR64dwDg
scenes-app-product-analytics-home-overview--narrow--light:
- hash: v1.k794b7964.b89791bc686fe04411373af589a088d69a33599c285003dfbced1b705da3343c.FhkkgCr1CO7ag3TG-oDFaFSLLnAjFyMgGbn9G1jtI0g
+ hash: v1.k794b7964.1f901ef88f942b236ebf1fd41c6cf9a109b2817a2ca2c11135ca6741533e22ea.scVfZn48rqxpWip-XgM1laX9XHRDudhZ8I0Gx3KlOQY
scenes-app-product-analytics-home-overview--populated--dark:
- hash: v1.k794b7964.47e72a32df8f128027dfe8529c9af11dd29950b78d61661c18d950eca34ca88a.n1ghHhhJqLixQW_RoYIVq3QpHsb2roUNp-laRWxISfY
+ hash: v1.k794b7964.0658ea671d9bcb09c9fd960c3fea86d8aaf3155b7f92cbde4fbf619f5ab407a4.HgNkQzUYWVr8FSm5orZMLRl6IFA8Nk3h-CfU57_faDc
scenes-app-product-analytics-home-overview--populated--light:
- hash: v1.k794b7964.a64e7adc26b441428d4e442bc9d39486ba53c588b96f2a7770b59fe1d123609c.lagSqJT8Eo2vr6wXTlKMqIPCBBKmTt12AWrPb9F1PVc
+ hash: v1.k794b7964.87106742c22b8310a8af54c6edb982bebc65be64523a9d329fa66bf5af36f56b.3ex94ctQOa8Fi20yMzKcc7lKZIJ9GAAv2sMyO0Zobi8
scenes-app-project-homepage--no-primary-dashboard--dark:
hash: v1.k794b7964.70707572ec3098ed0c916ac56ec8618ccd95b7b270cffb5a5425d447622912d5.Izwpm_cSdfGfQ1bysk9MbTHFu8B9R1YDo0NDluAAgnA
scenes-app-project-homepage--no-primary-dashboard--light:
diff --git a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.test.tsx b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.test.tsx
index ae72a5e67bbf..4a50402f3483 100644
--- a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.test.tsx
+++ b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.test.tsx
@@ -22,6 +22,7 @@ describe('AnalyticsMetricCard', () => {
await userEvent.keyboard(' ')
expect(onClick).toHaveBeenCalledTimes(2)
expect(screen.getByRole('button')).toHaveAttribute('aria-pressed', 'false')
+ expect(screen.getByRole('button').querySelector('svg')).toBeNull()
})
it('does not trigger a containing click action', () => {
diff --git a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
index 4a2f6fa4740a..73d59a49f37f 100644
--- a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
+++ b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
@@ -78,7 +78,7 @@ export function AnalyticsMetricCard({
) : (
<MetricCard {...metricProps} title={label} className="h-full [&>div:first-child]:flex-1" />
)}
- {onClick && (
+ {onClick && selected === undefined && (
<IconChevronRight className="absolute bottom-3 right-3 size-3 text-secondary" aria-hidden />
)}
</Content>
diff --git a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
index 82533ff676f3..e8e1e8676492 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
@@ -166,12 +166,23 @@ describe('HomeTabDefault query reuse', () => {
await waitFor(() => expect(container.querySelector('[data-attr="metric-card-sparkline"]')).not.toBeNull())
})
- it('replaces sample charts with live queries when the project starts receiving events', async () => {
+ it('replaces sample metrics and charts with live queries when the project starts receiving events', async () => {
+ ensureJsdom()
teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: false, is_demo: false })
const { container } = render(<HomeTabDefault />)
- await waitFor(() => expect(mockedQuery).toHaveBeenCalledTimes(9))
- expect(container.querySelectorAll('[data-attr="insight-sample-data-state"]')).toHaveLength(5)
+ await waitFor(() =>
+ expect(container.querySelectorAll('[data-attr="insight-sample-data-state"]')).toHaveLength(11)
+ )
+ for (const tile of container.querySelectorAll('[data-attr^="home-tab-metric-"]')) {
+ expect(tile).toHaveAttribute('aria-busy', 'false')
+ expect(tile.querySelector('[data-attr="metric-card-sparkline"]')).not.toBeNull()
+ }
+ expect(mockedQuery).not.toHaveBeenCalled()
+ expect(screen.queryByText('No previous period data')).not.toBeInTheDocument()
+
+ await act(async () => homeTabDefaultLogic.actions.setSelectedMetric('sessions'))
+ expect(mockedQuery).not.toHaveBeenCalled()
await act(async () => {
teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: true, is_demo: false })
@@ -179,5 +190,10 @@ describe('HomeTabDefault query reuse', () => {
await waitFor(() => expect(mockedQuery).toHaveBeenCalledTimes(14))
expect(container.querySelector('[data-attr="insight-sample-data-state"]')).toBeNull()
+ await waitFor(() =>
+ expect(
+ within(screen.getByLabelText('Sessions', { selector: 'button' })).getByText('10')
+ ).toBeInTheDocument()
+ )
})
})
diff --git a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
index f87705bdd039..327800fd648c 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
@@ -1,10 +1,13 @@
import { useValues } from 'kea'
+import { useMemo } from 'react'
import { useChartTheme } from 'lib/charts/hooks'
import { AnalyticsMetricCard } from 'lib/components/AnalyticsMetricCard/AnalyticsMetricCard'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'
import { formatBucketLabel } from 'lib/utils/timeBuckets'
+import { SampleDataState } from 'scenes/insights/EmptyStates/SampleDataState'
+import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'
import { teamLogic } from 'scenes/teamLogic'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
@@ -15,6 +18,7 @@ import type { TrendResult } from '~/types'
import { homeTabDefaultLogic } from './homeTabDefaultLogic'
import { getHomeTabStatValue, isHomeTabStatBucketInProgress, type HomeTabStatQuery } from './homeTabDefaultTiles'
import { homeTabDataCollectionId, homeTabStatKey, homeTabStatTrendKey } from './homeTabQueryKeys'
+import { getHomeTabSampleStatData } from './homeTabSampleData'
interface HomeTabStatTileProps {
stat: HomeTabStatQuery
@@ -25,19 +29,35 @@ interface HomeTabStatTileProps {
export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabStatTileProps): JSX.Element {
const { currentTeamId, currentTeam } = useValues(teamLogic)
+ const { shouldShowSampleData } = useValues(sampleDataStateLogic)
+ const sampleData = useMemo(
+ () => (shouldShowSampleData ? getHomeTabSampleStatData(stat.key, stat.query) : undefined),
+ [shouldShowSampleData, stat.key, stat.query]
+ )
+ const sampleTrendData = useMemo(
+ () =>
+ shouldShowSampleData
+ ? getHomeTabSampleStatData(stat.trendKey ?? stat.key, stat.trendQuery ?? stat.query)
+ : undefined,
+ [shouldShowSampleData, stat.key, stat.trendKey, stat.trendQuery, stat.query]
+ )
const theme = useChartTheme()
const key = homeTabStatKey(currentTeamId, stat.key)
const logic = dataNodeLogic({
query: stat.query,
loadPriority: 0,
- key,
+ key: shouldShowSampleData ? `${key}.sample` : key,
+ cachedResults: sampleData,
+ doNotLoad: shouldShowSampleData,
dataNodeCollectionId: homeTabDataCollectionId(currentTeamId),
})
useAttachedLogic(logic, homeTabDefaultLogic)
const trendLogic = dataNodeLogic({
query: stat.trendQuery ?? stat.query,
loadPriority: stat.trendQuery && !stat.trendKey ? 1 : 0,
- key: homeTabStatTrendKey(currentTeamId, stat),
+ key: `${homeTabStatTrendKey(currentTeamId, stat)}${shouldShowSampleData ? '.sample' : ''}`,
+ cachedResults: sampleTrendData,
+ doNotLoad: shouldShowSampleData,
dataNodeCollectionId: homeTabDataCollectionId(currentTeamId),
})
useAttachedLogic(trendLogic, homeTabDefaultLogic)
@@ -81,7 +101,7 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
? 'No previous period data'
: `vs. ${formatItem(previousValue, stat.kind)} prior`
- return (
+ const card = (
<AnalyticsMetricCard
className="h-full w-full"
title={label}
@@ -107,4 +127,6 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
restingSubtitle={<span translate="no">{subtitle}</span>}
/>
)
+
+ return shouldShowSampleData ? <SampleDataState>{card}</SampleDataState> : card
}
diff --git a/products/product_analytics/frontend/insights/home/homeTabSampleData.test.ts b/products/product_analytics/frontend/insights/home/homeTabSampleData.test.ts
new file mode 100644
index 000000000000..517fb2fc67dc
--- /dev/null
+++ b/products/product_analytics/frontend/insights/home/homeTabSampleData.test.ts
@@ -0,0 +1,31 @@
+import tk from 'timekeeper'
+
+import { getHomeTabChartOptions, getHomeTabStatQueries } from './homeTabDefaultTiles'
+import { getHomeTabSampleData, getHomeTabSampleStatData } from './homeTabSampleData'
+
+describe('homeTabSampleData', () => {
+ beforeEach(() => tk.freeze(new Date('2026-10-14T12:00:00Z')))
+ afterEach(() => tk.reset())
+
+ it.each([
+ ['-1dStart', '-1dEnd', '2026-10-13T22:00:00.000Z'],
+ ['-1wStart', '-1wEnd', '2026-10-09T00:00:00.000Z'],
+ ['-1mStart', '-1mEnd', '2026-09-29T00:00:00.000Z'],
+ ['2026-10-01', '2026-10-07', '2026-10-06T00:00:00.000Z'],
+ ['-7d', null, '2026-10-13T00:00:00.000Z'],
+ ['-7d', undefined, '2026-10-13T00:00:00.000Z'],
+ ])('generates sample timestamps for %s to %s', (date_from, date_to, lastBucket) => {
+ const dateRange = { date_from, date_to }
+ const stat = getHomeTabStatQueries(dateRange, true).find(({ key }) => key === 'sessions')!
+ const response = getHomeTabSampleStatData(stat.key, stat.query)
+
+ expect(response.results).toHaveLength(2)
+ for (const result of response.results) {
+ expect(result.days).toHaveLength(result.data.length)
+ expect(result.days[result.days.length - 1]).toBe(lastBucket)
+ }
+
+ const chart = getHomeTabChartOptions(dateRange, true).find(({ key }) => key === 'sessions')!
+ expect(getHomeTabSampleData(chart)).toEqual(response)
+ })
+})
diff --git a/products/product_analytics/frontend/insights/home/homeTabSampleData.ts b/products/product_analytics/frontend/insights/home/homeTabSampleData.ts
index 0fe7a36f2a2d..a5d475546d4f 100644
--- a/products/product_analytics/frontend/insights/home/homeTabSampleData.ts
+++ b/products/product_analytics/frontend/insights/home/homeTabSampleData.ts
@@ -1,10 +1,59 @@
import { dayjs } from 'lib/dayjs'
+import { dateStringToDayJs } from 'lib/utils/dateFilters'
-import { NodeKind, RetentionQueryResponse, TrendsQueryResponse } from '~/queries/schema/schema-general'
-import { TrendResult } from '~/types'
+import { NodeKind, RetentionQueryResponse, TrendsQuery, TrendsQueryResponse } from '~/queries/schema/schema-general'
+import { CompareLabelType, TrendResult } from '~/types'
+import type { HomeTabMetricKey } from './homeTabDefaultLogic'
import { HomeTabChartOption } from './homeTabDefaultTiles'
+const METRIC_VALUES: Record<HomeTabMetricKey, number[]> = {
+ active_users: [340, 410, 380, 520, 460, 610, 580],
+ sessions: [480, 560, 530, 720, 640, 850, 810],
+ new_users: [80, 110, 95, 140, 120, 170, 150],
+ session_duration: [145, 160, 152, 180, 165, 195, 184],
+ daily_active_users: [340, 410, 380, 520, 460, 610, 580],
+}
+
+export function getHomeTabSampleStatData(metric: HomeTabMetricKey, query: TrendsQuery): TrendsQueryResponse {
+ const values = METRIC_VALUES[metric]
+ const interval = query.interval ?? 'day'
+ const unit = interval === 'quarter' ? 'month' : interval
+ const step = interval === 'quarter' ? 3 : 1
+ const end = (dateStringToDayJs(query.dateRange?.date_to ?? null) ?? dayjs()).startOf(unit)
+ const days = values.map((_, index) => end.subtract((values.length - index) * step, unit).toISOString())
+ const series = query.series[0]
+
+ return {
+ results: Array.from({ length: query.compareFilter?.compare ? 2 : 1 }, (_, index): TrendResult => {
+ const data = values.map((value) => Math.round(value * (index === 0 ? 1 : 0.84)))
+ const total = data.reduce((sum, value) => sum + value, 0)
+ const count = metric === 'session_duration' || metric === 'daily_active_users' ? total / data.length : total
+ return {
+ action: {
+ id: series.kind === NodeKind.EventsNode ? (series.event ?? null) : null,
+ type: 'events',
+ order: 0,
+ name: 'Sample',
+ math: series.math,
+ },
+ label: 'Sample',
+ count,
+ aggregated_value: count,
+ data,
+ days,
+ labels: days,
+ ...(query.compareFilter?.compare
+ ? {
+ compare: true,
+ compare_label: index === 0 ? CompareLabelType.Current : CompareLabelType.Previous,
+ }
+ : {}),
+ }
+ }),
+ }
+}
+
const BREAKDOWNS: Record<string, [string, number][]> = {
users_by_country: [
['US', 640],
@@ -64,7 +113,9 @@ export function getHomeTabSampleData(
const breakdowns = BREAKDOWNS[option.key]
if (!breakdowns) {
- return undefined
+ return option.key in METRIC_VALUES
+ ? getHomeTabSampleStatData(option.key as HomeTabMetricKey, source)
+ : undefined
}
const results: TrendResult[] = breakdowns.map(([label, count]) => ({