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): route persons-modal "View events" to events explorer (#62837)

Sam Pennington6cc509eea656
diff --git a/frontend/src/scenes/activity/explore/eventsSceneLogic.test.ts b/frontend/src/scenes/activity/explore/eventsSceneLogic.test.ts
new file mode 100644
index 000000000000..f940ea04495b
--- /dev/null
+++ b/frontend/src/scenes/activity/explore/eventsSceneLogic.test.ts
@@ -0,0 +1,45 @@
+import { combineUrl, router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { urls } from 'scenes/urls'
+
+import { useMocks } from '~/mocks/jest'
+import { DataTableNode, NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+import { ActivityTab } from '~/types'
+
+import { eventsSceneLogic } from './eventsSceneLogic'
+
+describe('eventsSceneLogic', () => {
+ let logic: ReturnType<typeof eventsSceneLogic.build>
+
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/query': () => [200, { results: [] }],
+ },
+ })
+ initKeaTests()
+ logic = eventsSceneLogic()
+ logic.mount()
+ })
+
+ it('picks up a drill-down events query from the #q= hash', async () => {
+ // The "View events" persons-modal action deep-links here with an events DataTableNode in the hash.
+ const query: DataTableNode = {
+ kind: NodeKind.DataTableNode,
+ source: {
+ kind: NodeKind.EventsQuery,
+ select: ['*', 'event', 'person', 'timestamp'],
+ event: '$pageview',
+ after: 'all',
+ } as any,
+ full: true,
+ }
+
+ router.actions.push(combineUrl(urls.activity(ActivityTab.ExploreEvents), {}, { q: query }).url)
+
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.query).toEqual(query)
+ })
+})
diff --git a/frontend/src/scenes/trends/persons-modal/personsModalLogic.test.ts b/frontend/src/scenes/trends/persons-modal/personsModalLogic.test.ts
index 42038c1ba4b9..1b97893e4f29 100644
--- a/frontend/src/scenes/trends/persons-modal/personsModalLogic.test.ts
+++ b/frontend/src/scenes/trends/persons-modal/personsModalLogic.test.ts
@@ -1,9 +1,12 @@
+import { combineUrl } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { urls } from 'scenes/urls'
+
import { useMocks } from '~/mocks/jest'
import { FunnelsActorsQuery, FunnelsQuery, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { FilterLogicalOperator, PersonActorType, PropertyFilterType, PropertyOperator } from '~/types'
+import { ActivityTab, FilterLogicalOperator, PersonActorType, PropertyFilterType, PropertyOperator } from '~/types'
import { personsModalLogic } from './personsModalLogic'
@@ -457,4 +460,50 @@ describe('personsModalLogic', () => {
)
})
})
+
+ describe('insightEventsQueryUrl', () => {
+ it('routes "View events" to the events explorer with the events query in the #q= hash', () => {
+ logic = personsModalLogic({
+ query: {
+ kind: NodeKind.InsightActorsQuery,
+ source: {
+ kind: NodeKind.TrendsQuery,
+ series: [{ kind: NodeKind.EventsNode, event: '$pageview' }],
+ },
+ includeRecordings: true,
+ },
+ url: null,
+ })
+ logic.mount()
+
+ const url = logic.values.insightEventsQueryUrl
+ expect(url).not.toBeNull()
+
+ // Must target the dedicated events explorer, NOT /insights/new — the explorer reads the query
+ // synchronously and avoids the async upgrade that drops the drill-down to a default Trends insight.
+ const { pathname, hashParams } = combineUrl(url as string)
+ expect(pathname).toEqual(urls.activity(ActivityTab.ExploreEvents))
+ expect(hashParams.q?.kind).toEqual(NodeKind.DataTableNode)
+ expect(hashParams.q?.source?.kind).toEqual(NodeKind.EventsQuery)
+ expect(hashParams.q?.source?.event).toEqual('$pageview')
+ // The embedded InsightActorsQuery (and its TrendsQuery source) is what scopes the events to the
+ // clicked data point rather than showing every event in the project.
+ expect(hashParams.q?.source?.source?.kind).toEqual(NodeKind.InsightActorsQuery)
+ expect(hashParams.q?.source?.source?.source?.kind).toEqual(NodeKind.TrendsQuery)
+ })
+
+ it('returns null for non-Trends actors queries', () => {
+ logic = personsModalLogic({
+ query: {
+ kind: NodeKind.FunnelsActorsQuery,
+ source: { kind: NodeKind.FunnelsQuery, series: [] },
+ funnelStep: 1,
+ },
+ url: null,
+ })
+ logic.mount()
+
+ expect(logic.values.insightEventsQueryUrl).toBeNull()
+ })
+ })
})
diff --git a/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts b/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts
index 9102cdaddb79..3b65d154463c 100644
--- a/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts
+++ b/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts
@@ -1,6 +1,6 @@
import { actions, afterMount, connect, kea, listeners, path, props, propsChanged, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { router, urlToAction } from 'kea-router'
+import { combineUrl, router, urlToAction } from 'kea-router'
import { lemonToast } from '@posthog/lemon-ui'
@@ -31,6 +31,7 @@ import {
} from '~/queries/schema/schema-general'
import { setLatestVersionsOnQuery } from '~/queries/utils'
import {
+ ActivityTab,
ActorType,
BreakdownType,
ChartDisplayType,
@@ -529,7 +530,11 @@ export const personsModalLogic = kea<personsModalLogicType>([
full: true,
}
- return urls.insightNew({ query })
+ // Route to the dedicated events explorer rather than /insights/new. The explorer reads the
+ // query synchronously from the `#q=` hash and renders the events table directly, whereas the
+ // insight scene round-trips this drill-down through an async query upgrade that can drop it and
+ // fall back to a default Trends insight.
+ return combineUrl(urls.activity(ActivityTab.ExploreEvents), {}, { q: query }).url
},
],
sessionIdsFromLoadedActors: [
diff --git a/playwright/e2e/product-analytics/insights/persons-modal.spec.ts b/playwright/e2e/product-analytics/insights/persons-modal.spec.ts
new file mode 100644
index 000000000000..555f53db080c
--- /dev/null
+++ b/playwright/e2e/product-analytics/insights/persons-modal.spec.ts
@@ -0,0 +1,45 @@
+import { InsightPage } from '../../../page-models/insightPage'
+import { pageviews } from '../../../utils/test-data'
+import { PlaywrightWorkspaceSetupResult, expect, test } from '../../../utils/workspace-test-base'
+
+const events = [...pageviews.events]
+
+test.describe('Persons modal', () => {
+ let workspace: PlaywrightWorkspaceSetupResult | null = null
+
+ test.beforeAll(async ({ playwrightSetup }) => {
+ workspace = await playwrightSetup.createWorkspace({
+ use_current_time: true,
+ skip_onboarding: true,
+ no_demo_data: true,
+ events,
+ })
+ })
+
+ test.beforeEach(async ({ page, playwrightSetup }) => {
+ await playwrightSetup.login(page, workspace!)
+ })
+
+ test('"View events" navigates to the events explorer, not a Trends insight', async ({ page }) => {
+ const insight = new InsightPage(page)
+
+ await test.step('open a Number chart and click the value to open the persons modal', async () => {
+ await insight.goToNewTrends()
+ await insight.trends.waitForChart()
+ // A Number chart exposes a single clickable aggregated value — a far more deterministic
+ // drill-down target than a line-graph data point.
+ await insight.trends.selectChartType(/^Number/)
+ await expect(insight.trends.boldNumber).toContainText(pageviews.expected.total)
+ await insight.trends.boldNumber.click()
+ await expect(insight.personsModal).toBeVisible()
+ })
+
+ await test.step('"View events" opens the events explorer', async () => {
+ await expect(insight.personsModalViewEventsButton).toBeVisible()
+ const popupPromise = page.context().waitForEvent('page')
+ await insight.personsModalViewEventsButton.click()
+ const eventsTab = await popupPromise
+ await expect(eventsTab).toHaveURL(/\/activity\/explore/)
+ })
+ })
+})
diff --git a/playwright/page-models/insightPage.ts b/playwright/page-models/insightPage.ts
index 68e8e49f5bf5..75b3eb4fa632 100644
--- a/playwright/page-models/insightPage.ts
+++ b/playwright/page-models/insightPage.ts
@@ -23,6 +23,9 @@ export class InsightPage {
readonly topBarName: Locator
readonly activeTab: Locator
+ readonly personsModal: Locator
+ readonly personsModalViewEventsButton: Locator
+
readonly trends: TrendsInsight
readonly funnels: FunnelsInsight
readonly retention: RetentionInsight
@@ -40,6 +43,9 @@ export class InsightPage {
this.topBarName = page.getByTestId('scene-name')
this.activeTab = page.locator('.LemonTabs__tab--active')
+ this.personsModal = page.getByTestId('persons-modal')
+ this.personsModalViewEventsButton = page.getByTestId('person-modal-view-events')
+
this.trends = new TrendsInsight(page)
this.funnels = new FunnelsInsight(page)
this.retention = new RetentionInsight(page)