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(test): drop redundant attribution validation-example tests (#66379)

Georges-Antoine Assi4968004a070d
diff --git a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
index 683eba5280d0..e3a704459051 100644
--- a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
+++ b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py
@@ -1698,205 +1698,6 @@ class TestConversionGoalProcessor(ClickhouseTestMixin, BaseTest):
assert conversion_count == 1, f"Expected 1 conversion, got {conversion_count}"
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot
- def test_temporal_attribution_forward_order_validation_example(self):
- """
- EXAMPLE: How to validate attribution results properly
-
- This test shows the pattern for validating attribution results.
- """
- # Setup: Create ad touchpoint before conversion
- with freeze_time("2023-04-15"):
- _create_person(distinct_ids=["validation_user"], team=self.team)
- _create_event(
- distinct_id="validation_user",
- event="$pageview",
- team=self.team,
- properties={"utm_campaign": "spring_sale", "utm_source": "google"},
- )
- flush_persons_and_events_in_batches()
-
- with freeze_time("2023-05-10"):
- _create_event(distinct_id="validation_user", event="purchase", team=self.team, properties={"revenue": 100})
- flush_persons_and_events_in_batches()
-
- # Create processor and execute query
- goal = ConversionGoalFilter1(
- kind="EventsNode",
- event="purchase",
- conversion_goal_id="validation_test",
- conversion_goal_name="Validation Test",
- math=BaseMathType.TOTAL,
- schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
- )
-
- processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=self.config)
-
- additional_conditions = [
- ast.CompareOperation(
- left=ast.Field(chain=["events", "timestamp"]),
- op=ast.CompareOperationOp.GtEq,
- right=ast.Call(name="toDate", args=[ast.Constant(value="2023-05-01")]),
- ),
- ]
-
- cte_query = processor.generate_cte_query(additional_conditions)
- response = execute_hogql_query(query=cte_query, team=self.team)
-
- # 1. Basic response validation
- assert response is not None
- assert response.results is not None
- assert len(response.results) == 1, f"Expected 1 result, got {len(response.results)}"
-
- # 2. Expected result structure validation
- # The query returns: [campaign_name, source_name, conversion_count]
- first_result = response.results[0]
-
- # Validate attribution values (correct indices based on actual query structure)
- expected_campaign = "spring_sale"
- expected_source = "google"
- expected_conversion_count = 1
-
- # Schema: [0]=match_key, [1]=campaign, [2]=id, [3]=source, [4]=conversion
- assert first_result[1] == expected_campaign, f"Expected campaign '{expected_campaign}', got '{first_result[1]}'"
- assert first_result[3] == expected_source, f"Expected source '{expected_source}', got '{first_result[3]}'"
- assert first_result[4] == expected_conversion_count, (
- f"Expected {expected_conversion_count} conversion, got {first_result[4]}"
- )
-
- def test_temporal_attribution_backward_order_validation_example(self):
- """
- Test that wrong temporal order produces Unknown attribution.
-
- Scenario: Conversion occurs before ad touchpoint
- Expected: Should show Unknown attribution since ad came after conversion
- """
- # Setup: Create conversion before ad touchpoint (wrong order)
- with freeze_time("2023-04-15"):
- _create_person(distinct_ids=["backward_validation_user"], team=self.team)
- _create_event(
- distinct_id="backward_validation_user",
- event="purchase",
- team=self.team,
- properties={"revenue": 100}, # Conversion first
- )
- flush_persons_and_events_in_batches()
-
- with freeze_time("2023-05-10"):
- _create_event(
- distinct_id="backward_validation_user",
- event="$pageview",
- team=self.team,
- properties={"utm_campaign": "too_late", "utm_source": "google"}, # Ad after conversion
- )
- flush_persons_and_events_in_batches()
-
- goal = ConversionGoalFilter1(
- kind="EventsNode",
- event="purchase",
- conversion_goal_id="backward_validation",
- conversion_goal_name="Backward Validation",
- math=BaseMathType.TOTAL,
- schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
- )
-
- processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=self.config)
-
- additional_conditions = [
- ast.CompareOperation(
- left=ast.Field(chain=["events", "timestamp"]),
- op=ast.CompareOperationOp.GtEq,
- right=ast.Call(name="toDate", args=[ast.Constant(value="2023-04-01")]),
- ),
- ]
-
- cte_query = processor.generate_cte_query(additional_conditions)
- response = execute_hogql_query(query=cte_query, team=self.team)
-
- # Validation: Should show Unknown attribution since ad came after conversion
- assert response is not None
- assert len(response.results) == 1
-
- first_result = response.results[0]
- # Schema: [0]=match_key, [1]=campaign, [2]=id, [3]=source, [4]=conversion
- campaign_name, source_name, conversion_count = first_result[1], first_result[3], first_result[4]
-
- # Assert that attribution is Unknown because ad came after conversion
- assert campaign_name == "organic", f"Expected organic attribution, got {campaign_name}"
- assert source_name == "organic", f"Expected organic source, got {source_name}"
- assert conversion_count == 1, f"Expected 1 conversion, got {conversion_count}"
-
- def test_multiple_touchpoints_attribution_validation_example(self):
- """
- Test multi-touch attribution with last-touch logic.
-
- Timeline: Email touchpoint → Facebook touchpoint → Purchase
- Expected: Should attribute to Facebook (last touchpoint before conversion)
- """
- # Setup: Create email touchpoint first
- with freeze_time("2023-04-01"):
- _create_person(distinct_ids=["multi_user"], team=self.team)
- _create_event(
- distinct_id="multi_user",
- event="$pageview",
- team=self.team,
- properties={"utm_campaign": "newsletter", "utm_source": "email"},
- )
- flush_persons_and_events_in_batches()
-
- # Setup: Create Facebook touchpoint later (last touch)
- with freeze_time("2023-04-15"):
- _create_event(
- distinct_id="multi_user",
- event="$pageview",
- team=self.team,
- properties={"utm_campaign": "spring_promo", "utm_source": "facebook"},
- )
- flush_persons_and_events_in_batches()
-
- # Conversion with no UTM (should use last touchpoint)
- with freeze_time("2023-05-10"):
- _create_event(distinct_id="multi_user", event="purchase", team=self.team, properties={"revenue": 100})
- flush_persons_and_events_in_batches()
-
- # Create processor and execute query
- goal = ConversionGoalFilter1(
- kind="EventsNode",
- event="purchase",
- conversion_goal_id="multi_touch_test",
- conversion_goal_name="Multi Touch Test",
- math=BaseMathType.TOTAL,
- schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},
- )
-
- processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=self.config)
-
- additional_conditions = [
- ast.CompareOperation(
- left=ast.Field(chain=["events", "timestamp"]),
- op=ast.CompareOperationOp.GtEq,
- right=ast.Call(name="toDate", args=[ast.Constant(value="2023-04-01")]),
- ),
- ]
-
- cte_query = processor.generate_cte_query(additional_conditions)
- response = execute_hogql_query(query=cte_query, team=self.team)
-
- # Validate basic response
- assert response is not None
- assert len(response.results) == 1
-
- # Validation: Last-touch attribution should choose Facebook over Email
- # Timeline: newsletter/email (Apr 1) → spring_promo/facebook (Apr 15) → purchase (May 10)
- first_result = response.results[0]
- # Schema: [0]=match_key, [1]=campaign, [2]=id, [3]=source, [4]=conversion
- campaign_name, source_name, conversion_count = first_result[1], first_result[3], first_result[4]
-
- assert campaign_name == "spring_promo", (
- f"Last-touch attribution should choose Facebook campaign over Email, got {campaign_name}"
- )
- assert source_name == "meta", f"Last-touch attribution should choose Meta source over Email, got {source_name}"
- assert conversion_count == 1, f"Expected 1 conversion, got {conversion_count}"
-
@pytest.mark.usefixtures("unittest_snapshot")
def test_direct_utm_attribution_priority_over_temporal(self):
"""