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.

fix(analytics): skip lifecycle events from the hosted dev deployment (#78586)

Ian Vanagasd3e130fe21bc
diff --git a/posthog/event_usage.py b/posthog/event_usage.py
index 615bedc555e2..1cdf1555b47c 100644
--- a/posthog/event_usage.py
+++ b/posthog/event_usage.py
@@ -22,12 +22,16 @@ from posthog.oauth_provenance import get_oauth_client_id, is_first_party_oauth_c
from posthog.settings import SITE_URL
from posthog.synthetic_user import SyntheticUser
from posthog.temporal.oauth import POSTHOG_AI_OAUTH_APP_CLIENT_IDS, SIGNALS_OAUTH_APP_CLIENT_IDS
-from posthog.utils import get_instance_realm
+from posthog.utils import get_instance_realm, get_instance_region
if TYPE_CHECKING:
from rest_framework.request import Request
+def _is_hosted_dev_deployment() -> bool:
+ return get_instance_region() == "DEV"
+
+
def report_user_signed_up(
user: User,
is_instance_first_user: bool,
@@ -45,6 +49,9 @@ def report_user_signed_up(
Reports that a new user has joined. Only triggered when a new user is actually created (i.e. when an existing user
joins a new organization, this event is **not** triggered; see `report_user_joined_organization`).
"""
+ if _is_hosted_dev_deployment():
+ return
+
if not user.distinct_id:
return
@@ -629,6 +636,9 @@ def report_user_or_team_action(
def report_organization_deleted(user: User, organization: Organization):
+ if _is_hosted_dev_deployment():
+ return
+
if not user.distinct_id:
return
posthoganalytics.capture(
@@ -640,6 +650,9 @@ def report_organization_deleted(user: User, organization: Organization):
def report_organization_deletion_initiated(user: User, organization: Organization):
+ if _is_hosted_dev_deployment():
+ return
+
if not user.distinct_id:
return
posthoganalytics.capture(
@@ -654,6 +667,9 @@ def report_organization_deletion_completed(user_id: int, organization_id: str) -
from posthog.models import User as UserModel
from posthog.ph_client import ph_scoped_capture
+ if _is_hosted_dev_deployment():
+ return
+
user = UserModel.objects.filter(id=user_id).first()
if not user or not user.distinct_id:
return
diff --git a/posthog/test/test_event_usage.py b/posthog/test/test_event_usage.py
index 6bb84ca78fcf..28148ca59a69 100644
--- a/posthog/test/test_event_usage.py
+++ b/posthog/test/test_event_usage.py
@@ -15,6 +15,8 @@ from posthog.event_usage import (
get_event_source,
get_mcp_properties,
is_wizard_self_driving_program,
+ report_organization_deleted,
+ report_organization_deletion_initiated,
report_user_action,
report_user_signed_up,
sanitize_header_value,
@@ -583,3 +585,35 @@ class TestSanitizeHeaderValue(BaseTest):
)
def test_sanitize_header_value(self, _name, input_value, expected):
assert sanitize_header_value(input_value) == expected
+
+
+class TestHostedDevDeploymentReporting(BaseTest):
+ @parameterized.expand(
+ [
+ (
+ "user signed up",
+ lambda self: report_user_signed_up(
+ self.user, is_instance_first_user=False, is_organization_first_user=True
+ ),
+ ),
+ (
+ "organization deleted",
+ lambda self: report_organization_deleted(self.user, self.organization),
+ ),
+ (
+ "organization deletion initiated",
+ lambda self: report_organization_deletion_initiated(self.user, self.organization),
+ ),
+ ]
+ )
+ @patch("posthog.event_usage.posthoganalytics.capture")
+ def test_lifecycle_events_are_skipped_on_the_hosted_dev_deployment(self, event, report, mock_capture):
+ with self.settings(CLOUD_DEPLOYMENT="US"):
+ report(self)
+ assert [call.kwargs["event"] for call in mock_capture.call_args_list] == [event]
+
+ mock_capture.reset_mock()
+
+ with self.settings(CLOUD_DEPLOYMENT="DEV"):
+ report(self)
+ mock_capture.assert_not_called()