: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(marketing): enable setup for the new dashboard rollout (#98646)
Javier Bahamondesc07f508cc5c9
diff --git a/docs/internal/marketing-analytics-configuration-writes.md b/docs/internal/marketing-analytics-configuration-writes.mdindex b79c6a960c4d..a3244e4210c0 100644--- a/docs/internal/marketing-analytics-configuration-writes.md+++ b/docs/internal/marketing-analytics-configuration-writes.md@@ -6,6 +6,8 @@ Explicit conversion-goal list updates still replace the list; simultaneous editsLoading a project replaces the current and saved Marketing settings with that project’s configuration, including an empty configuration when none exists.+Setup is available when either `marketing-analytics-setup` or `new-marketing-analytics-dashboard` is enabled for the requesting person. Both Setup endpoints use the same rule; existing project permissions still apply.+Setup usage emits `marketing analytics setup section viewed` on entry and section changes.Suggestion review, dismissal, restoration, batch review, capability filters, rescans and navigation have separate events.`marketing analytics setup change submitted`, `change completed` and `change failed` share the same prefix and report operation types, counts, source and whether the change is an undo. Completed reports the server's applied count, which may be zero.diff --git a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsxindex f0c1bf3c7f1d..1435483038e1 100644--- a/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx+++ b/frontend/src/scenes/marketing-analytics/MarketingAnalyticsScene.tsx@@ -246,7 +246,9 @@ const MarketingAnalyticsContent = (): JSX.Element => {// Setup absorbs Integration health: while its flag is on, the audit lives inside// Setup as a section rather than as a second top-level tab, so there's one door to// "something is wrong with my setup" instead of two.- const setupEnabled = !!featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_SETUP]+ const setupEnabled =+ !!featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_SETUP] ||+ !!featureFlags[FEATURE_FLAGS.MARKETING_ANALYTICS_NEW_DASHBOARD]// Setup absorbs the tabs it replaces, so a link or bookmark carrying one still lands// somewhere sensible. Here rather than in the logic because only the scene knowsdiff --git a/products/marketing_analytics/backend/api.py b/products/marketing_analytics/backend/api.pyindex 09ad1c61eaca..b3f89f720142 100644--- a/products/marketing_analytics/backend/api.py+++ b/products/marketing_analytics/backend/api.py@@ -92,14 +92,17 @@ def _setup_enabled(request: Request, team: Team) -> bool:email = getattr(request.user, "email", None)if email:person_properties["email"] = email- enabled = feature_enabled_or_false(- "marketing-analytics-setup",- # Service credentials authenticate as a synthetic user with no person behind them;- # the team UUID keeps the call well-formed, and a person condition won't match it.- getattr(request.user, "distinct_id", None) or str(team.uuid),- groups={"organization": str(team.organization.id)},- person_properties=person_properties,- group_properties={"organization": {"id": str(team.organization.id)}},+ enabled = any(+ feature_enabled_or_false(+ flag,+ # Service credentials authenticate as a synthetic user with no person behind them;+ # the team UUID keeps the call well-formed, and a person condition won't match it.+ getattr(request.user, "distinct_id", None) or str(team.uuid),+ groups={"organization": str(team.organization.id)},+ person_properties=person_properties,+ group_properties={"organization": {"id": str(team.organization.id)}},+ )+ for flag in ("marketing-analytics-setup", "new-marketing-analytics-dashboard"))request._ma_setup_flag = enabled # type: ignore[attr-defined]return enabled@@ -1470,7 +1473,7 @@ class MarketingAnalyticsViewSet(TeamAndOrgViewSetMixin, GenericViewSet):response=SetupPlanResponseSerializer,description="Ranked, machine-applicable setup suggestions plus per-capability readiness",),- 404: OpenApiResponse(description="The marketing-analytics-setup feature flag is off for this team"),+ 404: OpenApiResponse(description="Marketing Setup and new dashboard feature flags are both off"),},summary="Get the marketing analytics setup plan",description=(@@ -1527,7 +1530,7 @@ class MarketingAnalyticsViewSet(TeamAndOrgViewSetMixin, GenericViewSet):description="The applied operations and the ops that reverse them",),400: OpenApiResponse(description="An operation was malformed, unsupported, or not applicable"),- 404: OpenApiResponse(description="The marketing-analytics-setup feature flag is off for this team"),+ 404: OpenApiResponse(description="Marketing Setup and new dashboard feature flags are both off"),},summary="Apply setup operations",description=(diff --git a/products/marketing_analytics/backend/test_api_apply_setup_ops.py b/products/marketing_analytics/backend/test_api_apply_setup_ops.pyindex 56d3e4141ce8..80780cb5c89b 100644--- a/products/marketing_analytics/backend/test_api_apply_setup_ops.py+++ b/products/marketing_analytics/backend/test_api_apply_setup_ops.py@@ -3,6 +3,8 @@ from unittest.mock import patchfrom django.core.cache import cache+from parameterized import parameterized+from posthog.constants import AvailableFeaturefrom posthog.models.organization import OrganizationMembershipfrom posthog.models.team.team_marketing_analytics_config import TeamMarketingAnalyticsConfig@@ -413,19 +415,22 @@ class TestApplySetupOpsFeatureFlag(APIBaseTest):self.url = f"/api/projects/{self.team.pk}/marketing_analytics/apply_setup_ops"cache.clear()- def test_the_endpoint_is_absent_when_the_flag_is_off(self):- # The ops only ever come from a plan, so an unreleased read side means there is- # nothing legitimate to apply — and a write that lands anyway would be a config- # change from a surface the user cannot see.- with patch(_FLAG_TARGET, return_value=False):+ @parameterized.expand([(False, False), (False, True), (True, False), (True, True)])+ def test_setup_availability(self, setup: bool, dashboard: bool) -> None:+ self.organization_membership.level = OrganizationMembership.Level.ADMIN+ self.organization_membership.save()+ flags = {"marketing-analytics-setup": setup, "new-marketing-analytics-dashboard": dashboard}+ with patch(_FLAG_TARGET, side_effect=lambda flag, *args, **kwargs: flags[flag]):response = self.client.post(self.url,{"ops": [{"op": "add_custom_source_mapping", "integration": "MetaAds", "raw_utm_source": "fb-ads"}]},format="json",)- assert response.status_code == 404- assert TeamMarketingAnalyticsConfig.objects.get(team=self.team).custom_source_mappings == {}+ assert response.status_code == (200 if setup or dashboard else 404)+ assert TeamMarketingAnalyticsConfig.objects.get(team=self.team).custom_source_mappings == (+ {"MetaAds": ["fb-ads"]} if setup or dashboard else {}+ )class TestApplySetupOpsRequiresProjectAdmin(APIBaseTest):diff --git a/products/marketing_analytics/backend/test_api_setup_plan.py b/products/marketing_analytics/backend/test_api_setup_plan.pyindex be26687cd49d..d1a9bfe7d5ff 100644--- a/products/marketing_analytics/backend/test_api_setup_plan.py+++ b/products/marketing_analytics/backend/test_api_setup_plan.py@@ -3,6 +3,8 @@ from unittest.mock import patchfrom django.core.cache import cache+from parameterized import parameterized+from posthog.models.organization import Organization, OrganizationMembershipfrom posthog.models.team.team import Teamfrom posthog.models.user import User@@ -149,13 +151,17 @@ class TestSetupPlanFeatureFlag(APIBaseTest):self.url = f"/api/projects/{self.team.pk}/marketing_analytics/setup_plan"cache.clear()- def test_the_endpoint_is_absent_when_the_flag_is_off(self):- with patch(_FLAG_TARGET, return_value=False), patch(_PLAN_TARGET, return_value=_plan()) as build:+ @parameterized.expand([(False, False), (False, True), (True, False), (True, True)])+ def test_setup_availability(self, setup: bool, dashboard: bool) -> None:+ flags = {"marketing-analytics-setup": setup, "new-marketing-analytics-dashboard": dashboard}+ with (+ patch(_FLAG_TARGET, side_effect=lambda flag, *args, **kwargs: flags[flag]),+ patch(_PLAN_TARGET, return_value=_plan()) as build,+ ):response = self.client.get(self.url)- assert response.status_code == 404- # 404 rather than 403 so an unreleased endpoint looks absent, not forbidden.- assert build.call_count == 0+ assert response.status_code == (200 if setup or dashboard else 404)+ assert build.call_count == int(setup or dashboard)def test_the_flag_is_evaluated_once_per_request(self):# A second call in the same request would fire a redundant `$feature_flag_called`.