: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
fix(mcp-analytics): aggregate dashboard sessions by $mcp_session_id (#60840)
Georgis Andonisb96c85f7c8cf
diff --git a/products/mcp_analytics/backend/dashboard_templates.py b/products/mcp_analytics/backend/dashboard_templates.pyindex 31e6a845ff7d..ce4fa5e3e28a 100644--- a/products/mcp_analytics/backend/dashboard_templates.py+++ b/products/mcp_analytics/backend/dashboard_templates.py@@ -67,7 +67,7 @@ def get_mcp_analytics_default_template() -> DashboardTemplate:"name": "mcp_initialize","custom_name": "sessions","math": "hogql",- "math_hogql": "count(DISTINCT properties.$session_id)",+ "math_hogql": "count(DISTINCT properties.$mcp_session_id)",},],"trendsFilter": {},diff --git a/products/mcp_analytics/backend/tests/test_dashboard_templates.py b/products/mcp_analytics/backend/tests/test_dashboard_templates.pyindex b9a18a967593..62ce01a8c797 100644--- a/products/mcp_analytics/backend/tests/test_dashboard_templates.py+++ b/products/mcp_analytics/backend/tests/test_dashboard_templates.py@@ -47,7 +47,7 @@ def test_mcp_analytics_default_template_includes_users_and_sessions() -> None:"name": "mcp_initialize","custom_name": "sessions","math": "hogql",- "math_hogql": "count(DISTINCT properties.$session_id)",+ "math_hogql": "count(DISTINCT properties.$mcp_session_id)",},]diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex 6bc234118837..ca9e16c57ccb 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -13,7 +13,7 @@ const LOOKBACK_DAYS = 7const KPI_QUERY = hogql`SELECTtoDate(timestamp) AS bucket,- countDistinctIf(toString(properties.$session_id), toString(properties.$session_id) != '') AS sessions,+ countDistinctIf(toString(properties.$mcp_session_id), toString(properties.$mcp_session_id) != '') AS sessions,count() AS tool_calls,countIf(toBool(properties.$mcp_is_error)) AS errors,round(quantile(0.95)(toFloat(properties.$mcp_duration_ms))) AS p95,@@ -31,7 +31,7 @@ ORDER BY bucket// applies fixed rules over this set; no per-rule SQL.const SESSION_ROWS_QUERY = hogql`SELECT- toString(properties.$session_id) AS session_id,+ toString(properties.$mcp_session_id) AS session_id,count() AS tool_calls,countIf(toBool(properties.$mcp_is_error)) AS errors,round(countIf(toBool(properties.$mcp_is_error)) * 100.0 / count(), 1) AS error_rate_pct,@@ -41,8 +41,8 @@ SELECTFROM eventsWHERE event = 'mcp_tool_call'AND timestamp >= now() - INTERVAL ${hogql.raw(String(LOOKBACK_DAYS))} DAY- AND properties.$session_id IS NOT NULL- AND properties.$session_id != ''+ AND properties.$mcp_session_id IS NOT NULL+ AND properties.$mcp_session_id != ''AND properties.$mcp_tool_name IS NOT NULLAND properties.$mcp_tool_name != ''GROUP BY session_id@@ -75,7 +75,7 @@ SELECTtoString(properties.$mcp_client_name) AS client,count() AS total_calls,countIf(toBool(properties.$mcp_is_error)) AS errors,- countDistinctIf(toString(properties.$session_id), toString(properties.$session_id) != '') AS sessions+ countDistinctIf(toString(properties.$mcp_session_id), toString(properties.$mcp_session_id) != '') AS sessionsFROM eventsWHERE event = 'mcp_tool_call'AND timestamp >= now() - INTERVAL ${hogql.raw(String(LOOKBACK_DAYS))} DAY