: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-analytics): emit click ids under the name production uses in demo data (#83302)
Javier Bahamondes0fd5a4793962
diff --git a/products/marketing_analytics/backend/demo/config.py b/products/marketing_analytics/backend/demo/config.pyindex 1fcd4c135bb8..87e3b4a04b1b 100644--- a/products/marketing_analytics/backend/demo/config.py+++ b/products/marketing_analytics/backend/demo/config.py@@ -90,6 +90,20 @@ def build_conversion_goals(team: Team) -> list[dict]:"distinct_id_field": "distinct_id",},},+ # Sums money and is flagged as neither, so ROAS and cost per customer stay+ # blocked with a goal sitting right there that would unblock them. Drives+ # mark_goal_as_revenue / mark_goal_as_customer, and gives the settings+ # checkboxes something to turn on.+ {+ "kind": "EventsNode",+ "event": EVENT_PURCHASE,+ "conversion_goal_id": "cg_unflagged_revenue",+ "name": EVENT_PURCHASE,+ "conversion_goal_name": "Checkout value (unflagged)",+ "math": "sum",+ "math_property": "revenue",+ "schema_map": _DEFAULT_SCHEMA_MAP,+ },# Deliberately broken goals: exercise is_misconfigured in the inspector# and the dashboard's validation warnings.{diff --git a/products/marketing_analytics/backend/demo/events.py b/products/marketing_analytics/backend/demo/events.pyindex ebf5c7a0a3f5..ac79cff1b4ed 100644--- a/products/marketing_analytics/backend/demo/events.py+++ b/products/marketing_analytics/backend/demo/events.py@@ -110,6 +110,7 @@ class MarketingEventGenerator:properties["utm_medium"] = channel.utm_mediumif channel.utm_campaign:properties["utm_campaign"] = channel.utm_campaign+ properties.update(channel.extra_properties)session_id = self._pageview(distinct_id, person_uuid, ts, properties)self._maybe_convert(distinct_id,diff --git a/products/marketing_analytics/backend/demo/health.py b/products/marketing_analytics/backend/demo/health.pyindex 838efcc78c88..9f7fc5017a43 100644--- a/products/marketing_analytics/backend/demo/health.py+++ b/products/marketing_analytics/backend/demo/health.py@@ -2,8 +2,10 @@Source health is computed purely from ExternalDataSource / ExternalDataSchema /ExternalDataJob rows, so each platform below is staged into a different-`last_sync_status`. TikTok is deliberately not created: its traffic makes the-diagnose service report `events_only`.+`last_sync_status`.++Every native platform gets a source here, so no platform lands in `events_only`+and `connect_source` is the one suggestion kind this fixture never produces."""import datetime as dtdiff --git a/products/marketing_analytics/backend/demo/test_config.py b/products/marketing_analytics/backend/demo/test_config.pynew file mode 100644index 000000000000..fa67f40d35e4--- /dev/null+++ b/products/marketing_analytics/backend/demo/test_config.py@@ -0,0 +1,31 @@+from posthog.test.base import BaseTest++from products.marketing_analytics.backend.demo.config import build_conversion_goals++SUM_MATHS = {"sum"}+++class TestDemoConversionGoals(BaseTest):+ def test_every_revenue_goal_actually_sums_an_amount(self):+ # `counts_as_revenue` without sum math feeds ROAS a conversion count, and the+ # write path rejects it — demo config must not seed a state the API refuses.+ for goal in build_conversion_goals(self.team):+ if goal.get("counts_as_revenue"):+ assert goal.get("math") in SUM_MATHS, goal["conversion_goal_id"]+ assert goal.get("math_property"), goal["conversion_goal_id"]++ def test_a_revenue_shaped_goal_is_left_unflagged(self):+ unflagged = [+ g+ for g in build_conversion_goals(self.team)+ if g.get("math") in SUM_MATHS+ and g.get("math_property")+ and not g.get("counts_as_revenue")+ and not g.get("counts_as_customer")+ ]+ assert unflagged, "nothing drives mark_goal_as_revenue / mark_goal_as_customer"++ def test_both_flags_are_represented(self):+ goals = build_conversion_goals(self.team)+ assert any(g.get("counts_as_revenue") for g in goals)+ assert any(g.get("counts_as_customer") for g in goals)diff --git a/products/marketing_analytics/backend/demo/test_world.py b/products/marketing_analytics/backend/demo/test_world.pynew file mode 100644index 000000000000..72b9f78bcb14--- /dev/null+++ b/products/marketing_analytics/backend/demo/test_world.py@@ -0,0 +1,54 @@+from django.test import SimpleTestCase++from products.marketing_analytics.backend.demo.world import CAMPAIGNS, FREE_CHANNELS+from products.marketing_analytics.backend.services.native_integrations import lookup_alias++PAID_MEDIUMS = {"cpc", "cpm", "cpv", "cpa", "ppc", "retargeting"}+++def _is_paid_medium(medium: str | None) -> bool:+ if not medium:+ return False+ return medium in PAID_MEDIUMS or medium.startswith("paid")+++class TestDemoWorldPaidSignals(SimpleTestCase):+ """The paid/organic split the `connect_source` gate reads.++ Both sides have to exist here or the gate is untestable against demo data: it+ suppresses only on positive evidence (mediums tagged, none of them paid).+ """++ def test_some_organic_traffic_carries_an_ad_platform_source_name(self):+ organic_on_ad_alias = [+ c+ for c in FREE_CHANNELS+ if c.utm_source+ and lookup_alias(c.utm_source)+ and c.utm_medium+ and not _is_paid_medium(c.utm_medium)+ and not c.extra_properties+ ]+ assert organic_on_ad_alias, (+ "no free channel looks like an unconnected ad account on utm_source alone, "+ "so nothing exercises suppressing connect_source"+ )++ def test_paid_traffic_is_recognisable_by_medium_or_click_id(self):+ for campaign in CAMPAIGNS:+ if campaign.daily_sessions == 0: # not_linked: spend with no tagged events+ continue+ assert _is_paid_medium(campaign.utm_medium) or campaign.click_id_property, (+ f"{campaign.name} spends money but carries no paid signal"+ )++ def test_click_ids_use_the_property_name_the_sdk_writes(self):+ # `$gclid` is the person-scoped copy; the event carries the unprefixed one, and+ # that is what every paid-detection query reads.+ for campaign in CAMPAIGNS:+ if campaign.click_id_property:+ assert not campaign.click_id_property.startswith("$"), campaign.name++ def test_a_paid_click_id_exists_without_any_medium(self):+ autotagged = [c for c in FREE_CHANNELS if c.extra_properties.get("gad_source") and not c.utm_medium]+ assert autotagged, "nothing covers paid traffic detectable only by gad_source"diff --git a/products/marketing_analytics/backend/demo/world.py b/products/marketing_analytics/backend/demo/world.pyindex 98cb60ed82c4..82f9cff4234b 100644--- a/products/marketing_analytics/backend/demo/world.py+++ b/products/marketing_analytics/backend/demo/world.py@@ -33,7 +33,9 @@ class DemoCampaign:utm_campaign: str | None # value events carry; None => use name.lower()utm_medium: str = "cpc"referring_domain: str = ""- click_id_property: str | None = None # $gclid / $fbclid+ # Unprefixed, matching what the SDK writes on the event. `$initial_gclid` is the+ # person-scoped copy channel_type reads, and is derived from this one.+ click_id_property: str | None = None # gclid / fbclidsignup_rate: float = 0.0purchase_rate: float = 0.0reported_conversion_rate: float = 0.02 # of clicks@@ -55,6 +57,7 @@ class DemoFreeChannel:signup_rate: float = 0.03purchase_rate: float = 0.008utm_source_variants: dict[str, float] = field(default_factory=dict)+ extra_properties: dict[str, str] = field(default_factory=dict)scenario: str = ""@@ -86,7 +89,7 @@ CAMPAIGNS: tuple[DemoCampaign, ...] = (utm_source="google",utm_campaign="brand_search",referring_domain="google.com",- click_id_property="$gclid",+ click_id_property="gclid",signup_rate=0.12,purchase_rate=0.035,reported_conversion_rate=0.05,@@ -108,7 +111,7 @@ CAMPAIGNS: tuple[DemoCampaign, ...] = (utm_source="google",utm_campaign="generic_search",referring_domain="google.com",- click_id_property="$gclid",+ click_id_property="gclid",signup_rate=0.015,purchase_rate=0.002,reported_conversion_rate=0.01,@@ -141,7 +144,7 @@ CAMPAIGNS: tuple[DemoCampaign, ...] = (utm_source="google",utm_campaign="spring_sale_2026",referring_domain="google.com",- click_id_property="$gclid",+ click_id_property="gclid",signup_rate=0.08,purchase_rate=0.02,utm_campaign_variants={"spring-sale-2026": 0.4},@@ -249,7 +252,7 @@ CAMPAIGNS: tuple[DemoCampaign, ...] = (utm_campaign="prospecting_feed",utm_medium="paid-social",referring_domain="facebook.com",- click_id_property="$fbclid",+ click_id_property="fbclid",signup_rate=0.05,purchase_rate=0.012,# The UTM audit only exact-matches the primary source (default aliases@@ -629,6 +632,54 @@ FREE_CHANNELS: tuple[DemoFreeChannel, ...] = (purchase_rate=0.025,scenario="AI channel reached via utm_source=chatgpt (not just referrer)",),+ # --- Organic traffic tagged with an ad platform's own name ---+ # The canonical alias table maps these utm_source values to an ad platform, so on+ # utm_source alone every one of them looks like an ad account the team forgot to+ # connect. The medium is what says otherwise. Shapes taken from real project data.+ DemoFreeChannel(+ key="linkedin_organic",+ daily_sessions=18,+ referring_domain="linkedin.com",+ utm_source="linkedin",+ utm_medium="social",+ utm_campaign="company_page_post",+ signup_rate=0.04,+ purchase_rate=0.007,+ scenario="Organic company posts under utm_source=linkedin: connect_source must stay silent",+ ),+ DemoFreeChannel(+ key="meta_page_organic",+ daily_sessions=14,+ referring_domain="facebook.com",+ utm_source="facebook",+ utm_medium="page_organic",+ signup_rate=0.03,+ purchase_rate=0.005,+ scenario="Organic page posts under an alias of Meta Ads",+ ),+ DemoFreeChannel(+ key="youtube_kol",+ daily_sessions=10,+ referring_domain="youtube.com",+ utm_source="youtube",+ utm_medium="kol",+ utm_campaign="creator_collab",+ signup_rate=0.05,+ purchase_rate=0.009,+ scenario="Influencer traffic under an alias of Google Ads, with a medium nobody classifies as paid",+ ),+ # gad_source without any utm_medium: auto-tagged Google Ads traffic is paid on the+ # click id alone, so a medium-only rule would read this as organic.+ DemoFreeChannel(+ key="google_autotagged",+ daily_sessions=12,+ referring_domain="google.com",+ utm_source="google",+ signup_rate=0.06,+ purchase_rate=0.015,+ extra_properties={"gad_source": "1"},+ scenario="Paid traffic carrying gad_source and no utm_medium",+ ),)# Sources with cost rows written to the warehouse (must stay in sync with health.py).