: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(activity): offer a wider date range on the empty events list (#129676)
ruby childsfe51b7395a78
diff --git a/frontend/src/scenes/activity/explore/EventsScene.tsx b/frontend/src/scenes/activity/explore/EventsScene.tsxindex 91b5ba7cd532..dda73350d12a 100644--- a/frontend/src/scenes/activity/explore/EventsScene.tsx+++ b/frontend/src/scenes/activity/explore/EventsScene.tsx@@ -3,6 +3,7 @@ import { useActions, useValues } from 'kea'import { LiveUserCount } from 'lib/components/LiveUserCount'import { FEATURE_FLAGS } from 'lib/constants'import { LemonBanner } from 'lib/lemon-ui/LemonBanner'+import { LemonButton } from 'lib/lemon-ui/LemonButton'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { ActivitySceneHeader } from 'scenes/activity/ActivitySceneHeader'import { FLAG_EVALUATIONS_RETENTION_DAYS } from 'scenes/feature-flags/flagEvaluationsTable'@@ -13,12 +14,15 @@ import { LiveRecordingsCount } from 'scenes/session-recordings/components/LiveReimport { SceneContent } from '~/layout/scenes/components/SceneContent'import { QueryFeature } from '~/queries/nodes/DataTable/queryFeatures'import { Query } from '~/queries/Query/Query'-import { ProductKey } from '~/queries/schema/schema-general'+import { isDataTableNode } from '~/queries/schema/node-guards'+import { DataTableNode, ProductKey } from '~/queries/schema/schema-general'+import { isEventsQuery } from '~/queries/utils'import { ActivityTab } from '~/types'import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'import { buildExploreAgentContext } from '../activityAgentContext'+import { widerActivityRange } from './defaults'import { eventsSceneLogic } from './eventsSceneLogic'import { SAMPLE_EVENTS_SOURCE } from './sampleEventRows'@@ -27,6 +31,14 @@ export function EventsScene(): JSX.Element {const { setQuery } = useActions(eventsSceneLogic())const { featureFlags } = useValues(featureFlagLogic)+ const dataTableQuery = isDataTableNode(query) ? query : null+ const eventsSource = dataTableQuery && isEventsQuery(dataTableQuery.source) ? dataTableQuery.source : null+ const widerRange = eventsSource ? widerActivityRange(eventsSource.after, eventsSource.before) : null+ const widerQuery: DataTableNode | null =+ dataTableQuery && eventsSource && widerRange+ ? { ...dataTableQuery, source: { ...eventsSource, after: widerRange.after } }+ : null+useAttachedContext(buildExploreAgentContext(ActivityTab.ExploreEvents, query))return (@@ -66,6 +78,22 @@ export function EventsScene(): JSX.Element {// A live-data explorer over captured events, so it keeps the hidden ones selectable.includeHiddenEvents: true,dataTableSampleRows: SAMPLE_EVENTS_SOURCE,+ // The scene defaults to the last hour, so an empty list is often a narrow window,+ // not missing data. Offer the next wider range in one click.+ emptyStateDetail:+ widerQuery && widerRange ? (+ <div className="flex flex-col items-center gap-2">+ <span>Try changing the date range, or pick another action, event or breakdown.</span>+ <LemonButton+ type="secondary"+ size="small"+ data-attr="events-empty-widen-date-range"+ onClick={() => setQuery(widerQuery)}+ >+ {widerRange.label}+ </LemonButton>+ </div>+ ) : undefined,}}/></SceneContent>diff --git a/frontend/src/scenes/activity/explore/defaults.test.ts b/frontend/src/scenes/activity/explore/defaults.test.tsindex b257d318b5ef..a8b5fc5fbb31 100644--- a/frontend/src/scenes/activity/explore/defaults.test.ts+++ b/frontend/src/scenes/activity/explore/defaults.test.ts@@ -1,6 +1,6 @@import { NodeKind } from '~/queries/schema/schema-general'-import { getDefaultEventsSceneQuery, getDefaultSessionsSceneQuery } from './defaults'+import { getDefaultEventsSceneQuery, getDefaultSessionsSceneQuery, widerActivityRange } from './defaults'describe('activity explore defaults', () => {test.each([@@ -11,4 +11,23 @@ describe('activity explore defaults', () => {expect(query.source.kind).toBe(kind)expect(query.source).toMatchObject({ after: '-1h' })})++ describe('widerActivityRange', () => {+ test.each([+ ['-1h', '-24h', 'Show last 24 hours'],+ ['-24h', '-7d', 'Show last 7 days'],+ ['-7d', '-30d', 'Show last 30 days'],+ ])('steps %s up to %s', (after, widerAfter, label) => {+ expect(widerActivityRange(after, undefined)).toEqual({ after: widerAfter, label })+ })++ test.each([+ ['a custom range', '-3h', undefined],+ ['the widest step', '-30d', undefined],+ ['a missing after', undefined, undefined],+ ['a bounded range', '-1h', '-30m'],+ ])('returns null for %s', (_, after, before) => {+ expect(widerActivityRange(after, before)).toBeNull()+ })+ })})diff --git a/frontend/src/scenes/activity/explore/defaults.ts b/frontend/src/scenes/activity/explore/defaults.tsindex cc1323df78d4..fefa353149fd 100644--- a/frontend/src/scenes/activity/explore/defaults.ts+++ b/frontend/src/scenes/activity/explore/defaults.ts@@ -19,6 +19,27 @@ export const getDefaultEventsSceneQuery = (properties?: AnyPropertyFilter[]): DashowPersistentColumnConfigurator: true,})+const WIDER_ACTIVITY_RANGES: Record<string, { after: '-24h' | '-7d' | '-30d'; label: string }> = {+ '-1h': { after: '-24h', label: 'Show last 24 hours' },+ '-24h': { after: '-7d', label: 'Show last 7 days' },+ '-7d': { after: '-30d', label: 'Show last 30 days' },+}++/**+ * The next wider range to offer when an activity list is empty, stepping 1h → 24h → 7d → 30d.+ * The scenes default to one hour on purpose (#35425, query memory limits), so an empty list is+ * often just a narrow window. Null for custom or bounded ranges, which the user chose themselves.+ */+export function widerActivityRange(+ after: string | null | undefined,+ before: string | null | undefined+): { after: '-24h' | '-7d' | '-30d'; label: string } | null {+ if (before || !after) {+ return null+ }+ return WIDER_ACTIVITY_RANGES[after] ?? null+}+// An event link opens the events scene with this query. isUnnamedEventLookup recognizes its filter. Change the two together.export const getEventLookupQuery = (id: string): DataTableNode =>getDefaultEventsSceneQuery([