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): disable person drill-down clicks on shared insights (#67864)

Christiaan Hendriksen405fdc2fa137
diff --git a/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx b/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
index a52c91bad4c5..1990e162ddec 100644
--- a/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
+++ b/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
@@ -39,6 +39,7 @@ import { asDisplay, pickBestPersonDistinctId } from 'scenes/persons/person-utils
import { PersonDisplay } from 'scenes/persons/PersonDisplay'
import { teamLogic } from 'scenes/teamLogic'
+import { isSharedView } from '~/exporter/exporterViewLogic'
import { Noun } from '~/models/groupsModel'
import { MAX_SELECT_RETURNED_ROWS } from '~/queries/nodes/DataTable/DataTableExport'
import {
@@ -606,6 +607,12 @@ export function MissingPersonsAlert({
export type OpenPersonsModalProps = Omit<PersonsModalProps, 'onClose' | 'onAfterClose'>
export const openPersonsModal = (props: OpenPersonsModalProps): void => {
+ if (isSharedView()) {
+ // Shared/exported views authenticate with a sharing token, which can never run the
+ // person-level queries this modal needs — it would only ever render an error state.
+ return
+ }
+
const div = document.createElement('div')
const root = createRoot(div)
function destroy(): void {
diff --git a/frontend/src/scenes/trends/trendsDataLogic.test.ts b/frontend/src/scenes/trends/trendsDataLogic.test.ts
index 47467cfff3df..5ad227dcd81c 100644
--- a/frontend/src/scenes/trends/trendsDataLogic.test.ts
+++ b/frontend/src/scenes/trends/trendsDataLogic.test.ts
@@ -5,6 +5,7 @@ import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { getTrendResultCustomizationKey } from 'scenes/insights/utils'
+import { ExportType } from '~/exporter/types'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { DataNode, LifecycleQuery, NodeKind, ResultCustomizationBy, TrendsQuery } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
@@ -428,4 +429,53 @@ describe('trendsDataLogic', () => {
})
})
})
+
+ describe('hasPersonsModal', () => {
+ it('is true for a plain trends query', async () => {
+ await expectLogic(logic).toMatchValues({ hasPersonsModal: true })
+ })
+
+ describe('on shared/exported views', () => {
+ beforeEach(async () => {
+ // Set before mounting: the global is read inside the selector, so it must be
+ // in place when the selector first computes (as on real shared pages, where
+ // Django injects it before React runs). The outer beforeEach has already
+ // mounted everything, so remount with the global in place.
+ window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }
+ initKeaTests(false)
+ await initTrendsDataLogic()
+ })
+
+ afterEach(() => {
+ delete (window as { POSTHOG_EXPORTED_DATA?: unknown }).POSTHOG_EXPORTED_DATA
+ })
+
+ it('is false', async () => {
+ await expectLogic(logic).toMatchValues({ hasPersonsModal: false })
+ })
+ })
+
+ it('is false when the query opts out via hidePersonsModal', async () => {
+ // insightDataLogic only seeds from props.query for `new-AdHoc.` ids; this also
+ // gives the logics a distinct key so they don't reuse the beforeEach mounts.
+ const propsWithHidePersonsModal: InsightLogicProps = {
+ dashboardItemId: 'new-AdHoc.trendsDataLogic.hidePersonsModal',
+ query: {
+ kind: NodeKind.InsightVizNode,
+ source: { kind: NodeKind.TrendsQuery, series: [] },
+ hidePersonsModal: true,
+ },
+ }
+
+ insightDataLogic(propsWithHidePersonsModal).mount()
+ insightLogic(propsWithHidePersonsModal).mount()
+ insightVizDataLogic(propsWithHidePersonsModal).mount()
+
+ const logicWithHidePersonsModal = trendsDataLogic(propsWithHidePersonsModal)
+ logicWithHidePersonsModal.mount()
+ await expectLogic(logicWithHidePersonsModal).toFinishAllListeners()
+
+ await expectLogic(logicWithHidePersonsModal).toMatchValues({ hasPersonsModal: false })
+ })
+ })
})
diff --git a/frontend/src/scenes/trends/trendsDataLogic.ts b/frontend/src/scenes/trends/trendsDataLogic.ts
index a0a8664e0d52..2bf3f6b45d2b 100644
--- a/frontend/src/scenes/trends/trendsDataLogic.ts
+++ b/frontend/src/scenes/trends/trendsDataLogic.ts
@@ -5,6 +5,7 @@ import { dayjs } from 'lib/dayjs'
import { isMultiSeriesFormula } from 'lib/utils/strings'
import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import { getColorFromToken } from 'scenes/dataThemeLogic'
+import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import {
@@ -18,6 +19,7 @@ import {
getTrendResultCustomizationKey,
} from 'scenes/insights/utils'
+import { isSharedView } from '~/exporter/exporterViewLogic'
import {
BreakdownFilter,
EventsNode,
@@ -114,6 +116,8 @@ export const trendsDataLogic = kea<trendsDataLogicType>([
'getTheme',
'theme',
],
+ insightLogic(props),
+ ['showPersonsModal'],
],
actions: [insightVizDataLogic(props), ['setInsightData', 'updateInsightFilter', 'updateBreakdownFilter']],
})),
@@ -175,8 +179,12 @@ export const trendsDataLogic = kea<trendsDataLogicType>([
},
],
hasPersonsModal: [
- (s) => [s.formula, s.hasDataWarehouseSeries, s.isLifecycle, s.querySource],
- (formula, hasDataWarehouseSeries, isLifecycle, querySource) => {
+ (s) => [s.formula, s.hasDataWarehouseSeries, s.isLifecycle, s.querySource, s.showPersonsModal],
+ (formula, hasDataWarehouseSeries, isLifecycle, querySource, showPersonsModal) => {
+ if (!showPersonsModal || isSharedView()) {
+ return false
+ }
+
if (isMultiSeriesFormula(formula)) {
return false
}
diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
index 71587152fac7..9b8a77c7030f 100644
--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
@@ -6,6 +6,7 @@ import { setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'
import { FEATURE_FLAGS } from 'lib/constants'
+import { ExportType } from '~/exporter/types'
import { NodeKind } from '~/queries/schema/schema-general'
import { buildStickinessQuery, chart, getHogChart, personsModal, renderInsight } from '~/test/insight-testing'
@@ -119,6 +120,26 @@ describe('StickinessLineChart', () => {
expect(seriesArg.day).toBe(3)
expect(personsModal.get()).not.toBeInTheDocument()
})
+
+ describe('shared mode', () => {
+ beforeEach(() => {
+ // Shared/exported pages set this global before React mounts; trendsDataLogic.hasPersonsModal reads it.
+ window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }
+ })
+
+ afterEach(() => {
+ delete (window as { POSTHOG_EXPORTED_DATA?: unknown }).POSTHOG_EXPORTED_DATA
+ })
+
+ it('clicking a data point does not open the persons modal', async () => {
+ renderInsight({ query: buildStickinessQuery(), inSharedMode: true })
+
+ await chart.clickAtIndex(2)
+
+ // Sharing-token auth can't run person-level queries, so shared views must not offer the drill-down.
+ expect(personsModal.get()).not.toBeInTheDocument()
+ })
+ })
})
describe('quill in-chart legend (PRODUCT_ANALYTICS_QUILL_LEGEND on)', () => {
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
index 31ad70a8e04f..47eccfeb8792 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
@@ -6,6 +6,7 @@ import { dimensions, setupJsdom, setupSyncRaf } from '@posthog/quill-charts/test
import { FEATURE_FLAGS } from 'lib/constants'
+import { ExportType } from '~/exporter/types'
import { NodeKind } from '~/queries/schema/schema-general'
import { buildTrendsQuery, chart, getHogChart, personsModal, renderInsight } from '~/test/insight-testing'
import { buildAnnotation } from '~/test/insight-testing/test-data'
@@ -130,6 +131,27 @@ describe('TrendsBarChart (ActionsBar)', () => {
expect(personsModal.title()).toMatch(/12 Jun/)
})
+ describe('shared mode', () => {
+ beforeEach(() => {
+ // Shared/exported pages set this global before React mounts; trendsDataLogic.hasPersonsModal reads it.
+ window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }
+ })
+
+ afterEach(() => {
+ delete (window as { POSTHOG_EXPORTED_DATA?: unknown }).POSTHOG_EXPORTED_DATA
+ })
+
+ it('clicking a bar does not open the persons modal', async () => {
+ renderInsight({ query: trendsBar(), inSharedMode: true })
+ await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+
+ await chart.clickAtIndex(2)
+
+ // Sharing-token auth can't run person-level queries, so shared views must not offer the drill-down.
+ expect(personsModal.get()).not.toBeInTheDocument()
+ })
+ })
+
it('renders InsightEmptyState when all series are zero', async () => {
renderInsight({
query: trendsBar({
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
index 97f9a37a3023..16dca5fe6830 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
@@ -6,6 +6,7 @@ import { setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'
import { FEATURE_FLAGS } from 'lib/constants'
+import { ExportType } from '~/exporter/types'
import { NodeKind } from '~/queries/schema/schema-general'
import {
buildTrendsQuery,
@@ -792,6 +793,26 @@ describe('TrendsLineChart', () => {
// Without a click handler the canvas still renders; clicking is a no-op.
expect(personsModal.get()).not.toBeInTheDocument()
})
+
+ describe('shared mode', () => {
+ beforeEach(() => {
+ // Shared/exported pages set this global before React mounts; trendsDataLogic.hasPersonsModal reads it.
+ window.POSTHOG_EXPORTED_DATA = { type: ExportType.Embed }
+ })
+
+ afterEach(() => {
+ delete (window as { POSTHOG_EXPORTED_DATA?: unknown }).POSTHOG_EXPORTED_DATA
+ })
+
+ it('clicking a data point does not open the persons modal', async () => {
+ renderInsight({ query: buildTrendsQuery(), inSharedMode: true })
+
+ await chart.clickAtIndex(2)
+
+ // Sharing-token auth can't run person-level queries, so shared views must not offer the drill-down.
+ expect(personsModal.get()).not.toBeInTheDocument()
+ })
+ })
})
describe('quill in-chart legend (PRODUCT_ANALYTICS_QUILL_LEGEND on)', () => {