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(web-analytics): add heatmap capture config schema (#102555)

Jordan Mryyan8e762ceacf17
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yaml
index 20e3d859165d..cbb95a3477f1 100644
--- a/.semgrep/rules/security/idor-team-scoped-models.yaml
+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml
@@ -334,6 +334,7 @@ rules:
|ResourceLink
|ScoreDefinition
|SavedHeatmap
+ |HeatmapCaptureConfigVersion
|ScheduledChange
|SessionGroupSummary
|SessionRecording
@@ -748,6 +749,7 @@ rules:
|ResourceLink
|ScoreDefinition
|SavedHeatmap
+ |HeatmapCaptureConfigVersion
|ScheduledChange
|SessionGroupSummary
|SessionRecording
diff --git a/posthog/migrations/1374_teamheatmapconfig_capture_enforcement_started_at_and_more.py b/posthog/migrations/1374_teamheatmapconfig_capture_enforcement_started_at_and_more.py
new file mode 100644
index 000000000000..36cc82dfcd99
--- /dev/null
+++ b/posthog/migrations/1374_teamheatmapconfig_capture_enforcement_started_at_and_more.py
@@ -0,0 +1,37 @@
+# Generated by Django 5.2.17 on 2026-09-11 18:55
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [("posthog", "1373_taggeditem_generic_pointer_unique")]
+
+ operations = [
+ migrations.AddField(
+ model_name="teamheatmapconfig",
+ name="capture_enforcement_started_at",
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name="teamheatmapconfig",
+ name="capture_mode",
+ field=models.CharField(
+ choices=[("all", "All URLs"), ("url_allowlist", "Only listed URLs")],
+ db_default="url_allowlist",
+ default="url_allowlist",
+ max_length=20,
+ ),
+ ),
+ migrations.AddField(
+ model_name="teamheatmapconfig",
+ name="capture_url_allowlist",
+ field=django.contrib.postgres.fields.ArrayField(
+ base_field=models.CharField(max_length=2000),
+ blank=True,
+ db_default=[],
+ default=list,
+ size=None,
+ ),
+ ),
+ ]
diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt
index bac358916eef..f8e87321530e 100644
--- a/posthog/migrations/max_migration.txt
+++ b/posthog/migrations/max_migration.txt
@@ -1 +1 @@
-1373_taggeditem_generic_pointer_unique
+1374_teamheatmapconfig_capture_enforcement_started_at_and_more
diff --git a/posthog/models/team/team_heatmap_config.py b/posthog/models/team/team_heatmap_config.py
index a11009b7d62a..8eeada7d8082 100644
--- a/posthog/models/team/team_heatmap_config.py
+++ b/posthog/models/team/team_heatmap_config.py
@@ -6,6 +6,10 @@ from posthog.rbac.decorators import field_access_control
class TeamHeatmapConfig(models.Model):
+ class CaptureMode(models.TextChoices):
+ ALL = "all", "All URLs"
+ URL_ALLOWLIST = "url_allowlist", "Only listed URLs"
+
team = models.OneToOneField(Team, on_delete=models.CASCADE, primary_key=True, db_constraint=False)
screenshot_secret = field_access_control(
@@ -14,3 +18,18 @@ class TeamHeatmapConfig(models.Model):
allowed_hostnames = field_access_control(
ArrayField(models.CharField(max_length=253), default=list, blank=True, db_default=[]), "project", "admin"
)
+
+ capture_mode = field_access_control(
+ models.CharField(
+ max_length=20,
+ choices=CaptureMode.choices,
+ default=CaptureMode.URL_ALLOWLIST,
+ db_default=CaptureMode.URL_ALLOWLIST,
+ ),
+ "project",
+ "admin",
+ )
+ capture_url_allowlist = field_access_control(
+ ArrayField(models.CharField(max_length=2000), default=list, blank=True, db_default=[]), "project", "admin"
+ )
+ capture_enforcement_started_at = models.DateTimeField(null=True, blank=True)
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index f001cef775f2..85545ee061fd 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -937,6 +937,10 @@ REMOTE_CONFIG_CDN_PURGE_ENDPOINT = get_from_env("REMOTE_CONFIG_CDN_PURGE_ENDPOIN
REMOTE_CONFIG_CDN_PURGE_TOKEN = get_from_env("REMOTE_CONFIG_CDN_PURGE_TOKEN", "")
REMOTE_CONFIG_CDN_PURGE_DOMAINS = get_list(os.getenv("REMOTE_CONFIG_CDN_PURGE_DOMAINS", ""))
+HEATMAP_URL_ALLOWLIST_ENFORCEMENT_ENABLED = get_from_env(
+ "HEATMAP_URL_ALLOWLIST_ENFORCEMENT_ENABLED", False, type_cast=str_to_bool
+)
+
# Versioned posthog-js S3 bucket — enables versioned JS content serving when set
POSTHOG_JS_S3_BUCKET = get_from_env("POSTHOG_JS_S3_BUCKET", "")
# CDN cache control for array.js responses
diff --git a/products/web_analytics/backend/migrations/0013_heatmapcaptureconfigversion.py b/products/web_analytics/backend/migrations/0013_heatmapcaptureconfigversion.py
new file mode 100644
index 000000000000..3b6697b44ab5
--- /dev/null
+++ b/products/web_analytics/backend/migrations/0013_heatmapcaptureconfigversion.py
@@ -0,0 +1,88 @@
+# Generated by Django 5.2.17 on 2026-09-11 18:56
+
+import django.utils.timezone
+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 = [
+ ("posthog", "1374_teamheatmapconfig_capture_enforcement_started_at_and_more"),
+ ("web_analytics", "0012_alter_savedheatmap_created_by_and_more"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="HeatmapCaptureConfigVersion",
+ fields=[
+ (
+ "id",
+ models.UUIDField(
+ default=posthog.uuidt.uuid7,
+ editable=False,
+ primary_key=True,
+ serialize=False,
+ ),
+ ),
+ (
+ "mode",
+ models.CharField(
+ choices=[
+ ("all", "All URLs"),
+ ("url_allowlist", "Only listed URLs"),
+ ],
+ max_length=20,
+ ),
+ ),
+ (
+ "patterns",
+ django.contrib.postgres.fields.ArrayField(
+ base_field=models.CharField(max_length=2000),
+ blank=True,
+ db_default=[],
+ default=list,
+ size=None,
+ ),
+ ),
+ (
+ "effective_from",
+ models.DateTimeField(default=django.utils.timezone.now),
+ ),
+ ("effective_to", models.DateTimeField(blank=True, null=True)),
+ (
+ "created_by",
+ models.ForeignKey(
+ blank=True,
+ db_constraint=False,
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="+",
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ (
+ "team",
+ models.ForeignKey(
+ db_constraint=False,
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="+",
+ to="posthog.team",
+ ),
+ ),
+ ],
+ options={
+ "db_table": "posthog_heatmapcaptureconfigversion",
+ "indexes": [
+ models.Index(
+ fields=["team", "effective_from", "effective_to"],
+ name="heatmap_capture_ver_team_idx",
+ )
+ ],
+ },
+ ),
+ ]
diff --git a/products/web_analytics/backend/migrations/max_migration.txt b/products/web_analytics/backend/migrations/max_migration.txt
index 0ae77494427d..da60a187630c 100644
--- a/products/web_analytics/backend/migrations/max_migration.txt
+++ b/products/web_analytics/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0012_alter_savedheatmap_created_by_and_more
+0013_heatmapcaptureconfigversion
diff --git a/products/web_analytics/backend/models/__init__.py b/products/web_analytics/backend/models/__init__.py
index 9816a12b9f14..09954cc564f7 100644
--- a/products/web_analytics/backend/models/__init__.py
+++ b/products/web_analytics/backend/models/__init__.py
@@ -1,4 +1,5 @@
from .content_autopilot import ContentAutopilotProposal, ContentAutopilotRun, ContentAutopilotSiteProfile
+from .heatmap_capture_config_version import HeatmapCaptureConfigVersion
from .heatmap_saved import HeatmapSnapshot, SavedHeatmap
from .web_analytics_achievement_progress import WebAnalyticsAchievementProgress
from .web_analytics_filter_preset import WebAnalyticsFilterPreset
@@ -7,6 +8,7 @@ from .web_analytics_user_config import WebAnalyticsUserConfig
from .web_analytics_visit import WebAnalyticsVisit
__all__ = [
+ "HeatmapCaptureConfigVersion",
"HeatmapSnapshot",
"SavedHeatmap",
"ContentAutopilotProposal",
diff --git a/products/web_analytics/backend/models/heatmap_capture_config_version.py b/products/web_analytics/backend/models/heatmap_capture_config_version.py
new file mode 100644
index 000000000000..6fcd8fbc98ad
--- /dev/null
+++ b/products/web_analytics/backend/models/heatmap_capture_config_version.py
@@ -0,0 +1,24 @@
+from django.contrib.postgres.fields import ArrayField
+from django.db import models
+from django.utils import timezone
+
+from posthog.models.scoping.root_mixin import TeamScopedRootMixin
+from posthog.models.team.team_heatmap_config import TeamHeatmapConfig
+from posthog.models.utils import UUIDModel
+
+
+class HeatmapCaptureConfigVersion(TeamScopedRootMixin, UUIDModel):
+ team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+")
+ mode = models.CharField(max_length=20, choices=TeamHeatmapConfig.CaptureMode.choices)
+ patterns = ArrayField(models.CharField(max_length=2000), default=list, blank=True, db_default=[])
+ effective_from = models.DateTimeField(default=timezone.now)
+ effective_to = models.DateTimeField(null=True, blank=True)
+ created_by = models.ForeignKey(
+ "posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False, related_name="+"
+ )
+
+ class Meta:
+ db_table = "posthog_heatmapcaptureconfigversion"
+ indexes = [
+ models.Index(fields=["team", "effective_from", "effective_to"], name="heatmap_capture_ver_team_idx"),
+ ]