: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 property filtering to the overview dashboard (#64813)
Paul D'Ambra861fc8566e14
diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboard.stories.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboard.stories.tsxindex 737a9461e9b9..5954b8a2f513 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboard.stories.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboard.stories.tsx@@ -124,6 +124,30 @@ const TOOL_CALL_LIST = {],}+// Scoped to $mcp_tool_call via eventNames — these populate the property-filter picker.+const MCP_PROPERTY_DEFINITIONS = {+ count: 5,+ results: [+ { id: 'tool', name: '$mcp_tool_name', property_type: 'String', is_seen_on_filtered_events: true },+ { id: 'err', name: '$mcp_is_error', property_type: 'Boolean', is_seen_on_filtered_events: true },+ { id: 'client', name: '$mcp_client_name', property_type: 'String', is_seen_on_filtered_events: true },+ { id: 'session', name: '$mcp_session_id', property_type: 'String', is_seen_on_filtered_events: true },+ { id: 'duration', name: '$mcp_duration_ms', property_type: 'Numeric', is_seen_on_filtered_events: true },+ ],+}++const MCP_FEATURE_FLAG_DEFINITIONS = {+ count: 1,+ results: [+ {+ id: 'flag',+ name: '$feature/mcp-new-thing',+ property_type: 'String',+ is_seen_on_filtered_events: true,+ },+ ],+}+const CLUSTER_SNAPSHOT = {status: 'ready',error_message: '',@@ -151,6 +175,15 @@ const meta: Meta = {'/api/environments/:team_id/mcp_analytics/intent_clusters/': CLUSTER_SNAPSHOT,'/api/environments/:team_id/mcp_analytics/sessions/': SESSION_LIST,'/api/environments/:team_id/mcp_analytics/sessions/:session_id/tool_calls/': TOOL_CALL_LIST,+ '/api/projects/:team_id/property_definitions': ({ request }) => {+ const isFeatureFlag = new URL(request.url).searchParams.get('is_feature_flag') === 'true'+ return [200, isFeatureFlag ? MCP_FEATURE_FLAG_DEFINITIONS : MCP_PROPERTY_DEFINITIONS]+ },+ '/api/environments/:team_id/events/values/': [+ { name: 'execute-sql' },+ { name: 'read-data-schema' },+ { name: 'query-trends' },+ ],},post: {'/api/environments/:team_id/query/:kind': async ({ request }) => {diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsxindex 0564331e9b55..887cf53a9005 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx@@ -4,6 +4,8 @@ import { useMemo } from 'react'import { type ChartTheme } from '@posthog/quill-charts'import { buildTheme } from 'lib/charts/utils/theme'+import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'import { teamLogic } from 'scenes/teamLogic'@@ -36,8 +38,9 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {dateFilter,interval,filterTestAccounts,+ propertyFilters,} = useValues(mcpDashboardOverviewLogic)- const { setDateFilter, setFilterTestAccounts } = useActions(mcpDashboardOverviewLogic)+ const { setDateFilter, setFilterTestAccounts, setPropertyFilters } = useActions(mcpDashboardOverviewLogic)const { isDarkModeOn } = useValues(themeLogic)const { timezone } = useValues(teamLogic)@@ -48,12 +51,27 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {return (<div className="flex flex-col gap-4" data-quill><div className="flex flex-wrap items-center justify-between gap-3">- <McpDateFilter- dateFrom={dateFilter.dateFrom}- dateTo={dateFilter.dateTo}- onChange={(dateFrom, dateTo) => setDateFilter(dateFrom, dateTo)}- dataAttr="mcp-dashboard-date-filter"- />+ <div className="flex flex-wrap items-center gap-3">+ <McpDateFilter+ dateFrom={dateFilter.dateFrom}+ dateTo={dateFilter.dateTo}+ onChange={(dateFrom, dateTo) => setDateFilter(dateFrom, dateTo)}+ dataAttr="mcp-dashboard-date-filter"+ />+ <div data-attr="mcp-dashboard-property-filter">+ <PropertyFilters+ pageKey="mcp-dashboard-overview"+ propertyFilters={propertyFilters}+ onChange={setPropertyFilters}+ taxonomicGroupTypes={[+ TaxonomicFilterGroupType.EventProperties,+ TaxonomicFilterGroupType.EventFeatureFlags,+ ]}+ eventNames={['$mcp_tool_call']}+ buttonText="Add filter"+ />+ </div>+ </div><TestAccountFilterSwitchchecked={filterTestAccounts}onChange={setFilterTestAccounts}diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex 10516da85f35..a3c4dfbd08ea 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -1,11 +1,14 @@import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'+import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import api from 'lib/api'import { dayjs } from 'lib/dayjs'+import { urls } from 'scenes/urls'import { initKeaTests } from '~/test/init'+import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'import {type ActivityRow,@@ -443,5 +446,63 @@ describe('mcpDashboardOverviewLogic', () => {expect(reloads.length).toBeGreaterThanOrEqual(6)expect(reloads.every((call) => call.filters.filterTestAccounts === true)).toBe(true)})++ const EVENT_FILTER: AnyPropertyFilter = {+ key: '$mcp_tool_name',+ value: ['create_insight'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ }+ // Feature-flag filters arrive as ordinary $feature/<key> event-property filters.+ const FLAG_FILTER: AnyPropertyFilter = {+ key: '$feature/mcp-new-thing',+ value: ['test'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ }++ it.each([+ ['event property', EVENT_FILTER],+ ['feature flag', FLAG_FILTER],+ ])('passes %s filters to every tile', async (_label, filter) => {+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ const callsBefore = mockApi.query.mock.calls.length++ await expectLogic(logic, () => {+ logic.actions.setPropertyFilters([filter])+ }).toFinishAllListeners()++ const reloads = reloadCallsSince(callsBefore)+ expect(reloads.length).toBe(6)+ expect(reloads.every((call) => JSON.stringify(call.filters.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 57ce3511e58f..73a788e5eed2 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -3,13 +3,14 @@ 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 { dayjs } from 'lib/dayjs'import { dateStringToComponents, dateStringToDayJs, getDefaultInterval } from 'lib/utils/dateFilters'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { HogQLFilters, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'-import { IntervalType, TeamType } from '~/types'+import { AnyPropertyFilter, IntervalType, TeamType } from '~/types'import { mcpClusteringLogic } from './clustering/mcpClusteringLogic'import { categorizeHarness } from './dashboard/harnessRegistry'@@ -479,6 +480,7 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([actions({setDateFilter: (dateFrom: string | null, dateTo: string | null) => ({ dateFrom, dateTo }),setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),+ setPropertyFilters: (properties: AnyPropertyFilter[]) => ({ properties }),reloadAll: true,}),reducers({@@ -496,6 +498,12 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([setFilterTestAccounts: (_, { filterTestAccounts }): boolean | null => filterTestAccounts,},],+ propertyFilters: [+ [] as AnyPropertyFilter[],+ {+ setPropertyFilters: (_, { properties }): AnyPropertyFilter[] => properties,+ },+ ],}),loaders(({ values }) => ({kpis: [@@ -629,10 +637,16 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([override ?? !!currentTeam?.test_account_filters_default_checked,],queryFilters: [- (s) => [s.dateFilter, s.filterTestAccounts],- (dateFilter: DateFilter, filterTestAccounts: boolean): HogQLFilters => ({+ (s) => [s.dateFilter, s.filterTestAccounts, s.propertyFilters],+ (+ dateFilter: DateFilter,+ filterTestAccounts: boolean,+ propertyFilters: AnyPropertyFilter[]+ ): 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),}),],interval: [@@ -675,6 +689,9 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([setFilterTestAccounts: () => {actions.reloadAll()},+ setPropertyFilters: () => {+ actions.reloadAll()+ },reloadAll: () => {actions.loadKPIs()actions.loadToolRows()@@ -704,11 +721,17 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([} 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,}}),urlToAction(({ actions, values, cache }) => ({@@ -719,17 +742,22 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([// Absent param leaves the override null (effective value follows the team default).const rawFilter = searchParams.filter_test_accountsconst 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.dateToconst filterChanged = filterOverride !== values.filterTestAccountsOverride- // setDateFilter / setFilterTestAccounts each reload via their listeners.+ 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 && !cache.hasLoaded) {+ if (!dateChanged && !filterChanged && !propertiesChanged && !cache.hasLoaded) {actions.reloadAll()}cache.hasLoaded = true@@ -744,7 +772,8 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([const hasUrlFilters =typeof searchParams.date_from === 'string' ||typeof searchParams.date_to === 'string' ||- typeof searchParams.filter_test_accounts !== 'undefined'+ typeof searchParams.filter_test_accounts !== 'undefined' ||+ Array.isArray(searchParams.properties)if (!hasUrlFilters && !cache.hasLoaded) {cache.hasLoaded = trueactions.reloadAll()