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(marketing): show paid event counts in source suggestions (#109194)

Javier Bahamondese26ce1cc0d7f
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.md
new file mode 100644
index 000000000000..8d750deda5b1
--- /dev/null
+++ b/docs/internal/marketing-source-suggestions.md
@@ -0,0 +1,12 @@
+# Marketing source suggestions
+
+Marketing analytics suggests connecting an ad platform when a matching UTM source has events with paid attribution signals.
+Connection suggestions display the number of these events over the last seven days and rank platforms by that count.
+Events without paid signals and fuzzy-only source matches do not increase the count.
+Each event counts at most once for its matched platform, even if it carries multiple paid signals.
+
+The count includes all matching event types, so it does not represent unique visitors or ad clicks.
+For example, a source with 700 matching events, including 17 with paid signals, shows 17 events in its connection suggestion.
+It ranks below a source with 25 paid events, regardless of that source's total traffic.
+
+These counts guide connection suggestions; they do not change report attribution or connected-source sync checks.
diff --git a/products/marketing_analytics/backend/services/setup_plan.py b/products/marketing_analytics/backend/services/setup_plan.py
index e20a07fa46f3..925cde544200 100644
--- a/products/marketing_analytics/backend/services/setup_plan.py
+++ b/products/marketing_analytics/backend/services/setup_plan.py
@@ -282,16 +282,13 @@ def _integration_suggestion(integration: IntegrationDiagnostic) -> Suggestion |
source_type = integration.source_type
ds = integration.data_source
attribution = integration.attribution
- # Exact and fuzzy source matches do not overlap, so both contribute to the source volume.
- volume = (
- attribution.events_matched_last_7d + attribution.events_unmatched_likely_yours_last_7d if attribution else 0
- )
-
if status == "events_only":
# Organic and referral links can carry both utm_source and utm_campaign.
if attribution is None or attribution.events_matched_paid_last_7d == 0:
return None
+ paid_volume = attribution.events_matched_paid_last_7d
+ event_label = "event" if paid_volume == 1 else "events"
# Traffic arrives but no spend data, so cost, ROAS and CAC are all unavailable.
return Suggestion(
id=f"connect_source:{key}",
@@ -300,13 +297,13 @@ def _integration_suggestion(integration: IntegrationDiagnostic) -> Suggestion |
confidence=0.95,
title=f"Connect {display}",
evidence=(
- f"{volume:,} events in the last 7 days carry a {display} utm_source, "
- "including traffic with paid attribution. Connect the platform to add spend data."
+ f"Detected {paid_volume:,} {event_label} with paid attribution signals for {display} "
+ "in the last 7 days. Connect the platform to add spend data."
),
unlocks=[Capability.COST, Capability.ROAS, Capability.CAC],
apply=OpenSourceWizard(kind=source_type),
integration=source_type,
- event_volume=volume,
+ event_volume=paid_volume,
)
if status == "sync_broken":
diff --git a/products/marketing_analytics/backend/services/test_setup_plan.py b/products/marketing_analytics/backend/services/test_setup_plan.py
index 5593714fd6f1..fb9114aa9ecd 100644
--- a/products/marketing_analytics/backend/services/test_setup_plan.py
+++ b/products/marketing_analytics/backend/services/test_setup_plan.py
@@ -314,6 +314,22 @@ class TestInvariants(SetupPlanTestCase):
class TestRanking(SetupPlanTestCase):
+ @pytest.mark.asyncio
+ async def test_connect_suggestions_rank_by_paid_event_volume(self) -> None:
+ self.diagnostic = MarketingDiagnosticResponse(
+ integrations=[
+ _integration("google_ads", "GoogleAds", status="events_only", matched=700, unmatched=500, paid=1),
+ _integration("meta_ads", "MetaAds", status="events_only", matched=100, paid=17),
+ ],
+ overall_status="degraded",
+ conversion_goals=ConversionGoalsListResponse(goals=[_goal()]),
+ )
+
+ plan = await get_setup_plan(self.team)
+
+ connects = [s for s in plan.suggestions if s.kind == SuggestionKind.CONNECT_SOURCE]
+ assert [s.id for s in connects] == ["connect_source:meta_ads", "connect_source:google_ads"]
+
@pytest.mark.asyncio
async def test_unblocking_action_outranks_a_higher_volume_one(self):
# Connecting the platform unblocks the goal-flag work, so it must come first
@@ -645,17 +661,24 @@ class TestIntegrationSuggestions(SetupPlanTestCase):
@parameterized.expand(
[
("exact_utm_source_match_only", 0, 700, 700),
- ("both_kinds_of_match", 500, 700, 1200),
+ ("mixed_paid_and_organic", 500, 700, 17),
+ ("single_paid_event", 500, 700, 1),
+ ("formatted_paid_count", 800, 1600, 1250),
]
)
@pytest.mark.asyncio
- async def test_connect_suggestion_counts_every_event_carrying_the_utm_source(
- self, _name, unmatched, matched, expected
- ):
+ async def test_connect_suggestion_counts_only_events_with_paid_evidence(
+ self, _name: str, unmatched: int, matched: int, paid: int
+ ) -> None:
self.diagnostic = MarketingDiagnosticResponse(
integrations=[
_integration(
- "pinterest_ads", "PinterestAds", status="events_only", unmatched=unmatched, matched=matched, paid=1
+ "pinterest_ads",
+ "PinterestAds",
+ status="events_only",
+ unmatched=unmatched,
+ matched=matched,
+ paid=paid,
)
],
overall_status="degraded",
@@ -665,8 +688,12 @@ class TestIntegrationSuggestions(SetupPlanTestCase):
plan = await get_setup_plan(self.team)
connect = next(s for s in plan.suggestions if s.kind == SuggestionKind.CONNECT_SOURCE)
- assert connect.event_volume == expected
- assert f"{expected:,} events" in connect.evidence
+ assert connect.event_volume == paid
+ event_label = "event" if paid == 1 else "events"
+ assert connect.evidence == (
+ f"Detected {paid:,} {event_label} with paid attribution signals for Pinterest Ads in the last 7 days. "
+ "Connect the platform to add spend data."
+ )
@pytest.mark.asyncio
async def test_healthy_integration_produces_nothing(self):