: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
fix(insights): hide sample-data placeholder on shared views (#68415)
posthog[bot]b05bb831823f
diff --git a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.tsnew file mode 100644index 000000000000..8083fd691509--- /dev/null+++ b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.test.ts@@ -0,0 +1,47 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import { expectLogic } from 'kea-test-utils'++import { teamLogic } from 'scenes/teamLogic'++import { ExportType } from '~/exporter/types'+import { initKeaTests } from '~/test/init'++import { sampleDataStateLogic } from './sampleDataStateLogic'++describe('sampleDataStateLogic', () => {+ let logic: ReturnType<typeof sampleDataStateLogic.build>++ afterEach(() => {+ delete (window as { POSTHOG_EXPORTED_DATA?: unknown }).POSTHOG_EXPORTED_DATA+ })++ // The global is read inside the selector, so it must be in place before the selector first+ // computes (as on real shared pages, where Django injects it before React runs).+ function mount(currentTeam: unknown): void {+ initKeaTests(false)+ teamLogic.mount()+ teamLogic.actions.loadCurrentTeamSuccess(currentTeam as any)+ logic = sampleDataStateLogic()+ logic.mount()+ }++ it('shows the placeholder for a project that never ingested an event', async () => {+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: false })+ await expectLogic(logic).toMatchValues({ shouldShowSampleData: true })+ })++ it('hides the placeholder once a project has ingested', async () => {+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: true })+ await expectLogic(logic).toMatchValues({ shouldShowSampleData: false })+ })++ // Regression guard for the shared-dashboard placeholder bug: TeamPublicSerializer omits+ // `ingested_event`, so it reads as undefined on shared views. Without the isSharedView gate,+ // every empty tile on a real, data-carrying project falsely renders fake sample data.+ it('hides the placeholder on shared views even when ingested_event is absent', async () => {+ window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }+ mount({ ...MOCK_DEFAULT_TEAM, ingested_event: undefined })+ await expectLogic(logic).toMatchValues({ shouldShowSampleData: false })+ })+})diff --git a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.tsindex 1d6215ace211..7ea7be9d833e 100644--- a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts+++ b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts@@ -2,6 +2,8 @@ import { connect, kea, path, selectors } from 'kea'import { teamLogic } from 'scenes/teamLogic'+import { isSharedView } from '~/exporter/exporterViewLogic'+import type { sampleDataStateLogicType } from './sampleDataStateLogicType'/**@@ -16,7 +18,12 @@ export const sampleDataStateLogic = kea<sampleDataStateLogicType>([selectors({shouldShowSampleData: [(s) => [s.currentTeam],- (currentTeam): boolean => !!currentTeam && !currentTeam.ingested_event && !currentTeam.is_demo,+ // Never show the placeholder in shared/embedded/exported views: `TeamPublicSerializer`+ // omits `ingested_event`, so it reads as `undefined` and would otherwise falsely flag+ // every empty tile on a real, data-carrying project as "never ingested". External+ // viewers should just see the normal "No data" state.+ (currentTeam): boolean =>+ !isSharedView() && !!currentTeam && !currentTeam.ingested_event && !currentTeam.is_demo,],}),])