: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(replay): probe the retention window for the empty state gate (#99711)
posthog[bot]310ef5e2ddf0
diff --git a/products/replay/frontend/emptyState/sessionReplaySetupLogic.test.ts b/products/replay/frontend/emptyState/sessionReplaySetupLogic.test.tsindex fe8c7d1bd033..19229cdf2265 100644--- a/products/replay/frontend/emptyState/sessionReplaySetupLogic.test.ts+++ b/products/replay/frontend/emptyState/sessionReplaySetupLogic.test.ts@@ -32,4 +32,19 @@ describe('sessionReplaySetupLogic', () => {await expectLogic(sessionReplaySetupLogic).toFinishAllListeners()expect(productSetupStatusLogic({ productKey: ProductKey.SESSION_REPLAY }).values.status).toBe(expected)})++ // Without an explicit range the list falls back to the last 3 days, so a project whose newest+ // recording is older than that reads as "nothing captured" and loses the scene to the gate.+ it.each([+ ['30d', '-30d'],+ ['1y', '-1y'],+ ['legacy', '-90d'],+ [null, '-90d'],+ ])('retention %s probes back to %s', async (period, expected) => {+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, session_recording_retention_period: period } as TeamType)+ const list = jest.spyOn(api.recordings, 'list').mockResolvedValue({ results: [], has_next: false })+ sessionReplaySetupLogic.mount()+ await expectLogic(sessionReplaySetupLogic).toFinishAllListeners()+ expect(list).toHaveBeenCalledWith(expect.objectContaining({ date_from: expected }))+ })})diff --git a/products/replay/frontend/emptyState/sessionReplaySetupLogic.ts b/products/replay/frontend/emptyState/sessionReplaySetupLogic.tsindex 91678aacc43e..b2c86af813b8 100644--- a/products/replay/frontend/emptyState/sessionReplaySetupLogic.ts+++ b/products/replay/frontend/emptyState/sessionReplaySetupLogic.ts@@ -4,6 +4,16 @@ import { teamLogic } from 'scenes/teamLogic'import { NodeKind } from '~/queries/schema/schema-general'import { ProductKey } from '~/queries/schema/schema-general'+import type { SessionRecordingRetentionPeriod } from '~/types'++// The recordings list defaults to the last 3 days server-side, which reads a project whose newest+// recording is older than that as "nothing captured" and hides the scene behind the waiting+// screen. Probe the project's retention period instead: no recording can outlive it, so it is the+// widest window worth scanning. `legacy` (not a duration) and an unset period fall back to 90+// days, as the recordings API does.+function probeDateFrom(period: SessionRecordingRetentionPeriod | null | undefined): string {+ return `-${period && period !== 'legacy' ? period : '90d'}`+}/*** Setup detection for the session replay empty state. Three-state: recordings@@ -15,13 +25,16 @@ export const sessionReplaySetupLogic = createSetupDetectionLogic({productKey: ProductKey.SESSION_REPLAY,path: ['products', 'replay', 'frontend', 'emptyState', 'sessionReplaySetupLogic'],detect: async () => {- const response = await api.recordings.list({ kind: NodeKind.RecordingsQuery, limit: 1 })+ const currentTeam = teamLogic.findMounted()?.values.currentTeam+ const response = await api.recordings.list({+ kind: NodeKind.RecordingsQuery,+ limit: 1,+ date_from: probeDateFrom(currentTeam?.session_recording_retention_period),+ })if (response.results.length > 0) {return 'has-data'}- return teamLogic.findMounted()?.values.currentTeam?.session_recording_opt_in- ? 'waiting-for-data'- : 'needs-setup'+ return currentTeam?.session_recording_opt_in ? 'waiting-for-data' : 'needs-setup'},pollIntervalMs: 20000,// Enabling recording (from this empty state or settings) must flip the