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.

chore(marketing-analytics): cover the touchpoint gate's negative cases in demo data (#86905)

Javier Bahamondes99b99b6dff4b
diff --git a/products/marketing_analytics/backend/demo/events.py b/products/marketing_analytics/backend/demo/events.py
index ac79cff1b4ed..a3053aec3353 100644
--- a/products/marketing_analytics/backend/demo/events.py
+++ b/products/marketing_analytics/backend/demo/events.py
@@ -110,6 +110,8 @@ class MarketingEventGenerator:
properties["utm_medium"] = channel.utm_medium
if channel.utm_campaign:
properties["utm_campaign"] = channel.utm_campaign
+ if channel.click_id_property:
+ properties[channel.click_id_property] = uuid.uuid5(PERSON_NAMESPACE, f"click-{distinct_id}").hex
properties.update(channel.extra_properties)
session_id = self._pageview(distinct_id, person_uuid, ts, properties)
self._maybe_convert(
diff --git a/products/marketing_analytics/backend/demo/test_world.py b/products/marketing_analytics/backend/demo/test_world.py
index 72b9f78bcb14..a73e92b76937 100644
--- a/products/marketing_analytics/backend/demo/test_world.py
+++ b/products/marketing_analytics/backend/demo/test_world.py
@@ -52,3 +52,22 @@ class TestDemoWorldPaidSignals(SimpleTestCase):
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"
+
+ def test_a_paid_click_id_exists_without_any_utm(self):
+ # gad_source above still rides alongside a utm_source, so it never exercises the
+ # click-id branch on its own.
+ assert [c for c in FREE_CHANNELS if c.click_id_property == "gclid" and not c.utm_source], (
+ "nothing covers a paid click whose only evidence is the click id"
+ )
+
+ def test_fbclid_exists_without_any_other_paid_signal(self):
+ assert [
+ c for c in FREE_CHANNELS if c.click_id_property == "fbclid" and not c.utm_source and not c.extra_properties
+ ], "nothing covers fbclid as the sole identifier, so excluding it proves nothing"
+
+ def test_a_campaign_exists_with_nothing_naming_its_source(self):
+ assert [
+ c
+ for c in FREE_CHANNELS
+ if c.utm_campaign and not c.utm_source and not c.click_id_property and not c.extra_properties
+ ], "nothing covers a campaign-only pageview, so the source requirement is untested"
diff --git a/products/marketing_analytics/backend/demo/world.py b/products/marketing_analytics/backend/demo/world.py
index 3fd140fff3ee..0d29b14cc18c 100644
--- a/products/marketing_analytics/backend/demo/world.py
+++ b/products/marketing_analytics/backend/demo/world.py
@@ -57,6 +57,9 @@ class DemoFreeChannel:
signup_rate: float = 0.03
purchase_rate: float = 0.008
utm_source_variants: dict[str, float] = field(default_factory=dict)
+ # Same unprefixed name the SDK writes, as on DemoCampaign. Emitted per person, so a
+ # channel can carry a click id without carrying any UTM at all.
+ click_id_property: str | None = None
extra_properties: dict[str, str] = field(default_factory=dict)
scenario: str = ""
@@ -677,6 +680,36 @@ FREE_CHANNELS: tuple[DemoFreeChannel, ...] = (
extra_properties={"gad_source": "1"},
scenario="Paid traffic carrying gad_source and no utm_medium",
),
+ # The three gate cases below carry no utm_source, so each one isolates a single
+ # branch of the touchpoint rule. Without them the rule's negative half is
+ # untestable against demo data: every tagged pageview names a source.
+ DemoFreeChannel(
+ key="google_clickid_only",
+ daily_sessions=11,
+ referring_domain="google.com",
+ click_id_property="gclid",
+ signup_rate=0.06,
+ purchase_rate=0.014,
+ scenario="Paid click with the UTMs stripped: a gclid is the only evidence",
+ ),
+ DemoFreeChannel(
+ key="meta_fbclid_only",
+ daily_sessions=16,
+ referring_domain="facebook.com",
+ click_id_property="fbclid",
+ signup_rate=0.03,
+ purchase_rate=0.006,
+ scenario="fbclid rides on organic Facebook links too, so it must not qualify alone",
+ ),
+ DemoFreeChannel(
+ key="campaign_only_orphan",
+ daily_sessions=9,
+ referring_domain="",
+ utm_campaign="orphan_campaign",
+ signup_rate=0.03,
+ purchase_rate=0.006,
+ scenario="utm_campaign with nothing naming the source: stays excluded",
+ ),
)
# Sources with cost rows written to the warehouse (must stay in sync with health.py).