: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(mcp-analytics): add internal/test account filter to dashboard (#64435)
Paul D'Ambrae7f8e70d0866
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b4991397aa7a..0b0225ff629c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5721,9 +5721,9 @@ snapshots:scenes-app-marketing-analytics-cell-actions--source-cell-action-unmapped--light:hash: v1.k794b7964.4ebf2f848b10c8b2859630215a9be1ff91fb825fc334005207556310261d3a5c.UcqJY3dqyJNbi3x7oYaZ2rEu95LAEdbGmMyEpI-Wlgcscenes-app-mcp-analytics--dashboard--dark:- hash: v1.k794b7964.ce73116b61c51cdf515f7c449614e819605543194fc8194e3777cdd3fe37e847.V5cyDORCjiV-nUz1h65KpHKbywxm0u-TRuq7W3vJSrY+ hash: v1.k794b7964.c25b8e1693844d8f9d2b6e8c08a06bea95ea0a6ff0575e468c03004eabcd41f4.kgv_UP8c-JuwxoLHEYC5xFD08QcECeL5ThgVof5i0VUscenes-app-mcp-analytics--dashboard--light:- hash: v1.k794b7964.ca0753eb512b0d9ccef0d4c4ff92aadcea3b6df1be5651501038556443e5e914.yj6GSJwiP_mA_Eq426rKSfymYSgYCQVBqsnB5hLWwKQ+ hash: v1.k794b7964.e80fca14f66bcb1dff0d8645f852c51d5b0131a676e246d52ee938ce8bf1205e.zUCTZ71CfSoVdfgE-isvw_ymFWq8OoRQ0y_lv_z2HWYscenes-app-mcp-analytics--sessions--dark:hash: v1.k794b7964.277463ad445565d14f2549a063a4f8c0c23a81af419bfafc9eefc65577fb0834.woelvjefGWPDW4Acae_sP2fA7YidrA7tkhfvC8u_AQ4scenes-app-mcp-analytics--sessions--light:diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsxindex 70db4b17b30c..0564331e9b55 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx@@ -4,6 +4,7 @@ import { useMemo } from 'react'import { type ChartTheme } from '@posthog/quill-charts'import { buildTheme } from 'lib/charts/utils/theme'+import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'import { teamLogic } from 'scenes/teamLogic'import { themeLogic } from '~/layout/navigation-3000/themeLogic'@@ -34,8 +35,9 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {toolRowsLoading,dateFilter,interval,+ filterTestAccounts,} = useValues(mcpDashboardOverviewLogic)- const { setDateFilter } = useActions(mcpDashboardOverviewLogic)+ const { setDateFilter, setFilterTestAccounts } = useActions(mcpDashboardOverviewLogic)const { isDarkModeOn } = useValues(themeLogic)const { timezone } = useValues(teamLogic)@@ -45,13 +47,18 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {return (<div className="flex flex-col gap-4" data-quill>- <div className="flex flex-wrap items-center gap-3">+ <div className="flex flex-wrap items-center justify-between gap-3"><McpDateFilterdateFrom={dateFilter.dateFrom}dateTo={dateFilter.dateTo}onChange={(dateFrom, dateTo) => setDateFilter(dateFrom, dateTo)}dataAttr="mcp-dashboard-date-filter"/>+ <TestAccountFilterSwitch+ checked={filterTestAccounts}+ onChange={setFilterTestAccounts}+ data-attr="mcp-dashboard-test-account-filter"+ /></div><section><h2 className="mb-4 text-xl font-semibold text-primary">Key metrics</h2>diff --git a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsxindex 9b0367f39e19..7189a8687920 100644--- a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx+++ b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx@@ -15,6 +15,9 @@ interface TileSpec {format: (n: number) => stringcolor: stringloading: boolean+ // Overrides the default "vs. prior" comparison line — used to flag a tile+ // whose value isn't scoped by the dashboard filters.+ subtitle?: string}function KPITile({ tile, theme }: { tile: TileSpec; theme: ChartTheme }): JSX.Element {@@ -41,7 +44,10 @@ function KPITile({ tile, theme }: { tile: TileSpec; theme: ChartTheme }): JSX.Elcolor={tile.color}goodDirection={metric.goodDirection}formatValue={tile.format}- subtitle={hasComparison ? `vs. ${tile.format(metric.previousValue)} prior` : undefined}+ subtitle={+ tile.subtitle ??+ (hasComparison ? `vs. ${tile.format(metric.previousValue)} prior` : undefined)+ }sparklineHeight={50}sparklineClassName="mt-3 -mx-3 -mb-3"/>@@ -103,6 +109,10 @@ export function KpiTiles({format: formatNumber,color: theme.colors[6],loading: false,+ // Clusters come from the latest clustering snapshot across all sessions, so+ // unlike the other tiles this count isn't scoped by the date or test-account+ // filters. Label it so the grid doesn't read as a single consistent scope.+ subtitle: 'Latest run · all sessions',},]diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex 0a493fa91b50..73f2e39f0442 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -1,3 +1,5 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'+import { expectLogic } from 'kea-test-utils'import api from 'lib/api'@@ -283,7 +285,7 @@ describe('mcpDashboardOverviewLogic', () => {})})- describe('date filter wiring', () => {+ describe('filter wiring', () => {beforeEach(() => {jest.clearAllMocks()initKeaTests()@@ -315,5 +317,36 @@ describe('mcpDashboardOverviewLogic', () => {expect(kpi?.filters.dateRange.date_from).not.toBe('-30d')expect(dayjs(kpi?.filters.dateRange.date_from).isValid()).toBe(true)})++ it.each([[false], [true]])('passes filterTestAccounts=%s to every tile', async (enabled) => {+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ // enabled=false is the default mount state; enabled=true reloads after toggling.+ const callsBefore = enabled ? mockApi.query.mock.calls.length : 0++ if (enabled) {+ await expectLogic(logic, () => {+ logic.actions.setFilterTestAccounts(true)+ }).toFinishAllListeners()+ }++ const reloads = reloadCallsSince(callsBefore)+ expect(reloads.length).toBe(6)+ expect(reloads.every((call) => call.filters.filterTestAccounts === enabled)).toBe(true)+ })++ it('defaults the filter from the team test_account_filters_default_checked setting', async () => {+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, test_account_filters_default_checked: true })+ jest.spyOn(mockApi, 'query').mockResolvedValue({ results: [] } as any)+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ // No explicit toggle, yet every tile filters internal users because the team default is on.+ const reloads = mockApi.query.mock.calls.map((call) => call[0] as any)+ expect(reloads.length).toBeGreaterThanOrEqual(6)+ expect(reloads.every((call) => call.filters.filterTestAccounts === true)).toBe(true)+ })})})diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex 7d83c49b89a1..1bd170ac1543 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -9,7 +9,7 @@ import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { HogQLFilters, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'-import { IntervalType } from '~/types'+import { IntervalType, TeamType } from '~/types'import { mcpClusteringLogic } from './clustering/mcpClusteringLogic'import { categorizeHarness } from './dashboard/harnessRegistry'@@ -428,10 +428,11 @@ export function buildKPIs(rows: BucketRow[], currentStartBucket: string): KPIDatexport const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([path(['products', 'mcp_analytics', 'frontend', 'mcpDashboardOverviewLogic']),connect(() => ({- values: [mcpClusteringLogic, ['clusters', 'hasSnapshot'], teamLogic, ['timezone']],+ values: [mcpClusteringLogic, ['clusters', 'hasSnapshot'], teamLogic, ['timezone', 'currentTeam']],})),actions({setDateFilter: (dateFrom: string | null, dateTo: string | null) => ({ dateFrom, dateTo }),+ setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),reloadAll: true,}),reducers({@@ -441,6 +442,14 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([setDateFilter: (_, { dateFrom, dateTo }): DateFilter => ({ dateFrom, dateTo }),},],+ // null until the user toggles — the effective value falls back to the team's+ // test_account_filters_default_checked setting (see the filterTestAccounts selector).+ filterTestAccountsOverride: [+ null as boolean | null,+ {+ setFilterTestAccounts: (_, { filterTestAccounts }): boolean | null => filterTestAccounts,+ },+ ],}),loaders(({ values }) => ({kpis: [@@ -567,10 +576,17 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([],})),selectors({+ // Effective toggle state: the user's explicit override, else the team's default.+ filterTestAccounts: [+ (s) => [s.filterTestAccountsOverride, s.currentTeam],+ (override: boolean | null, currentTeam: TeamType | null): boolean =>+ override ?? !!currentTeam?.test_account_filters_default_checked,+ ],queryFilters: [- (s) => [s.dateFilter],- (dateFilter: DateFilter): HogQLFilters => ({+ (s) => [s.dateFilter, s.filterTestAccounts],+ (dateFilter: DateFilter, filterTestAccounts: boolean): HogQLFilters => ({dateRange: { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo },+ filterTestAccounts,}),],interval: [@@ -609,6 +625,9 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([setDateFilter: () => {actions.reloadAll()},+ setFilterTestAccounts: () => {+ actions.reloadAll()+ },reloadAll: () => {actions.loadKPIs()actions.loadToolRows()@@ -618,8 +637,8 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([actions.loadToolDailyRows()},})),- actionToUrl(({ values }) => ({- setDateFilter: () => {+ actionToUrl(({ values }) => {+ const syncUrl = (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => {const { currentLocation } = router.valuesconst searchParams = { ...currentLocation.searchParams }if (values.dateFilter.dateFrom) {@@ -632,19 +651,38 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([} else {delete searchParams.date_to}+ // Absent param = follow the team default; an explicit override (incl. false) persists.+ if (values.filterTestAccountsOverride === null) {+ delete searchParams.filter_test_accounts+ } else {+ searchParams.filter_test_accounts = values.filterTestAccountsOverride+ }return [currentLocation.pathname, searchParams, currentLocation.hashParams, { replace: true }]- },- })),+ }+ return {+ setDateFilter: syncUrl,+ setFilterTestAccounts: syncUrl,+ }+ }),urlToAction(({ actions, values, cache }) => ({[urls.mcpAnalyticsDashboard()]: (_, searchParams) => {const dateFrom =typeof searchParams.date_from === 'string' ? searchParams.date_from : DEFAULT_DATE_FILTER.dateFromconst dateTo = typeof searchParams.date_to === 'string' ? searchParams.date_to : null- if (dateFrom !== values.dateFilter.dateFrom || dateTo !== values.dateFilter.dateTo) {- // setDateFilter's listener reloads everything.+ // Absent param leaves the override null (effective value follows the team default).+ const rawFilter = searchParams.filter_test_accounts+ const filterOverride = rawFilter === undefined ? null : rawFilter === true || rawFilter === 'true'+ const dateChanged = dateFrom !== values.dateFilter.dateFrom || dateTo !== values.dateFilter.dateTo+ const filterChanged = filterOverride !== values.filterTestAccountsOverride+ // setDateFilter / setFilterTestAccounts each reload via their listeners.+ if (dateChanged) {actions.setDateFilter(dateFrom, dateTo)- } else if (!cache.hasLoaded) {- // URL already matches state (e.g. default window) and afterMount deferred — load once here.+ }+ if (filterChanged) {+ actions.setFilterTestAccounts(filterOverride)+ }+ // URL already matches state (e.g. default filters) and afterMount deferred — load once.+ if (!dateChanged && !filterChanged && !cache.hasLoaded) {actions.reloadAll()}cache.hasLoaded = true@@ -656,7 +694,10 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([// tests, where urlToAction never fires). The cache.hasLoaded guard keeps a// deep-linked load from firing twice.const { searchParams } = router.values- const hasUrlFilters = typeof searchParams.date_from === 'string' || typeof searchParams.date_to === 'string'+ const hasUrlFilters =+ typeof searchParams.date_from === 'string' ||+ typeof searchParams.date_to === 'string' ||+ typeof searchParams.filter_test_accounts !== 'undefined'if (!hasUrlFilters && !cache.hasLoaded) {cache.hasLoaded = trueactions.reloadAll()