: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): persist shared filter selection in URL (#103006)
Lucas Faria331e8d1befee
diff --git a/docs/internal/mcp-analytics-filter-navigation.md b/docs/internal/mcp-analytics-filter-navigation.mdnew file mode 100644index 000000000000..66e56f3ce0e4--- /dev/null+++ b/docs/internal/mcp-analytics-filter-navigation.md@@ -0,0 +1,8 @@+# MCP analytics filter navigation++The Dashboard stores its property filters and internal/test-user choice in the URL as `properties` and `filter_test_accounts`.+Tab links, KPI links, and tool-report links carry those parameters so the Dashboard restores the same selection when someone returns.+An absent or invalid `filter_test_accounts` value follows the project's default; `true` and `false` are explicit overrides.++This first layer preserves the selection but does not make other tabs use it in their queries.+Tool quality, Sessions, and Activity need their own query and UI wiring before their metrics can be described as filtered by these parameters.diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsxindex 5d2904b1b160..6dcfe581d06f 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx@@ -19,6 +19,7 @@ import { NotableSessionsTable } from './dashboard/NotableSessionsTable'import { ToolErrorRateChart } from './dashboard/ToolErrorRateChart'import { ToolUsageChart } from './dashboard/ToolUsageChart'import { MCPAnalyticsFirstLook } from './firstLook/MCPAnalyticsFirstLook'+import { mcpAnalyticsFiltersLogic } from './mcpAnalyticsFiltersLogic'import { mcpDashboardOverviewLogic } from './mcpDashboardOverviewLogic'export function MCPAnalyticsDashboardOverview(): JSX.Element {@@ -44,11 +45,11 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {toolRowsLoading,dateFilter,interval,- filterTestAccounts,- propertyFilters,queryFilters,} = useValues(mcpDashboardOverviewLogic)- const { setDateFilter, setFilterTestAccounts, setPropertyFilters } = useActions(mcpDashboardOverviewLogic)+ const { setDateFilter } = useActions(mcpDashboardOverviewLogic)+ const { filterTestAccounts, propertyFilters } = useValues(mcpAnalyticsFiltersLogic)+ const { setFilterTestAccounts, setPropertyFilters } = useActions(mcpAnalyticsFiltersLogic)const { timezone } = useValues(teamLogic)const { featureFlags } = useValues(featureFlagLogic)diff --git a/products/mcp_analytics/frontend/dashboard/KpiTiles.test.tsx b/products/mcp_analytics/frontend/dashboard/KpiTiles.test.tsxnew file mode 100644index 000000000000..afc4bbeda60d--- /dev/null+++ b/products/mcp_analytics/frontend/dashboard/KpiTiles.test.tsx@@ -0,0 +1,29 @@+import { combineUrl } from 'kea-router'++import { urls } from 'scenes/urls'++import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'++import { kpiTileUrls } from './KpiTiles'++const EVENT_FILTER: AnyPropertyFilter = {+ key: '$mcp_tool_name',+ value: ['create_insight'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+}++describe('KpiTiles', () => {+ it('keeps dashboard filters in Sessions and Tool quality links', () => {+ const searchParams = {+ date_from: '-7d',+ properties: [EVENT_FILTER],+ filter_test_accounts: false,+ }+ const tileUrls = kpiTileUrls({ ...searchParams, landing: 'old', search: 'old' })++ expect(tileUrls.sessions).toBe(combineUrl(urls.mcpAnalyticsSessions(), searchParams).url)+ expect(tileUrls.toolQuality).toBe(combineUrl(urls.mcpAnalyticsToolQuality(), searchParams).url)+ expect(tileUrls.intentClustering).toBe(combineUrl(urls.mcpAnalyticsIntentClustering(), searchParams).url)+ })+})diff --git a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsxindex 48d0506a0c71..46617947f769 100644--- a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx+++ b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx@@ -1,3 +1,6 @@+import { useValues } from 'kea'+import { combineUrl, router } from 'kea-router'+import { Link } from '@posthog/lemon-ui'import { type ChartTheme } from '@posthog/quill-charts'@@ -23,6 +26,19 @@ interface TileSpec {subtitle?: string}+export function kpiTileUrls(searchParams: Record<string, any>): {+ sessions: string+ toolQuality: string+ intentClustering: string+} {+ const { landing: _landing, search: _search, ...sharedParams } = searchParams+ return {+ sessions: combineUrl(urls.mcpAnalyticsSessions(), sharedParams).url,+ toolQuality: combineUrl(urls.mcpAnalyticsToolQuality(), sharedParams).url,+ intentClustering: combineUrl(urls.mcpAnalyticsIntentClustering(), sharedParams).url,+ }+}+function KPITile({tile,theme,@@ -91,12 +107,18 @@ export function KpiTiles({// silently renders the partial bucket as settled data.incompleteTail: boolean}): JSX.Element {+ const {+ sessions: sessionsHref,+ toolQuality: toolQualityHref,+ intentClustering: intentClusteringHref,+ } = kpiTileUrls(useValues(router).searchParams)+const tiles: TileSpec[] = [{label: 'Users',metric: users,// Person identity (email/name) is resolved on the Sessions tab, so that's the drill-down for "who".- href: urls.mcpAnalyticsSessions(),+ href: sessionsHref,format: formatNumber,color: theme.colors[2],loading: usersLoading,@@ -105,7 +127,7 @@ export function KpiTiles({{label: 'Sessions',metric: kpis.sessions,- href: urls.mcpAnalyticsSessions(),+ href: sessionsHref,format: formatNumber,color: theme.colors[0],loading: kpisLoading,@@ -114,7 +136,7 @@ export function KpiTiles({{label: 'Tool calls',metric: kpis.toolCalls,- href: urls.mcpAnalyticsToolQuality(),+ href: toolQualityHref,format: formatNumber,color: theme.colors[0],loading: kpisLoading,@@ -123,7 +145,7 @@ export function KpiTiles({{label: 'Error rate',metric: kpis.errorRatePct,- href: urls.mcpAnalyticsSessions(),+ href: sessionsHref,format: (n) => formatPercentage(n, { compact: true }),color: theme.colors[4],loading: kpisLoading,@@ -132,7 +154,7 @@ export function KpiTiles({{label: 'p95 latency',metric: kpis.p95LatencyMs,- href: urls.mcpAnalyticsToolQuality(),+ href: toolQualityHref,format: formatMs,color: theme.colors[0],loading: kpisLoading,@@ -143,7 +165,7 @@ export function KpiTiles({{label: 'Intent clusters',metric: intentClusterCount,- href: urls.mcpAnalyticsIntentClustering(),+ href: intentClusteringHref,format: formatNumber,color: theme.colors[6],loading: false,diff --git a/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.test.ts b/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.test.tsnew file mode 100644index 000000000000..ee64bfe2e749--- /dev/null+++ b/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.test.ts@@ -0,0 +1,115 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import { urls } from 'scenes/urls'++import { initKeaTests } from '~/test/init'+import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'++import { MCP_ANALYTICS_FILTER_ROUTES, mcpAnalyticsFiltersLogic } from './mcpAnalyticsFiltersLogic'+import { mcpToolQualityUrlWithDates, mcpToolReportUrl } from './mcpAnalyticsToolQualityLogic'++const EVENT_FILTER: AnyPropertyFilter = {+ key: '$mcp_tool_name',+ value: ['create_insight'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+}++describe('mcpAnalyticsFiltersLogic', () => {+ beforeEach(() => {+ initKeaTests()+ })++ it('syncs property filters to the URL and clears the param when emptied', async () => {+ router.actions.push(urls.mcpAnalyticsDashboard())+ const logic = mcpAnalyticsFiltersLogic()+ logic.mount()++ await expectLogic(logic, () => {+ logic.actions.setPropertyFilters([EVENT_FILTER])+ }).toFinishAllListeners()+ expect(router.values.searchParams.properties).toEqual([EVENT_FILTER])++ await expectLogic(logic, () => {+ logic.actions.setPropertyFilters([])+ }).toFinishAllListeners()+ expect(router.values.searchParams.properties).toBeUndefined()+ })++ it('keeps an explicit test-account override in the URL and drops it when following the team default', async () => {+ router.actions.push(urls.mcpAnalyticsDashboard())+ const logic = mcpAnalyticsFiltersLogic()+ logic.mount()++ await expectLogic(logic, () => {+ logic.actions.setFilterTestAccounts(false)+ }).toFinishAllListeners()+ expect(router.values.searchParams.filter_test_accounts).toBe(false)++ await expectLogic(logic, () => {+ logic.actions.setFilterTestAccounts(null)+ }).toFinishAllListeners()+ expect(router.values.searchParams.filter_test_accounts).toBeUndefined()+ })++ it.each(MCP_ANALYTICS_FILTER_ROUTES.map((route) => [route.replace(':toolName', 'create_insight')]))(+ 'hydrates the filters from the URL on %s',+ async (route) => {+ router.actions.push(route, { properties: [EVENT_FILTER], filter_test_accounts: true })+ const logic = mcpAnalyticsFiltersLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.propertyFilters).toEqual([EVENT_FILTER])+ expect(logic.values.filterTestAccounts).toBe(true)+ }+ )++ it('follows the team test_account_filters_default_checked setting until the user toggles', async () => {+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, test_account_filters_default_checked: true })+ router.actions.push(urls.mcpAnalyticsDashboard())+ const logic = mcpAnalyticsFiltersLogic()+ logic.mount()++ expect(logic.values.filterTestAccounts).toBe(true)+ logic.actions.setFilterTestAccounts(false)+ expect(logic.values.filterTestAccounts).toBe(false)+ })++ it.each(['1', 'invalid'])(+ 'ignores an invalid test-account URL value (%s) and follows the team default',+ (value) => {+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, test_account_filters_default_checked: true })+ router.actions.push(urls.mcpAnalyticsDashboard(), { filter_test_accounts: value })+ const logic = mcpAnalyticsFiltersLogic()+ logic.mount()++ expect(logic.values.filterTestAccountsOverride).toBeNull()+ expect(logic.values.filterTestAccounts).toBe(true)+ }+ )++ it('preserves shared filters when opening and leaving a tool report', () => {+ router.actions.push(urls.mcpAnalyticsToolQuality(), {+ properties: [EVENT_FILTER],+ filter_test_accounts: false,+ })++ router.actions.push(mcpToolReportUrl('create_insight', { dateFrom: '-7d', dateTo: null }))+ expect(router.values.searchParams).toMatchObject({+ properties: [EVENT_FILTER],+ filter_test_accounts: false,+ date_from: '-7d',+ })++ router.actions.push(mcpToolQualityUrlWithDates({ dateFrom: '-7d', dateTo: null }))+ expect(router.values.searchParams).toMatchObject({+ properties: [EVENT_FILTER],+ filter_test_accounts: false,+ date_from: '-7d',+ })+ })+})diff --git a/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.ts b/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.tsnew file mode 100644index 000000000000..38820f56a4d9--- /dev/null+++ b/products/mcp_analytics/frontend/mcpAnalyticsFiltersLogic.ts@@ -0,0 +1,164 @@+import { MakeLogicType, actions, connect, kea, path, reducers, selectors } from 'kea'+import { actionToUrl, router, urlToAction } from 'kea-router'++import { isValidPropertyFilter } from 'lib/components/PropertyFilters/utils'+import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'++import { HogQLFilters } from '~/queries/schema/schema-general'+import { AnyPropertyFilter, TeamType } from '~/types'++import type { TeamPublicType } from '../../../frontend/src/types'++export type MCPSharedQueryFilters = Required<Pick<HogQLFilters, 'filterTestAccounts' | 'properties'>>++export const MCP_ANALYTICS_FILTER_ROUTES = [+ urls.mcpAnalyticsActivity(),+ urls.mcpAnalyticsDashboard(),+ urls.mcpAnalyticsSessions(),+ urls.mcpAnalyticsToolQuality(),+ `${urls.mcpAnalyticsToolQuality()}/:toolName`,+ urls.mcpAnalyticsIntentClustering(),+ urls.mcpAnalyticsMissingCapabilities(),+ urls.mcpAnalyticsNotifications(),+]++interface UrlFilters {+ filterTestAccountsOverride: boolean | null+ propertyFilters: AnyPropertyFilter[]+}++function parseUrlFilters(searchParams: Record<string, any>): UrlFilters {+ const rawFilter = searchParams.filter_test_accounts+ return {+ filterTestAccountsOverride:+ rawFilter === true || rawFilter === 'true'+ ? true+ : rawFilter === false || rawFilter === 'false'+ ? false+ : null,+ propertyFilters: Array.isArray(searchParams.properties) ? searchParams.properties : [],+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface mcpAnalyticsFiltersLogicValues {+ currentTeam: TeamPublicType | TeamType | null // teamLogic+ filterTestAccounts: boolean+ filterTestAccountsOverride: boolean | null+ propertyFilters: AnyPropertyFilter[]+ queryFilters: MCPSharedQueryFilters+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface mcpAnalyticsFiltersLogicActions {+ hydrateFilters: (+ filterTestAccountsOverride: boolean | null,+ propertyFilters: AnyPropertyFilter[]+ ) => {+ filterTestAccountsOverride: boolean | null+ propertyFilters: AnyPropertyFilter[]+ }+ setFilterTestAccounts: (filterTestAccounts: boolean | null) => {+ filterTestAccounts: boolean | null+ }+ setPropertyFilters: (properties: AnyPropertyFilter[]) => {+ properties: AnyPropertyFilter[]+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface mcpAnalyticsFiltersLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ filterTestAccounts: (+ filterTestAccountsOverride: boolean | null,+ currentTeam: TeamPublicType | TeamType | null+ ) => boolean+ queryFilters: (filterTestAccounts: boolean, propertyFilters: AnyPropertyFilter[]) => MCPSharedQueryFilters+ }+}++export type mcpAnalyticsFiltersLogicType = MakeLogicType<+ mcpAnalyticsFiltersLogicValues,+ mcpAnalyticsFiltersLogicActions,+ Record<string, any>,+ mcpAnalyticsFiltersLogicMeta+>++export const mcpAnalyticsFiltersLogic = kea<mcpAnalyticsFiltersLogicType>([+ path(['products', 'mcp_analytics', 'frontend', 'mcpAnalyticsFiltersLogic']),+ connect(() => ({+ values: [teamLogic, ['currentTeam']],+ })),+ actions({+ hydrateFilters: (filterTestAccountsOverride: boolean | null, propertyFilters: AnyPropertyFilter[]) => ({+ filterTestAccountsOverride,+ propertyFilters,+ }),+ setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),+ setPropertyFilters: (properties: AnyPropertyFilter[]) => ({ properties }),+ }),+ reducers({+ filterTestAccountsOverride: [+ null as boolean | null,+ {+ hydrateFilters: (_, { filterTestAccountsOverride }): boolean | null => filterTestAccountsOverride,+ setFilterTestAccounts: (_, { filterTestAccounts }): boolean | null => filterTestAccounts,+ },+ ],+ propertyFilters: [+ [] as AnyPropertyFilter[],+ {+ hydrateFilters: (_, { propertyFilters }): AnyPropertyFilter[] => propertyFilters,+ setPropertyFilters: (_, { properties }): AnyPropertyFilter[] => properties,+ },+ ],+ }),+ selectors({+ filterTestAccounts: [+ (s) => [s.filterTestAccountsOverride, s.currentTeam],+ (override: boolean | null, currentTeam: TeamType | null): boolean =>+ override ?? !!currentTeam?.test_account_filters_default_checked,+ ],+ queryFilters: [+ (s) => [s.filterTestAccounts, s.propertyFilters],+ (filterTestAccounts: boolean, propertyFilters: AnyPropertyFilter[]): MCPSharedQueryFilters => ({+ filterTestAccounts,+ properties: propertyFilters.filter(isValidPropertyFilter),+ }),+ ],+ }),+ actionToUrl(({ values }) => {+ const syncUrl = (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => {+ const { currentLocation } = router.values+ const searchParams = { ...currentLocation.searchParams }+ if (values.filterTestAccountsOverride === null) {+ delete searchParams.filter_test_accounts+ } else {+ searchParams.filter_test_accounts = values.filterTestAccountsOverride+ }+ if (values.propertyFilters.length > 0) {+ searchParams.properties = values.propertyFilters+ } else {+ delete searchParams.properties+ }+ return [currentLocation.pathname, searchParams, currentLocation.hashParams, { replace: true }]+ }+ return {+ setFilterTestAccounts: syncUrl,+ setPropertyFilters: syncUrl,+ }+ }),+ urlToAction(({ actions, values }) => {+ const hydrate = (_: Record<string, any>, searchParams: Record<string, any>): void => {+ const { filterTestAccountsOverride, propertyFilters } = parseUrlFilters(searchParams)+ if (+ filterTestAccountsOverride !== values.filterTestAccountsOverride ||+ JSON.stringify(propertyFilters) !== JSON.stringify(values.propertyFilters)+ ) {+ actions.hydrateFilters(filterTestAccountsOverride, propertyFilters)+ }+ }+ return Object.fromEntries(MCP_ANALYTICS_FILTER_ROUTES.map((route) => [route, hydrate]))+ }),+])diff --git a/products/mcp_analytics/frontend/mcpAnalyticsSceneLogic.ts b/products/mcp_analytics/frontend/mcpAnalyticsSceneLogic.tsindex 636fb39f67bf..bf1c813af03c 100644--- a/products/mcp_analytics/frontend/mcpAnalyticsSceneLogic.ts+++ b/products/mcp_analytics/frontend/mcpAnalyticsSceneLogic.ts@@ -5,6 +5,7 @@ import { urls } from 'scenes/urls'import { sceneLogic } from '~/scenes/sceneLogic'+import { mcpAnalyticsFiltersLogic } from './mcpAnalyticsFiltersLogic'import { type MCPDashboardStage, mcpAnalyticsOnboardingLogic } from './mcpAnalyticsOnboardingLogic'export type MCPAnalyticsTab =@@ -73,6 +74,7 @@ export const mcpAnalyticsSceneLogic = kea<mcpAnalyticsSceneLogicType>([path(['products', 'mcp_analytics', 'frontend', 'mcpAnalyticsSceneLogic']),connect(() => ({values: [sceneLogic, ['sceneKey'], mcpAnalyticsOnboardingLogic, ['dashboardStage']],+ logic: [mcpAnalyticsFiltersLogic],})),selectors({activeTab: [diff --git a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.tsindex 72f485838918..a08e1fea3f16 100644--- a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts+++ b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts@@ -70,15 +70,24 @@ export function mcpDateSearchParams(dateFilter: DateFilter, interval?: IntervalTreturn params}+function mcpToolNavigationParams(dateFilter: DateFilter, interval?: IntervalType | null): Record<string, any> {+ const { properties, filter_test_accounts } = router.values.currentLocation.searchParams+ return {+ ...mcpDateSearchParams(dateFilter, interval),+ ...(properties !== undefined ? { properties } : {}),+ ...(filter_test_accounts !== undefined ? { filter_test_accounts } : {}),+ }+}+// Link from the Tool quality tab to an individual tool's report, keeping the date filter and pinned// interval so the tool page opens on the same window and granularity.export function mcpToolReportUrl(tool: string, dateFilter: DateFilter, interval?: IntervalType | null): string {- return combineUrl(urls.mcpAnalyticsTool(tool), mcpDateSearchParams(dateFilter, interval)).url+ return combineUrl(urls.mcpAnalyticsTool(tool), mcpToolNavigationParams(dateFilter, interval)).url}// Link back from a tool report to the Tool quality tab, restoring the date filter and interval.export function mcpToolQualityUrlWithDates(dateFilter: DateFilter, interval?: IntervalType | null): string {- return combineUrl(urls.mcpAnalyticsToolQuality(), mcpDateSearchParams(dateFilter, interval)).url+ return combineUrl(urls.mcpAnalyticsToolQuality(), mcpToolNavigationParams(dateFilter, interval)).url}export type ToolQualityRow = MCPToolQualityRowItemdiff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex e7e9892a09a4..d38a520785ba 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -527,6 +527,50 @@ describe('mcpDashboardOverviewLogic', () => {operator: PropertyOperator.Exact,type: PropertyFilterType.Event,}+ it('reloads tiles once when the URL hydrates both shared filters', async () => {+ router.actions.push(urls.mcpAnalyticsDashboard())+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ const callsBefore = mockApi.query.mock.calls.length++ await expectLogic(logic, () => {+ router.actions.push(urls.mcpAnalyticsDashboard(), {+ properties: [EVENT_FILTER],+ filter_test_accounts: true,+ })+ }).toFinishAllListeners()++ const reloads = reloadCallsSince(callsBefore)+ expect(reloads).toHaveLength(8)+ expect(reloads.every((call) => filtersOf(call).filterTestAccounts === true)).toBe(true)+ expect(+ reloads.every((call) => JSON.stringify(filtersOf(call).properties) === JSON.stringify([EVENT_FILTER]))+ ).toBe(true)+ })+ it('reloads tiles once when the URL changes the date and shared filters together', async () => {+ router.actions.push(urls.mcpAnalyticsDashboard())+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ const callsBefore = mockApi.query.mock.calls.length++ await expectLogic(logic, () => {+ router.actions.push(urls.mcpAnalyticsDashboard(), {+ date_from: '-30d',+ properties: [EVENT_FILTER],+ filter_test_accounts: true,+ })+ }).toFinishAllListeners()++ const reloads = reloadCallsSince(callsBefore)+ expect(reloads).toHaveLength(8)+ expect(reloads.every((call) => filtersOf(call).filterTestAccounts === true)).toBe(true)+ expect(+ reloads.every((call) => JSON.stringify(filtersOf(call).properties) === JSON.stringify([EVENT_FILTER]))+ ).toBe(true)+ expect(reloads.filter((call) => filtersOf(call).dateRange?.date_from === '-30d')).toHaveLength(6)+ })// Feature-flag filters arrive as ordinary $feature/<key> event-property filters.const FLAG_FILTER: AnyPropertyFilter = {key: '$feature/mcp-new-thing',@@ -554,29 +598,5 @@ describe('mcpDashboardOverviewLogic', () => {reloads.every((call) => JSON.stringify(filtersOf(call).properties) === JSON.stringify([filter]))).toBe(true)})-- it('syncs property filters to the URL and clears the param when emptied', async () => {- const logic = mcpDashboardOverviewLogic()- logic.mount()- await expectLogic(logic).toFinishAllListeners()-- await expectLogic(logic, () => {- logic.actions.setPropertyFilters([EVENT_FILTER])- }).toFinishAllListeners()- expect(router.values.searchParams.properties).toEqual([EVENT_FILTER])-- await expectLogic(logic, () => {- logic.actions.setPropertyFilters([])- }).toFinishAllListeners()- expect(router.values.searchParams.properties).toBeUndefined()- })-- it('hydrates property filters from the URL on mount', async () => {- router.actions.push(urls.mcpAnalyticsDashboard(), { properties: [EVENT_FILTER] })- const logic = mcpDashboardOverviewLogic()- logic.mount()- await expectLogic(logic).toFinishAllListeners()- expect(logic.values.propertyFilters).toEqual([EVENT_FILTER])- })})})diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex 8d98908a5d14..df9fe56d6d4a 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -3,7 +3,6 @@ import { loaders } from 'kea-loaders'import { actionToUrl, router, urlToAction } from 'kea-router'import api from 'lib/api'-import { isValidPropertyFilter } from 'lib/components/PropertyFilters/utils'import { getDefaultInterval } from 'lib/utils/dateFilters'import {type ComparisonWindow,@@ -24,11 +23,11 @@ import {MCPToolCallsAndErrorsItem,NodeKind,} from '~/queries/schema/schema-general'-import { AnyPropertyFilter, IntervalType, TeamType } from '~/types'+import { AnyPropertyFilter, IntervalType } from '~/types'-import type { TeamPublicType } from '../../../frontend/src/types'import { mcpClusteringLogic } from './clustering/mcpClusteringLogic'import type { MCPIntentClusterApi } from './generated/api.schemas'+import { type MCPSharedQueryFilters, mcpAnalyticsFiltersLogic } from './mcpAnalyticsFiltersLogic'export interface DateFilter {dateFrom: string | null@@ -376,10 +375,10 @@ export function buildKPIs(rows: BucketRow[], currentStartBucket: string): KPIDat// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface mcpDashboardOverviewLogicValues {+ sharedQueryFilters: MCPSharedQueryFilters // mcpAnalyticsFiltersLogicclusters: readonly MCPIntentClusterApi[] // mcpClusteringLogichasSnapshot: boolean // mcpClusteringLogictotalClusterCount: number // mcpClusteringLogic- currentTeam: TeamPublicType | TeamType | null // teamLogictimezone: string // teamLogicactivityIncompleteTail: booleanactivityRows: ActivityRow[]@@ -387,8 +386,6 @@ export interface mcpDashboardOverviewLogicValues {bucketKeys: string[]dailyActivity: DailyActivitydateFilter: DateFilter- filterTestAccounts: boolean- filterTestAccountsOverride: boolean | nullharnessRows: HarnessRow[]harnessRowsLoading: booleanhasModelData: boolean@@ -400,7 +397,6 @@ export interface mcpDashboardOverviewLogicValues {modelRows: ModelRow[]modelRowsLoading: booleannotableSessions: NotableSession[]- propertyFilters: AnyPropertyFilter[]queryFilters: HogQLFilterssessionRows: SessionRow[]sessionRowsLoading: boolean@@ -415,6 +411,19 @@ export interface mcpDashboardOverviewLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface mcpDashboardOverviewLogicActions {+ hydrateFilters: (+ filterTestAccountsOverride: boolean | null,+ propertyFilters: AnyPropertyFilter[]+ ) => {+ filterTestAccountsOverride: boolean | null+ propertyFilters: AnyPropertyFilter[]+ } // mcpAnalyticsFiltersLogic+ setFilterTestAccounts: (filterTestAccounts: boolean | null) => {+ filterTestAccounts: boolean | null+ } // mcpAnalyticsFiltersLogic+ setPropertyFilters: (properties: AnyPropertyFilter[]) => {+ properties: AnyPropertyFilter[]+ } // mcpAnalyticsFiltersLogicloadActivityRows: (_: void) => voidloadActivityRowsFailure: (error: string,@@ -585,25 +594,14 @@ export interface mcpDashboardOverviewLogicActions {dateFrom: string | nulldateTo: string | null}- setFilterTestAccounts: (filterTestAccounts: boolean | null) => {- filterTestAccounts: boolean | null- }- setPropertyFilters: (properties: AnyPropertyFilter[]) => {- properties: AnyPropertyFilter[]- }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface mcpDashboardOverviewLogicMeta {__keaTypeGenInternalSelectorTypes: {- filterTestAccounts: (- filterTestAccountsOverride: boolean | null,- currentTeam: TeamPublicType | TeamType | null- ) => booleanqueryFilters: (dateFilter: DateFilter,- filterTestAccounts: boolean,- propertyFilters: AnyPropertyFilter[]+ sharedQueryFilters: Required<Pick<HogQLFilters, 'filterTestAccounts' | 'properties'>>) => HogQLFiltersinterval: (dateFilter: DateFilter) => IntervalTypebucketKeys: (dateFilter: DateFilter, timezone: string, interval: IntervalType) => string[]@@ -631,13 +629,14 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([mcpClusteringLogic,['clusters', 'hasSnapshot', 'totalClusterCount'],teamLogic,- ['timezone', 'currentTeam'],+ ['timezone'],+ mcpAnalyticsFiltersLogic,+ ['queryFilters as sharedQueryFilters'],],+ actions: [mcpAnalyticsFiltersLogic, ['hydrateFilters', 'setFilterTestAccounts', 'setPropertyFilters']],})),actions({setDateFilter: (dateFrom: string | null, dateTo: string | null) => ({ dateFrom, dateTo }),- setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),- setPropertyFilters: (properties: AnyPropertyFilter[]) => ({ properties }),reloadAll: true,}),reducers({@@ -647,20 +646,6 @@ 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,- },- ],- propertyFilters: [- [] as AnyPropertyFilter[],- {- setPropertyFilters: (_, { properties }): AnyPropertyFilter[] => properties,- },- ],}),loaders(({ values }) => ({kpis: [@@ -851,23 +836,11 @@ 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, s.filterTestAccounts, s.propertyFilters],- (- dateFilter: DateFilter,- filterTestAccounts: boolean,- propertyFilters: AnyPropertyFilter[]- ): HogQLFilters => ({+ (s) => [s.dateFilter, s.sharedQueryFilters],+ (dateFilter: DateFilter, sharedQueryFilters: MCPSharedQueryFilters): HogQLFilters => ({dateRange: { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo },- filterTestAccounts,- // Drop incomplete picker rows and any malformed URL-hydrated entries before they fan out to every tile.- properties: propertyFilters.filter(isValidPropertyFilter),+ ...sharedQueryFilters,}),],interval: [@@ -923,7 +896,7 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([}),],}),- listeners(({ actions }) => ({+ listeners(({ actions, values }) => ({setDateFilter: () => {actions.reloadAll()},@@ -933,6 +906,15 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([setPropertyFilters: () => {actions.reloadAll()},+ hydrateFilters: () => {+ const { searchParams } = router.values.currentLocation+ const dateFrom =+ typeof searchParams.date_from === 'string' ? searchParams.date_from : DEFAULT_DATE_FILTER.dateFrom+ const dateTo = typeof searchParams.date_to === 'string' ? searchParams.date_to : null+ if (dateFrom === values.dateFilter.dateFrom && dateTo === values.dateFilter.dateTo) {+ actions.reloadAll()+ }+ },reloadAll: () => {actions.loadKPIs()actions.loadUsers()@@ -958,65 +940,34 @@ 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- }- if (values.propertyFilters.length > 0) {- searchParams.properties = values.propertyFilters- } else {- delete searchParams.properties- }return [currentLocation.pathname, searchParams, currentLocation.hashParams, { replace: true }]}return {setDateFilter: syncUrl,- setFilterTestAccounts: syncUrl,- setPropertyFilters: syncUrl,}}),+ // The shared property and test-account filters hydrate from the same URL in+ // mcpAnalyticsFiltersLogic, which mounts first (connected), so a deep-linked load below+ // already sees them.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- // 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 properties = Array.isArray(searchParams.properties) ? searchParams.properties : []const dateChanged = dateFrom !== values.dateFilter.dateFrom || dateTo !== values.dateFilter.dateTo- const filterChanged = filterOverride !== values.filterTestAccountsOverride- const propertiesChanged = JSON.stringify(properties) !== JSON.stringify(values.propertyFilters)- // setDateFilter / setFilterTestAccounts / setPropertyFilters each reload via their listeners.if (dateChanged) {actions.setDateFilter(dateFrom, dateTo)}- if (filterChanged) {- actions.setFilterTestAccounts(filterOverride)- }- if (propertiesChanged) {- actions.setPropertyFilters(properties)- }// URL already matches state (e.g. default filters) and afterMount deferred — load once.- if (!dateChanged && !filterChanged && !propertiesChanged && !cache.hasLoaded) {+ if (!dateChanged && !cache.hasLoaded) {actions.reloadAll()}cache.hasLoaded = true},})),afterMount(({ actions, cache }) => {- // urlToAction owns the initial load whenever the dashboard URL carries filter- // params; this is the fallback for a param-less mount (and off-route mounts in- // 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' ||- typeof searchParams.filter_test_accounts !== 'undefined' ||- Array.isArray(searchParams.properties)+ const hasUrlFilters = typeof searchParams.date_from === 'string' || typeof searchParams.date_to === 'string'if (!hasUrlFilters && !cache.hasLoaded) {cache.hasLoaded = trueactions.reloadAll()