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.

feat(warehouse-sources): add cursor team analytics and ai code change tables (#105158)

Tom Owers868197d07a77
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index a462df93e02b..74ab96e60797 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -2197,24 +2197,24 @@ Note: The OpenAPI 3 spec at https://api.cultureamp.com/spec declares exactly thr
## Cursor — **thin**
-Today (11): `agent_edits`, `ai_code_commits`, `by_user_agent_edits`, `by_user_models`, `by_user_tabs`, `by_user_top_file_extensions`, `daily_usage`, `members`, `spend`, `tabs`, `usage_events`
+Today (15): `agent_edits`, `ai_code_changes`, `ai_code_commits`, `by_user_agent_edits`, `by_user_models`, `by_user_tabs`, `by_user_top_file_extensions`, `daily_usage`, `dau`, `members`, `models`, `spend`, `tabs`, `top_file_extensions`, `usage_events`
Diffed against: <https://cursor.com/docs/account/teams/analytics-api.md>
- [x] `GET /analytics/ai-code/commits` — AI-authored code attribution per commit - Cursor's headline ROI metric (high)
-- [ ] `GET /analytics/ai-code/changes` — change-level AI vs human code accounting, the finer grain behind the commit metrics (high)
-- [ ] `GET /analytics/team/models` — model usage breakdown; the dimension every cost and adoption question needs alongside spend (high)
-- [ ] `GET /analytics/team/dau` — daily active users, the standard seat-utilization metric (high)
+- [x] `GET /analytics/ai-code/changes` — change-level AI vs human code accounting, the finer grain behind the commit metrics (high)
+- [x] `GET /analytics/team/models` — model usage breakdown; the dimension every cost and adoption question needs alongside spend (high)
+- [x] `GET /analytics/team/dau` — daily active users, the standard seat-utilization metric (high)
- [x] `GET /analytics/team/agent-edits` — agent edit volume - the primary productivity measure for agent usage (high)
- [x] `GET /analytics/team/tabs` — tab-completion acceptance metrics, the other half of core usage (high)
- [x] `GET /analytics/by-user/{agent-edits,tabs,models,top-file-extensions}` — per-user breakdowns joining directly to the members table we already sync (high)
- [ ] `GET /teams/groups and /teams/groups/{id}/members` — billing-group lookup and membership resolving the group IDs on member and spend rows (medium)
-- [ ] `GET /analytics/team/top-file-extensions` — language/file-type breakdown of AI usage (medium)
+- [x] `GET /analytics/team/top-file-extensions` — language/file-type breakdown of AI usage (medium)
- [ ] `GET /analytics/team/bugbot and /analytics/team/bugbot-reviews` — code-review volume and per-review analytics for the Bugbot product (medium)
- [ ] `GET /analytics/team/conversation-insights` — aggregated conversation topics and outcomes (medium)
- [ ] `GET /teams/audit-logs` — admin action history for access and compliance reporting (medium)
-Note: PostHog covers the four Admin API data endpoints (members, daily-usage-data, spend, filtered-usage-events) plus the agent-edits and tabs team metrics, their four by-user breakdowns, and the AI Code Tracking commit metrics. The rest of the Analytics API and the Cloud Agents API are still unmapped. Admin API endpoints verified at https://cursor.com/docs/account/teams/admin-api.md and AI code tracking at https://cursor.com/docs/account/teams/ai-code-tracking-api.md. Repo blocklists and spend-limit endpoints excluded as configuration. Correcting the original sweep: every Analytics API and AI Code Tracking endpoint is a plain GET with query params, not a POST with a body, and the Analytics API caps a range at 30 inclusive calendar days.
+Note: PostHog covers the four Admin API data endpoints (members, daily-usage-data, spend, filtered-usage-events) plus the agent-edits, tabs, dau, models and top-file-extensions team metrics, their four by-user breakdowns, and both AI Code Tracking grains (commits and changes). The adoption metrics (bugbot, conversation insights, leaderboard, mcp, commands, plans, skills, ask-mode, client-versions), the team groups and audit-log endpoints, and the Cloud Agents API are still unmapped. Admin API endpoints verified at https://cursor.com/docs/account/teams/admin-api.md and AI code tracking at https://cursor.com/docs/account/teams/ai-code-tracking-api.md. Repo blocklists and spend-limit endpoints excluded as configuration. Correcting the original sweep: every Analytics API and AI Code Tracking endpoint is a plain GET with query params, not a POST with a body, and the Analytics API caps a range at 30 inclusive calendar days.
## Customerly — gaps
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/canonical_descriptions.py
index 933fe9ab2fb0..a6d7b01277dc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/canonical_descriptions.py
@@ -118,6 +118,41 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"total_lines_accepted": "Total lines across accepted completions.",
},
},
+ "dau": {
+ "description": "Daily count of team members who used at least one AI feature in Cursor.",
+ "docs_url": "https://cursor.com/docs/account/teams/analytics-api",
+ "columns": {
+ "date": "Day the counts are aggregated for.",
+ "dau": "Number of team members who used an AI feature on this day.",
+ "cli_dau": "Number of team members who used the Cursor CLI on this day.",
+ "cloud_agent_dau": "Number of team members who used a cloud agent on this day.",
+ "bugbot_dau": "Number of team members who used Bugbot on this day.",
+ },
+ },
+ "models": {
+ "description": "Daily model usage across the whole team.",
+ "docs_url": "https://cursor.com/docs/account/teams/analytics-api",
+ "columns": {
+ "date": "Day the metrics are aggregated for.",
+ "model": "Model the row covers. The API returns a map keyed by model name, which PostHog expands into one row per model.",
+ "messages": "Number of messages the team sent to this model on this day.",
+ "users": "Number of team members who used this model on this day.",
+ },
+ },
+ "top_file_extensions": {
+ "description": "Daily breakdown of AI-assisted edits by file extension, for the five busiest extensions of each day.",
+ "docs_url": "https://cursor.com/docs/account/teams/analytics-api",
+ "columns": {
+ "event_date": "Day the metrics are aggregated for.",
+ "file_extension": "File extension the row covers, without the leading dot.",
+ "total_files": "Number of files with this extension the team touched.",
+ "total_accepts": "Number of AI suggestions accepted in files with this extension.",
+ "total_rejects": "Number of AI suggestions rejected in files with this extension.",
+ "total_lines_suggested": "Lines suggested in files with this extension.",
+ "total_lines_accepted": "Lines accepted in files with this extension.",
+ "total_lines_rejected": "Lines rejected in files with this extension.",
+ },
+ },
"by_user_agent_edits": {
"description": "Daily agent edit metrics broken down by team member.",
"docs_url": "https://cursor.com/docs/account/teams/analytics-api",
@@ -210,4 +245,19 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"createdAt": "When Cursor ingested the commit metrics.",
},
},
+ "ai_code_changes": {
+ "description": "Individual accepted AI changes, grouped by change rather than by commit.",
+ "docs_url": "https://cursor.com/docs/account/teams/ai-code-tracking-api",
+ "columns": {
+ "changeId": "Deterministic identifier Cursor assigns to the change.",
+ "userId": "Public (encoded) Cursor user ID of the author.",
+ "userEmail": "Email address of the author.",
+ "source": "What produced the change: TAB or COMPOSER.",
+ "model": "Model that produced the change, when one is recorded.",
+ "totalLinesAdded": "Total lines added by the change.",
+ "totalLinesDeleted": "Total lines deleted by the change.",
+ "createdAt": "When Cursor ingested the change.",
+ "metadata": "Per-file breakdown of the change. The file name is omitted when the team has privacy mode on.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/cursor.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/cursor.py
index f7efc3fb109a..f6552b4f56e5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/cursor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/cursor.py
@@ -302,11 +302,15 @@ _WINDOWED_NORMALIZERS: dict[str, Callable[[dict[str, Any]], dict[str, Any]]] = {
"daily_usage": _normalize_daily_usage,
"agent_edits": _make_iso_normalizer("event_date"),
"tabs": _make_iso_normalizer("event_date"),
+ "dau": _make_iso_normalizer("date"),
+ "models": _make_iso_normalizer("date"),
+ "top_file_extensions": _make_iso_normalizer("event_date"),
"by_user_agent_edits": _make_iso_normalizer("event_date"),
"by_user_tabs": _make_iso_normalizer("event_date"),
"by_user_top_file_extensions": _make_iso_normalizer("event_date"),
"by_user_models": _make_iso_normalizer("date"),
"ai_code_commits": _make_iso_normalizer("commitTs", "createdAt"),
+ "ai_code_changes": _make_iso_normalizer("createdAt"),
}
@@ -327,13 +331,16 @@ def _expand_model_breakdown(row: dict[str, Any]) -> list[dict[str, Any]]:
_ROW_EXPANDERS: dict[str, Callable[[dict[str, Any]], list[dict[str, Any]]]] = {
"by_user_models": _expand_model_breakdown,
+ "models": _expand_model_breakdown,
}
def _extract_rows(config: CursorEndpointConfig, data: dict[str, Any]) -> list[dict[str, Any]]:
payload = data.get(config.data_key)
+ expand = _ROW_EXPANDERS.get(config.name)
if not config.by_user:
- return payload or []
+ rows = payload or []
+ return [expanded for row in rows for expanded in expand(row)] if expand else rows
if not isinstance(payload, dict):
return []
@@ -344,7 +351,6 @@ def _extract_rows(config: CursorEndpointConfig, data: dict[str, Any]) -> list[di
for mapping in ((data.get("params") or {}).get("userMappings") or [])
if isinstance(mapping, dict) and mapping.get("email")
}
- expand = _ROW_EXPANDERS.get(config.name)
rows = [
{**row, "userEmail": email, "userId": ids_by_email.get(email)}
for email, user_rows in payload.items()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/settings.py
index 697dc0e5153d..eb14f6789f9c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/settings.py
@@ -119,6 +119,56 @@ CURSOR_ENDPOINTS: dict[str, CursorEndpointConfig] = {
should_sync_default=False,
description="Daily team totals for Tab autocomplete: suggestions, accepts, rejects, and line counts. Needs a Cursor Enterprise plan. Only syncs the last 365 days on initial sync",
),
+ "dau": CursorEndpointConfig(
+ name="dau",
+ path="/analytics/team/dau",
+ method="GET",
+ query_params=True,
+ date_param_format="iso_date",
+ data_key="data",
+ primary_keys=["date"],
+ windowed=True,
+ window_days=ANALYTICS_MAX_WINDOW_DAYS,
+ paginated=False,
+ partition_key="date",
+ incremental_fields=[_datetime_field("date")],
+ should_sync_default=False,
+ description="Daily count of team members who used an AI feature, with the CLI, cloud agent, and Bugbot counts alongside. Needs a Cursor Enterprise plan. Only syncs the last 365 days on initial sync",
+ ),
+ "models": CursorEndpointConfig(
+ name="models",
+ path="/analytics/team/models",
+ method="GET",
+ query_params=True,
+ date_param_format="iso_date",
+ data_key="data",
+ # One row per day per model, expanded from the per-model map the API returns.
+ primary_keys=["date", "model"],
+ windowed=True,
+ window_days=ANALYTICS_MAX_WINDOW_DAYS,
+ paginated=False,
+ partition_key="date",
+ incremental_fields=[_datetime_field("date")],
+ should_sync_default=False,
+ description="Daily team model usage, with a message count and a user count for each model. Needs a Cursor Enterprise plan. Only syncs the last 365 days on initial sync",
+ ),
+ "top_file_extensions": CursorEndpointConfig(
+ name="top_file_extensions",
+ path="/analytics/team/top-file-extensions",
+ method="GET",
+ query_params=True,
+ date_param_format="iso_date",
+ data_key="data",
+ # One row per day per file extension, for the five busiest extensions of that day.
+ primary_keys=["event_date", "file_extension"],
+ windowed=True,
+ window_days=ANALYTICS_MAX_WINDOW_DAYS,
+ paginated=False,
+ partition_key="event_date",
+ incremental_fields=[_datetime_field("event_date")],
+ should_sync_default=False,
+ description="Daily team file extension breakdown of AI-assisted edits, top five extensions per day. Needs a Cursor Enterprise plan. Only syncs the last 365 days on initial sync",
+ ),
"by_user_agent_edits": CursorEndpointConfig(
name="by_user_agent_edits",
path="/analytics/by-user/agent-edits",
@@ -207,6 +257,24 @@ CURSOR_ENDPOINTS: dict[str, CursorEndpointConfig] = {
should_sync_default=False,
description="Per-commit attribution of lines added and deleted to Tab, Composer, and non-AI authoring. Needs a Cursor Enterprise plan with AI code tracking enabled. Only syncs the last 365 days on initial sync",
),
+ "ai_code_changes": CursorEndpointConfig(
+ name="ai_code_changes",
+ path="/analytics/ai-code/changes",
+ method="GET",
+ query_params=True,
+ date_param_format="iso_date",
+ data_key="items",
+ # `changeId` is documented as deterministic per change; the author is in the key for the
+ # same reason as ai_code_commits — the docs scope uniqueness to the aggregate.
+ primary_keys=["changeId", "userId"],
+ windowed=True,
+ window_days=ANALYTICS_MAX_WINDOW_DAYS,
+ page_size=1000,
+ partition_key="createdAt",
+ incremental_fields=[_datetime_field("createdAt")],
+ should_sync_default=False,
+ description="Individual accepted AI changes with the lines added and deleted, the model, and the files each change touched. Needs a Cursor Enterprise plan with AI code tracking enabled. Only syncs the last 365 days on initial sync",
+ ),
}
ENDPOINTS = tuple(CURSOR_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor.py
index 212dd8a2d989..5ecf4426ddaa 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor.py
@@ -302,6 +302,26 @@ class TestCursorTransport:
}
]
+ def test_team_models_expands_the_per_model_map_into_rows(self):
+ # The team endpoint returns the same per-model map, but arrives as a plain list rather
+ # than the per-user object, so it takes the other branch of the row extractor.
+ data = {"data": [{"date": "2025-01-15", "model_breakdown": {"gpt-4o": {"messages": 450, "users": 15}}}]}
+
+ rows = _extract_rows(CURSOR_ENDPOINTS["models"], data)
+
+ assert rows == [{"date": "2025-01-15", "model": "gpt-4o", "messages": 450, "users": 15}]
+
+ def test_every_windowed_endpoint_has_a_normalizer(self):
+ # A windowed endpoint with no normalizer raises only once a sync reaches it, so an
+ # endpoint added without one ships broken.
+ missing = [
+ name
+ for name, config in CURSOR_ENDPOINTS.items()
+ if config.windowed and name not in cursor._WINDOWED_NORMALIZERS
+ ]
+
+ assert missing == []
+
def test_by_user_pagination_walks_past_a_page_where_nobody_was_active(self):
# Pages are sized in users, so a page of users who did nothing in the window yields no
# rows. Treating that as the end of the data would drop every later user.
@@ -351,8 +371,10 @@ class TestCursorTransport:
@parameterized.expand(
[
("agent_edits", {"data": []}, False),
+ ("dau", {"data": []}, False),
("by_user_agent_edits", {"data": {}, "pagination": {"hasNextPage": False}}, True),
("ai_code_commits", {"items": [], "totalCount": 0}, True),
+ ("ai_code_changes", {"items": [], "totalCount": 0}, True),
]
)
def test_analytics_endpoints_send_calendar_dates_as_query_params(self, endpoint, payload, paginated):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor_source.py
index 35f41ce4d786..54c6f5c729db 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cursor/tests/test_cursor_source.py
@@ -15,11 +15,15 @@ ALL_ENDPOINTS = [
"spend",
"agent_edits",
"tabs",
+ "dau",
+ "models",
+ "top_file_extensions",
"by_user_agent_edits",
"by_user_tabs",
"by_user_models",
"by_user_top_file_extensions",
"ai_code_commits",
+ "ai_code_changes",
]
@@ -68,11 +72,15 @@ class TestCursorSource:
("spend", False, None),
("agent_edits", True, "event_date"),
("tabs", True, "event_date"),
+ ("dau", True, "date"),
+ ("models", True, "date"),
+ ("top_file_extensions", True, "event_date"),
("by_user_agent_edits", True, "event_date"),
("by_user_tabs", True, "event_date"),
("by_user_models", True, "date"),
("by_user_top_file_extensions", True, "event_date"),
("ai_code_commits", True, "commitTs"),
+ ("ai_code_changes", True, "createdAt"),
]
)
def test_get_schemas_incremental_support(self, endpoint, supports_incremental, incremental_field):