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(customer-analytics): Notify account owners of usage spikes (#62783)

Arthur Moreira de Deus8de4be8f208b
diff --git a/ee/billing/queue/BillingConsumer.py b/ee/billing/queue/BillingConsumer.py
index b8a1f86371de..472e63a92374 100644
--- a/ee/billing/queue/BillingConsumer.py
+++ b/ee/billing/queue/BillingConsumer.py
@@ -9,11 +9,17 @@ from posthog.cloud_utils import get_cached_instance_license
from posthog.exceptions_capture import capture_exception
from posthog.models.organization import Organization
+from products.customer_analytics.backend.services.usage_spike_notifications import notify_managers_of_usage_spike
+
from ee.billing.billing_manager import BillingManager
from ee.sqs.SQSConsumer import SQSConsumer
logger = logging.getLogger(__name__)
+# PostHog's own team on Cloud US — owns the Customer-analytics accounts that inbound billing
+# usage-spike events resolve against. Billing emits these spike messages to the US queue.
+POSTHOG_SELF_TEAM_ID = 2
+
class BillingConsumer(SQSConsumer):
"""
@@ -44,6 +50,8 @@ class BillingConsumer(SQSConsumer):
# Process different message types
if message_type == "billing_customer_update":
self._process_billing_customer_update(body)
+ elif message_type == "usage_spike_detected":
+ self._process_usage_spike_detected(body)
# Add more message types as needed
# elif message_type == "invoice_created":
# self._process_invoice_created(body)
@@ -146,3 +154,23 @@ class BillingConsumer(SQSConsumer):
billing_manager.update_org_details(organization, data)
logger.info(f"Successfully processed billing customer update for {organization_id}")
+
+ def _process_usage_spike_detected(self, body: dict[str, Any]) -> None:
+ """Route a billing-detected usage spike to the account's CSM and Account Executive."""
+ data = body.get("data", {})
+ spike_id = data.get("spike_id")
+
+ if not spike_id:
+ logger.error("Usage spike message is missing spike_id")
+ capture_exception(Exception("Usage spike message is missing spike_id"))
+ return
+
+ notify_managers_of_usage_spike(
+ team_id=POSTHOG_SELF_TEAM_ID,
+ spike_id=str(spike_id),
+ spikes=data.get("spikes", []),
+ organization_id=data.get("organization_id"),
+ billing_id=data.get("billing_id"),
+ stripe_customer_id=data.get("stripe_customer_id"),
+ detected_at=data.get("detected_at"),
+ )
diff --git a/ee/billing/test/test_billing_consumer.py b/ee/billing/test/test_billing_consumer.py
new file mode 100644
index 000000000000..56da4b384189
--- /dev/null
+++ b/ee/billing/test/test_billing_consumer.py
@@ -0,0 +1,42 @@
+from posthog.test.base import BaseTest
+from unittest.mock import patch
+
+from ee.billing.queue.BillingConsumer import POSTHOG_SELF_TEAM_ID, BillingConsumer
+
+CONSUMER = "ee.billing.queue.BillingConsumer"
+
+
+class TestBillingConsumerUsageSpike(BaseTest):
+ def _build_consumer(self) -> BillingConsumer:
+ with patch("ee.sqs.SQSConsumer.boto3"):
+ return BillingConsumer(queue_url="http://example/queue", region_name="us-east-1")
+
+ @patch(f"{CONSUMER}.notify_managers_of_usage_spike")
+ def test_dispatches_usage_spike(self, mock_notify):
+ self._build_consumer()._process_usage_spike_detected(
+ {
+ "type": "usage_spike_detected",
+ "data": {
+ "spike_id": "spike-1",
+ "organization_id": "org-1",
+ "spikes": [{"metric": "events", "factor": 3}],
+ "detected_at": "2026-06-09",
+ },
+ }
+ )
+ mock_notify.assert_called_once_with(
+ team_id=POSTHOG_SELF_TEAM_ID,
+ spike_id="spike-1",
+ spikes=[{"metric": "events", "factor": 3}],
+ organization_id="org-1",
+ billing_id=None,
+ stripe_customer_id=None,
+ detected_at="2026-06-09",
+ )
+
+ @patch(f"{CONSUMER}.capture_exception")
+ @patch(f"{CONSUMER}.notify_managers_of_usage_spike")
+ def test_missing_spike_id_skips_and_captures(self, mock_notify, mock_capture):
+ self._build_consumer()._process_usage_spike_detected({"data": {"organization_id": "org-1"}})
+ mock_notify.assert_not_called()
+ mock_capture.assert_called_once()
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx
index 920fee5c4c25..4e9e913f3210 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx
@@ -54,6 +54,7 @@ const SOURCE_TYPE_TO_PATH: Record<NotificationEventSourceTypeEnumApi, (id: strin
survey: (id) => urls.survey(id),
experiment: (id) => urls.experiment(id),
error_tracking: (id) => urls.errorTrackingIssue(id),
+ customer_analytics: () => urls.customerAnalyticsAccounts(),
}
export interface NotificationGroup {
diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx
index 6a23201e762e..cd974d86733e 100644
--- a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx
+++ b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx
@@ -45,6 +45,10 @@ export const REALTIME_NOTIFICATION_TYPE_META: Record<string, { label: string; de
label: 'Projects created',
description: 'When a member creates a new project in your organization',
},
+ usage_spike: {
+ label: 'Usage spikes',
+ description: 'When billing detects a usage spike for one of your accounts',
+ },
}
export function NotificationRow({
diff --git a/frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx b/frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx
index 64213aeda356..000a5395d69f 100644
--- a/frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx
+++ b/frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx
@@ -6,6 +6,7 @@ import {
IconFolder,
IconNotification,
IconPlug,
+ IconTrending,
IconWarning,
} from '@posthog/icons'
import { lemonToast } from '@posthog/lemon-ui'
@@ -23,6 +24,7 @@ const NOTIFICATION_TYPE_ICONS: Record<string, JSX.Element> = {
issue_assigned: <IconBug className="size-5 text-primary shrink-0" />,
experiment_concluded: <IconFlask className="size-5 text-primary shrink-0" />,
project_created: <IconFolder className="size-5 text-primary shrink-0" />,
+ usage_spike: <IconTrending className="size-5 text-warning shrink-0" />,
}
export function getNotificationIcon(notificationType: string): JSX.Element {
diff --git a/products/customer_analytics/backend/api/serializers.py b/products/customer_analytics/backend/api/serializers.py
index 1b4a4f0d4940..78535c267f66 100644
--- a/products/customer_analytics/backend/api/serializers.py
+++ b/products/customer_analytics/backend/api/serializers.py
@@ -138,7 +138,10 @@ class AccountSerializer(TaggedItemSerializerMixin, serializers.ModelSerializer):
required=False,
allow_null=True,
allow_blank=True,
- help_text="Identifier for the account in an external system (e.g. CRM ID). Optional.",
+ help_text=(
+ "Identifier linking this account to its source customer — the analytics group key "
+ "(the customer's organization id), used to match billing and external records. Optional."
+ ),
)
properties = AccountPropertiesField(
source="_properties",
diff --git a/products/customer_analytics/backend/services/usage_spike_notifications.py b/products/customer_analytics/backend/services/usage_spike_notifications.py
new file mode 100644
index 000000000000..7aeb90f35c40
--- /dev/null
+++ b/products/customer_analytics/backend/services/usage_spike_notifications.py
@@ -0,0 +1,187 @@
+from typing import Any
+
+import structlog
+import posthoganalytics
+
+from posthog.exceptions_capture import capture_exception
+
+from products.customer_analytics.backend.constants import CUSTOMER_ANALYTICS_CSP_FLAG
+from products.customer_analytics.backend.models import Account
+from products.notifications.backend.facade.api import (
+ NotificationData,
+ NotificationType,
+ Priority,
+ SourceType,
+ TargetType,
+ create_notification,
+ has_been_dispatched,
+)
+
+logger = structlog.get_logger(__name__)
+
+TITLE_MAX_LENGTH = 100
+BODY_MAX_LENGTH = 200
+
+
+def notify_managers_of_usage_spike(
+ *,
+ team_id: int,
+ spike_id: str,
+ spikes: list[dict[str, Any]],
+ organization_id: str | None = None,
+ billing_id: str | None = None,
+ stripe_customer_id: str | None = None,
+ detected_at: str | None = None,
+) -> None:
+ """Notify a Customer-analytics account's CSM and Account Executive that billing detected a
+ usage spike for that customer. The account is resolved within `team_id` (the team that owns
+ the Customer-analytics accounts). Idempotent per (manager, spike). Never raises — the SQS
+ consumer must ack the message regardless; failures are captured to error tracking."""
+ try:
+ account = _find_account(
+ team_id=team_id,
+ organization_id=organization_id,
+ billing_id=billing_id,
+ stripe_customer_id=stripe_customer_id,
+ )
+ if account is None:
+ logger.info(
+ "usage_spike.account_not_found",
+ organization_id=organization_id,
+ billing_id=billing_id,
+ stripe_customer_id=stripe_customer_id,
+ )
+ return
+
+ if not _is_csp_enabled(account):
+ logger.info("usage_spike.csp_disabled", account_id=str(account.id))
+ return
+
+ manager_user_ids = _get_manager_user_ids(account)
+ if not manager_user_ids:
+ logger.info("usage_spike.no_managers", account_id=str(account.id))
+ return
+
+ title = f"Usage spike: {account.name}"[:TITLE_MAX_LENGTH]
+ body = _build_body(spikes, detected_at)[:BODY_MAX_LENGTH]
+ # No per-account detail route exists, so deep-link to the accounts list.
+ source_url = f"/project/{account.team.project_id}/customer_analytics/accounts"
+
+ for user_id in manager_user_ids:
+ _notify_manager(
+ account=account,
+ user_id=user_id,
+ spike_id=spike_id,
+ title=title,
+ body=body,
+ source_url=source_url,
+ )
+ except Exception as e:
+ capture_exception(e)
+ logger.exception("usage_spike.dispatch_failed", spike_id=spike_id)
+
+
+def _find_account(
+ *,
+ team_id: int,
+ organization_id: str | None,
+ billing_id: str | None,
+ stripe_customer_id: str | None,
+) -> Account | None:
+ # Scope to the team that owns the accounts: account identifiers (external_id/billing_id/
+ # stripe_customer_id) are user-editable, so an unscoped lookup could resolve a billing event
+ # to a customer-controlled account row. external_id is unique per team, so this also makes
+ # that lookup unambiguous.
+ candidates = Account.objects.for_team(team_id).select_related("team").order_by("created_at")
+ for lookup, value in (
+ ("external_id", organization_id),
+ ("_properties__billing_id", billing_id),
+ ("_properties__stripe_customer_id", stripe_customer_id),
+ ):
+ if not value:
+ continue
+ # The _properties__* JSON fields have no uniqueness constraint; fetch up to 2 to detect
+ # (and warn about) an ambiguous match without loading all rows.
+ matches = list(candidates.filter(**{lookup: str(value)})[:2])
+ if not matches:
+ continue
+ if len(matches) > 1:
+ logger.warning("usage_spike.multiple_accounts_matched", lookup=lookup, value=str(value))
+ return matches[0]
+ return None
+
+
+def _is_csp_enabled(account: Account) -> bool:
+ organization_id = str(account.team.organization_id)
+ return bool(
+ posthoganalytics.feature_enabled(
+ CUSTOMER_ANALYTICS_CSP_FLAG,
+ organization_id,
+ groups={"organization": organization_id},
+ only_evaluate_locally=False,
+ send_feature_flag_events=False,
+ )
+ )
+
+
+def _get_manager_user_ids(account: Account) -> list[int]:
+ properties = account.properties
+ user_ids: list[int] = []
+ for assignment in (properties.csm, properties.account_executive):
+ if assignment is not None and assignment.id not in user_ids:
+ user_ids.append(assignment.id)
+ return user_ids
+
+
+def _build_body(spikes: list[dict[str, Any]], detected_at: str | None) -> str:
+ summary = _summarize_spikes(spikes)
+ return f"{summary} — detected {detected_at}" if detected_at else summary
+
+
+def _summarize_spikes(spikes: list[dict[str, Any]]) -> str:
+ parts: list[str] = []
+ for spike in spikes:
+ metric = spike.get("metric") or "usage"
+ factor = spike.get("factor")
+ direction = spike.get("direction") or "up"
+ parts.append(f"{metric} {factor}× ({direction})" if factor is not None else str(metric))
+ return ", ".join(parts) if parts else "Unusual usage detected"
+
+
+def _notify_manager(
+ *,
+ account: Account,
+ user_id: int,
+ spike_id: str,
+ title: str,
+ body: str,
+ source_url: str,
+) -> None:
+ try:
+ if has_been_dispatched(
+ notification_type=NotificationType.USAGE_SPIKE,
+ target_type=TargetType.USER,
+ target_id=str(user_id),
+ resource_id=str(account.id),
+ source_id=spike_id,
+ ):
+ return
+ create_notification(
+ NotificationData(
+ team_id=account.team_id,
+ notification_type=NotificationType.USAGE_SPIKE,
+ priority=Priority.CRITICAL,
+ title=title,
+ body=body,
+ target_type=TargetType.USER,
+ target_id=str(user_id),
+ resource_type=None,
+ resource_id=str(account.id),
+ source_url=source_url,
+ source_type=SourceType.CUSTOMER_ANALYTICS,
+ source_id=spike_id,
+ )
+ )
+ except Exception as e:
+ capture_exception(e)
+ logger.exception("usage_spike.notify_failed", account_id=str(account.id), user_id=user_id)
diff --git a/products/customer_analytics/backend/test/test_usage_spike_notifications.py b/products/customer_analytics/backend/test/test_usage_spike_notifications.py
new file mode 100644
index 000000000000..792990a44f17
--- /dev/null
+++ b/products/customer_analytics/backend/test/test_usage_spike_notifications.py
@@ -0,0 +1,121 @@
+from posthog.test.base import BaseTest
+from unittest.mock import patch
+
+from parameterized import parameterized
+
+from posthog.models import Team
+
+from products.customer_analytics.backend.services.usage_spike_notifications import notify_managers_of_usage_spike
+from products.customer_analytics.backend.test.factories import create_account
+from products.notifications.backend.facade.enums import NotificationType, Priority, SourceType, TargetType
+
+SERVICE = "products.customer_analytics.backend.services.usage_spike_notifications"
+
+SPIKES = [{"metric": "events", "factor": 3.2, "direction": "up", "percent_change": 220}]
+
+
+@patch(f"{SERVICE}.has_been_dispatched", return_value=False)
+@patch(f"{SERVICE}.create_notification")
+class TestNotifyManagersOfUsageSpike(BaseTest):
+ def setUp(self):
+ super().setUp()
+ csp_patcher = patch("posthoganalytics.feature_enabled", return_value=True)
+ self.mock_feature_enabled = csp_patcher.start()
+ self.addCleanup(csp_patcher.stop)
+
+ def _notify_managers(self, *, team_id: int | None = None, **kwargs):
+ notify_managers_of_usage_spike(
+ team_id=self.team.id if team_id is None else team_id, spike_id="spike-1", spikes=SPIKES, **kwargs
+ )
+
+ def _create_account_with_managers(self, *, csm_id: int | None = 101, ae_id: int | None = 102, **account_kwargs):
+ properties: dict = {}
+ if csm_id is not None:
+ properties["csm"] = {"id": csm_id, "email": f"csm{csm_id}@example.com"}
+ if ae_id is not None:
+ properties["account_executive"] = {"id": ae_id, "email": f"ae{ae_id}@example.com"}
+ return create_account(team_id=self.team.id, name="Acme Corp", properties=properties, **account_kwargs)
+
+ @parameterized.expand(
+ [
+ ("external_id", {"external_id": "org-123"}, {}, {"organization_id": "org-123"}),
+ ("billing_id", {}, {"billing_id": "bill-9"}, {"billing_id": "bill-9"}),
+ ("stripe_customer_id", {}, {"stripe_customer_id": "cus_42"}, {"stripe_customer_id": "cus_42"}),
+ ]
+ )
+ def test_matches_account_by_identifier(
+ self, mock_create, _mock_dispatched, _name, account_kwargs, properties_extra, lookup
+ ):
+ account = self._create_account_with_managers(**account_kwargs)
+ if properties_extra:
+ account.properties = {**account.properties.model_dump(mode="json"), **properties_extra}
+ account.save()
+
+ self._notify_managers(**lookup)
+
+ assert mock_create.call_count == 2
+ target_ids = {call.args[0].target_id for call in mock_create.call_args_list}
+ assert target_ids == {"101", "102"}
+
+ def test_no_match_does_not_notify(self, mock_create, mock_dispatched):
+ self._create_account_with_managers(external_id="org-123")
+ self._notify_managers(organization_id="does-not-exist")
+ mock_create.assert_not_called()
+ mock_dispatched.assert_not_called()
+
+ def test_account_on_other_team_is_not_matched(self, mock_create, mock_dispatched):
+ other_team = Team.objects.create(organization=self.organization, name="Other")
+ create_account(
+ team_id=other_team.id,
+ name="Acme Corp",
+ properties={"csm": {"id": 101, "email": "[email protected]"}},
+ external_id="org-123",
+ )
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_not_called()
+ mock_dispatched.assert_not_called()
+
+ def test_account_without_managers_does_not_notify(self, mock_create, _mock_dispatched):
+ self._create_account_with_managers(csm_id=None, ae_id=None, external_id="org-123")
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_not_called()
+
+ def test_csp_disabled_does_not_notify(self, mock_create, mock_dispatched):
+ self.mock_feature_enabled.return_value = False
+ self._create_account_with_managers(external_id="org-123")
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_not_called()
+ mock_dispatched.assert_not_called()
+
+ def test_dispatch_never_raises_on_unexpected_error(self, mock_create, _mock_dispatched):
+ with patch(f"{SERVICE}._find_account", side_effect=RuntimeError("boom")):
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_not_called()
+
+ def test_dedupes_when_csm_and_ae_are_same_user(self, mock_create, _mock_dispatched):
+ self._create_account_with_managers(csm_id=55, ae_id=55, external_id="org-123")
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_called_once()
+ assert mock_create.call_args.args[0].target_id == "55"
+
+ def test_idempotent_when_already_dispatched(self, mock_create, mock_dispatched):
+ mock_dispatched.return_value = True
+ self._create_account_with_managers(external_id="org-123")
+ self._notify_managers(organization_id="org-123")
+ mock_create.assert_not_called()
+
+ def test_notification_content(self, mock_create, _mock_dispatched):
+ account = self._create_account_with_managers(csm_id=101, ae_id=None, external_id="org-123")
+ self._notify_managers(organization_id="org-123", detected_at="2026-06-09")
+
+ data = mock_create.call_args.args[0]
+ assert data.notification_type == NotificationType.USAGE_SPIKE
+ assert data.priority == Priority.CRITICAL
+ assert data.source_type == SourceType.CUSTOMER_ANALYTICS
+ assert data.target_type == TargetType.USER
+ assert data.team_id == self.team.id
+ assert data.resource_id == str(account.id)
+ assert data.source_id == "spike-1"
+ assert data.title == "Usage spike: Acme Corp"
+ assert data.body == "events 3.2× (up) — detected 2026-06-09"
+ assert data.source_url == f"/project/{self.team.project_id}/customer_analytics/accounts"
diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.ts
index 35c47c2506e3..b1a47df923ba 100644
--- a/products/customer_analytics/frontend/generated/api.schemas.ts
+++ b/products/customer_analytics/frontend/generated/api.schemas.ts
@@ -54,7 +54,7 @@ export interface AccountApi {
*/
name: string
/**
- * Identifier for the account in an external system (e.g. CRM ID). Optional.
+ * Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional.
* @maxLength 400
* @nullable
*/
@@ -217,7 +217,7 @@ export interface PatchedAccountApi {
*/
name?: string
/**
- * Identifier for the account in an external system (e.g. CRM ID). Optional.
+ * Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional.
* @maxLength 400
* @nullable
*/
diff --git a/products/customer_analytics/frontend/generated/api.zod.ts b/products/customer_analytics/frontend/generated/api.zod.ts
index 80fc154fccac..6923d19d6539 100644
--- a/products/customer_analytics/frontend/generated/api.zod.ts
+++ b/products/customer_analytics/frontend/generated/api.zod.ts
@@ -20,7 +20,9 @@ export const AccountsCreateBody = /* @__PURE__ */ zod
.string()
.max(accountsCreateBodyExternalIdMax)
.nullish()
- .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ .describe(
+ "Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional."
+ ),
properties: zod
.object({
csm: zod
@@ -83,7 +85,9 @@ export const AccountsUpdateBody = /* @__PURE__ */ zod
.string()
.max(accountsUpdateBodyExternalIdMax)
.nullish()
- .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ .describe(
+ "Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional."
+ ),
properties: zod
.object({
csm: zod
@@ -138,7 +142,9 @@ export const AccountsPartialUpdateBody = /* @__PURE__ */ zod
.string()
.max(accountsPartialUpdateBodyExternalIdMax)
.nullish()
- .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ .describe(
+ "Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional."
+ ),
properties: zod
.object({
csm: zod
diff --git a/products/notifications/backend/facade/enums.py b/products/notifications/backend/facade/enums.py
index 0eaab2803617..a15818085e78 100644
--- a/products/notifications/backend/facade/enums.py
+++ b/products/notifications/backend/facade/enums.py
@@ -14,6 +14,7 @@ class NotificationType(str, Enum):
EXPERIMENT_CONCLUDED = "experiment_concluded"
PIPELINE_FAILURE = "pipeline_failure"
PROJECT_CREATED = "project_created"
+ USAGE_SPIKE = "usage_spike"
class Priority(str, Enum):
@@ -37,6 +38,7 @@ class SourceType(str, Enum):
SURVEY = "survey"
EXPERIMENT = "experiment"
ERROR_TRACKING = "error_tracking"
+ CUSTOMER_ANALYTICS = "customer_analytics"
class NotificationOnlyResourceType(str, Enum):
diff --git a/products/notifications/backend/migrations/0012_alter_notificationevent_notification_type.py b/products/notifications/backend/migrations/0012_alter_notificationevent_notification_type.py
new file mode 100644
index 000000000000..421d0186a02c
--- /dev/null
+++ b/products/notifications/backend/migrations/0012_alter_notificationevent_notification_type.py
@@ -0,0 +1,30 @@
+# Generated by Django 5.2.14 on 2026-06-09 21:29
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("notifications", "0011_alter_notificationevent_notification_type"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="notificationevent",
+ name="notification_type",
+ field=models.CharField(
+ choices=[
+ ("comment_mention", "COMMENT_MENTION"),
+ ("alert_firing", "ALERT_FIRING"),
+ ("issue_assigned", "ISSUE_ASSIGNED"),
+ ("approval_requested", "APPROVAL_REQUESTED"),
+ ("approval_resolved", "APPROVAL_RESOLVED"),
+ ("experiment_concluded", "EXPERIMENT_CONCLUDED"),
+ ("pipeline_failure", "PIPELINE_FAILURE"),
+ ("project_created", "PROJECT_CREATED"),
+ ("usage_spike", "USAGE_SPIKE"),
+ ],
+ max_length=32,
+ ),
+ ),
+ ]
diff --git a/products/notifications/backend/migrations/max_migration.txt b/products/notifications/backend/migrations/max_migration.txt
index 3d1b0d5f4f30..dafb13aee25e 100644
--- a/products/notifications/backend/migrations/max_migration.txt
+++ b/products/notifications/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0011_alter_notificationevent_notification_type
+0012_alter_notificationevent_notification_type
diff --git a/products/notifications/frontend/generated/api.schemas.ts b/products/notifications/frontend/generated/api.schemas.ts
index 67dab364e95b..8101853a5f4a 100644
--- a/products/notifications/frontend/generated/api.schemas.ts
+++ b/products/notifications/frontend/generated/api.schemas.ts
@@ -16,6 +16,7 @@
* * `survey` - SURVEY
* * `experiment` - EXPERIMENT
* * `error_tracking` - ERROR_TRACKING
+ * * `customer_analytics` - CUSTOMER_ANALYTICS
*/
export type NotificationEventSourceTypeEnumApi =
(typeof NotificationEventSourceTypeEnumApi)[keyof typeof NotificationEventSourceTypeEnumApi]
@@ -29,6 +30,7 @@ export const NotificationEventSourceTypeEnumApi = {
Survey: 'survey',
Experiment: 'experiment',
ErrorTracking: 'error_tracking',
+ CustomerAnalytics: 'customer_analytics',
} as const
export interface NotificationEventApi {
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index e3d354aca279..39c76df8b3f5 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -104,7 +104,7 @@ export namespace Schemas {
*/
name: string;
/**
- * Identifier for the account in an external system (e.g. CRM ID). Optional.
+ * Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional.
* @maxLength 400
* @nullable
*/
@@ -24144,6 +24144,7 @@ export namespace Schemas {
* * `survey` - SURVEY
* * `experiment` - EXPERIMENT
* * `error_tracking` - ERROR_TRACKING
+ * * `customer_analytics` - CUSTOMER_ANALYTICS
*/
export type NotificationEventSourceTypeEnum = typeof NotificationEventSourceTypeEnum[keyof typeof NotificationEventSourceTypeEnum];
@@ -24157,6 +24158,7 @@ export namespace Schemas {
Survey: 'survey',
Experiment: 'experiment',
ErrorTracking: 'error_tracking',
+ CustomerAnalytics: 'customer_analytics',
} as const;
export interface NotificationEvent {
@@ -29104,7 +29106,7 @@ export namespace Schemas {
*/
name?: string;
/**
- * Identifier for the account in an external system (e.g. CRM ID). Optional.
+ * Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional.
* @maxLength 400
* @nullable
*/
diff --git a/services/mcp/src/generated/customer_analytics/api.ts b/services/mcp/src/generated/customer_analytics/api.ts
index 1b57b72dc54b..faae57f321b3 100644
--- a/services/mcp/src/generated/customer_analytics/api.ts
+++ b/services/mcp/src/generated/customer_analytics/api.ts
@@ -61,7 +61,9 @@ export const AccountsCreateBody = /* @__PURE__ */ zod
.string()
.max(accountsCreateBodyExternalIdMax)
.nullish()
- .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ .describe(
+ "Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional."
+ ),
properties: zod
.object({
csm: zod
@@ -189,7 +191,9 @@ export const AccountsPartialUpdateBody = /* @__PURE__ */ zod
.string()
.max(accountsPartialUpdateBodyExternalIdMax)
.nullish()
- .describe('Identifier for the account in an external system (e.g. CRM ID). Optional.'),
+ .describe(
+ "Identifier linking this account to its source customer — the analytics group key (the customer's organization id), used to match billing and external records. Optional."
+ ),
properties: zod
.object({
csm: zod
diff --git a/tach.toml b/tach.toml
index 06a0f3fd71ed..8bf1baf8126f 100644
--- a/tach.toml
+++ b/tach.toml
@@ -555,6 +555,7 @@ depends_on = [
"posthog",
"products.data_warehouse",
"products.notebooks",
+ "products.notifications",
"products.product_analytics",
]
layer = "modules"