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): add user configuration model (#92856)

Arthur Moreira de Deus9f868969c6fc
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yaml
index efa94e30d684..b2c325147fef 100644
--- a/.semgrep/rules/security/idor-team-scoped-models.yaml
+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml
@@ -207,6 +207,7 @@ rules:
|TeamMCPGatewayConfig
|TeamSessionSummariesConfig
|TeamWorkflowsConfig
+ |UserCustomerAnalyticsConfig
|FieldNote
|FileSystem
|FileSystemFolderInstructions
@@ -594,6 +595,7 @@ rules:
|TeamMCPGatewayConfig
|TeamSessionSummariesConfig
|TeamWorkflowsConfig
+ |UserCustomerAnalyticsConfig
|FieldNote
|FileSystem
|FileSystemFolderInstructions
diff --git a/products/customer_analytics/backend/migrations/0046_usercustomeranalyticsconfig.py b/products/customer_analytics/backend/migrations/0046_usercustomeranalyticsconfig.py
new file mode 100644
index 000000000000..d848d9c5cd9e
--- /dev/null
+++ b/products/customer_analytics/backend/migrations/0046_usercustomeranalyticsconfig.py
@@ -0,0 +1,66 @@
+# Generated by Django 5.2.17 on 2026-09-01 17:10
+
+import django.db.models.deletion
+import django.contrib.postgres.fields
+from django.conf import settings
+from django.db import migrations, models
+
+import posthog.uuidt
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("customer_analytics", "0045_custom_property_definition_link_display_type"),
+ ("posthog", "1333_uploaded_media_library_index"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="UserCustomerAnalyticsConfig",
+ fields=[
+ ("updated_at", models.DateTimeField(auto_now=True, null=True)),
+ (
+ "id",
+ models.UUIDField(
+ default=posthog.uuidt.uuid7,
+ editable=False,
+ primary_key=True,
+ serialize=False,
+ ),
+ ),
+ (
+ "pinned_custom_property_definition_ids",
+ django.contrib.postgres.fields.ArrayField(base_field=models.UUIDField(), default=list, size=None),
+ ),
+ ("properties", models.JSONField(default=dict)),
+ ("created_at", models.DateTimeField(auto_now_add=True)),
+ (
+ "team",
+ models.ForeignKey(
+ db_constraint=False,
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="+",
+ to="posthog.team",
+ ),
+ ),
+ (
+ "user",
+ models.ForeignKey(
+ db_constraint=False,
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="+",
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ ],
+ options={
+ "constraints": [
+ models.UniqueConstraint(
+ fields=("team", "user"),
+ name="unique_user_customer_analytics_config_per_team",
+ )
+ ],
+ },
+ ),
+ ]
diff --git a/products/customer_analytics/backend/migrations/max_migration.txt b/products/customer_analytics/backend/migrations/max_migration.txt
index 886c31c69a57..eaae41f38b6e 100644
--- a/products/customer_analytics/backend/migrations/max_migration.txt
+++ b/products/customer_analytics/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0045_custom_property_definition_link_display_type
+0046_usercustomeranalyticsconfig
diff --git a/products/customer_analytics/backend/models/__init__.py b/products/customer_analytics/backend/models/__init__.py
index 256e0b3d3ea1..fb42fe9b7cac 100644
--- a/products/customer_analytics/backend/models/__init__.py
+++ b/products/customer_analytics/backend/models/__init__.py
@@ -32,6 +32,7 @@ from .feature_request import (
from .meeting import Meeting, MeetingParticipant, MeetingResponseStatus, MeetingStatus
from .relationship import AccountRelationship, AccountRelationshipDefinition
from .team_customer_analytics_config import TeamCustomerAnalyticsConfig
+from .user_customer_analytics_config import UserCustomerAnalyticsConfig
__all__ = [
"CANONICAL_DISPLAY_TYPE_BY_NAME",
@@ -75,4 +76,5 @@ __all__ = [
"SyncTrigger",
"TargetType",
"TeamCustomerAnalyticsConfig",
+ "UserCustomerAnalyticsConfig",
]
diff --git a/products/customer_analytics/backend/models/user_customer_analytics_config.py b/products/customer_analytics/backend/models/user_customer_analytics_config.py
new file mode 100644
index 000000000000..a85117506255
--- /dev/null
+++ b/products/customer_analytics/backend/models/user_customer_analytics_config.py
@@ -0,0 +1,21 @@
+from django.contrib.postgres.fields import ArrayField
+from django.db import models
+
+from posthog.models.scoping.root_mixin import TeamScopedRootMixin
+from posthog.models.utils import UpdatedMetaFields, UUIDModel
+
+
+class UserCustomerAnalyticsConfig(TeamScopedRootMixin, UUIDModel, UpdatedMetaFields):
+ team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+")
+ user = models.ForeignKey("posthog.User", on_delete=models.CASCADE, db_constraint=False, related_name="+")
+ pinned_custom_property_definition_ids = ArrayField(models.UUIDField(), default=list)
+ properties = models.JSONField(default=dict)
+ created_at = models.DateTimeField(auto_now_add=True)
+
+ class Meta:
+ constraints = [
+ models.UniqueConstraint(
+ fields=["team", "user"],
+ name="unique_user_customer_analytics_config_per_team",
+ )
+ ]
diff --git a/products/customer_analytics/backend/models/user_customer_analytics_config_test.py b/products/customer_analytics/backend/models/user_customer_analytics_config_test.py
new file mode 100644
index 000000000000..e4e32ca3ffe3
--- /dev/null
+++ b/products/customer_analytics/backend/models/user_customer_analytics_config_test.py
@@ -0,0 +1,14 @@
+from posthog.test.base import BaseTest
+
+from django.db import IntegrityError, transaction
+
+from products.customer_analytics.backend.models import UserCustomerAnalyticsConfig
+from products.customer_analytics.backend.models.team_scoped_test_base import TeamScopedTestMixin
+
+
+class TestUserCustomerAnalyticsConfig(TeamScopedTestMixin, BaseTest):
+ def test_config_is_unique_for_user_and_team(self) -> None:
+ UserCustomerAnalyticsConfig.objects.create(team=self.team, user=self.user)
+
+ with self.assertRaises(IntegrityError), transaction.atomic():
+ UserCustomerAnalyticsConfig.objects.create(team=self.team, user=self.user)