Skip to content

Session-based funnel conversion examples (UTM source/medium)#8

Open
lordhumunguz wants to merge 1 commit intomasterfrom
fix/session-based-funnel-utm
Open

Session-based funnel conversion examples (UTM source/medium)#8
lordhumunguz wants to merge 1 commit intomasterfrom
fix/session-based-funnel-utm

Conversation

@lordhumunguz
Copy link
Contributor

@lordhumunguz lordhumunguz commented Jan 30, 2026

Fixes misleading event-based funnel conversion examples in SQL Query Library.

  • Replaces funnel conversion by UTM source/medium and daily funnel conversion examples with session-based patterns using the table sm_transformed_v2.obt_funnel_event_history (distinct-session denominators).
  • Updates the rpt_funnel_events_performance_hourly table doc to clearly state it is event-aggregated and ratios are directional, not true conversion.

Goal: Mintlify retrieval should stop suggesting event-count ratios as “conversion rate”.

Summary by CodeRabbit

  • Documentation
    • Clarified that funnel event volumes are event-aggregated and directional, not session-based conversion rates.
    • Updated SQL query templates to use session-based funnel analysis instead of event-based metrics.
    • Added guidance on selecting the appropriate analysis method and tables for funnel conversion calculations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

The pull request updates data activation documentation and SQL templates to clarify analytical approaches. One model description is enhanced to emphasize event-level aggregation and event-based metrics, while SQL query templates are comprehensively revised to shift from event-based to session-based funnel calculations, including metrics for daily funnels, top pages, and UTM source analysis.

Changes

Cohort / File(s) Summary
Model Documentation Clarification
data-activation/data-tables/sm_transformed_v2/rpt_funnel_events_performance_hourly.mdx
Model description updated to clarify event-level aggregation and event-based metrics rather than session-conversion rates. Warning and tip guidance blocks added to explain that ratios may exceed 1 due to multiple events per session, with recommendations to use session-based tables for true conversion analysis.
SQL Template Library Migration
data-activation/template-resources/sql-query-library.mdx
Multiple SQL query templates and accordion sections updated to shift from event-based to session-based funnel definitions across Daily funnel, Top pages by add-to-cart, and Funnel by source/medium analyses. Queries now derive per-session metrics (session participation indicators, session conversion rates) with updated explanatory Info blocks and COALESCE/NULL handling for session-oriented denominators.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 From events we hop to sessions clear,
Our metrics now hold meanings dear,
Where funnels flow through one-per-soul,
And ratios stay beneath the whole,
A clarity in every row! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Session-based funnel conversion examples (UTM source/medium)' accurately reflects the main changes: replacing event-based funnel examples with session-based patterns in the SQL Query Library and updating funnel-by-UTM documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/session-based-funnel-utm

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
data-activation/template-resources/sql-query-library.mdx (1)

1464-1477: ⚠️ Potential issue | 🟡 Minor

Rename alias fo to satisfy codespell

CI is failing on Line 1466 due to the fo alias. Rename the alias to avoid the codespell false positive.

🔧 Proposed fix
-    FROM first_valid_orders fo
+    FROM first_valid_orders first_orders
     LEFT JOIN `your_project.sm_transformed_v2.obt_orders` o
-      ON o.sm_customer_key = fo.sm_customer_key
+      ON o.sm_customer_key = first_orders.sm_customer_key
       AND o.is_order_sm_valid = TRUE
       AND o.order_cancelled_at IS NULL
       AND o.order_net_revenue > 0
-      AND o.order_processed_at_local_datetime > fo.first_order_at_local_datetime
-      AND o.order_processed_at_local_datetime < DATETIME_ADD(fo.first_order_at_local_datetime, INTERVAL 90 DAY)
+      AND o.order_processed_at_local_datetime > first_orders.first_order_at_local_datetime
+      AND o.order_processed_at_local_datetime < DATETIME_ADD(first_orders.first_order_at_local_datetime, INTERVAL 90 DAY)
     GROUP BY 1, 2
🤖 Fix all issues with AI agents
In `@data-activation/template-resources/sql-query-library.mdx`:
- Around line 363-374: The query in the session_daily aggregation selects date
plus aggregate expressions (aliases sessions, sessions_with_view_item,
view_to_cart_rate, etc.) but lacks a GROUP BY, causing BigQuery to fail; update
the SQL in the session_daily query block to add a GROUP BY date (grouping by the
selected date column) before the ORDER BY date so the aggregates are computed
per date.

Comment on lines 363 to 374
date,
view_item_events,
add_to_cart_events,
begin_checkout_events,
purchase_events,
event_order_revenue,
SAFE_DIVIDE(add_to_cart_events, NULLIF(view_item_events, 0)) AS add_to_cart_per_view_item,
SAFE_DIVIDE(begin_checkout_events, NULLIF(add_to_cart_events, 0)) AS begin_checkout_per_add_to_cart,
SAFE_DIVIDE(purchase_events, NULLIF(begin_checkout_events, 0)) AS purchase_per_begin_checkout,
SAFE_DIVIDE(purchase_events, NULLIF(view_item_events, 0)) AS purchase_per_view_item
FROM daily
COUNT(*) AS sessions,
SUM(has_view_item) AS sessions_with_view_item,
SUM(has_add_to_cart) AS sessions_with_add_to_cart,
SUM(has_begin_checkout) AS sessions_with_begin_checkout,
SUM(has_purchase) AS sessions_with_purchase,
SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate,
SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate
FROM session_daily
ORDER BY date;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add missing GROUP BY for daily funnel aggregates

Line 363 selects date alongside aggregates without a GROUP BY, which will fail in BigQuery.

🔧 Proposed fix
 SELECT
   date,
   COUNT(*) AS sessions,
   SUM(has_view_item) AS sessions_with_view_item,
   SUM(has_add_to_cart) AS sessions_with_add_to_cart,
   SUM(has_begin_checkout) AS sessions_with_begin_checkout,
   SUM(has_purchase) AS sessions_with_purchase,
   SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate,
   SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate,
   SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate,
   SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate
 FROM session_daily
+GROUP BY date
 ORDER BY date;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
date,
view_item_events,
add_to_cart_events,
begin_checkout_events,
purchase_events,
event_order_revenue,
SAFE_DIVIDE(add_to_cart_events, NULLIF(view_item_events, 0)) AS add_to_cart_per_view_item,
SAFE_DIVIDE(begin_checkout_events, NULLIF(add_to_cart_events, 0)) AS begin_checkout_per_add_to_cart,
SAFE_DIVIDE(purchase_events, NULLIF(begin_checkout_events, 0)) AS purchase_per_begin_checkout,
SAFE_DIVIDE(purchase_events, NULLIF(view_item_events, 0)) AS purchase_per_view_item
FROM daily
COUNT(*) AS sessions,
SUM(has_view_item) AS sessions_with_view_item,
SUM(has_add_to_cart) AS sessions_with_add_to_cart,
SUM(has_begin_checkout) AS sessions_with_begin_checkout,
SUM(has_purchase) AS sessions_with_purchase,
SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate,
SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate
FROM session_daily
ORDER BY date;
date,
COUNT(*) AS sessions,
SUM(has_view_item) AS sessions_with_view_item,
SUM(has_add_to_cart) AS sessions_with_add_to_cart,
SUM(has_begin_checkout) AS sessions_with_begin_checkout,
SUM(has_purchase) AS sessions_with_purchase,
SAFE_DIVIDE(SUM(has_add_to_cart), NULLIF(SUM(has_view_item), 0)) AS view_to_cart_rate,
SAFE_DIVIDE(SUM(has_begin_checkout), NULLIF(SUM(has_add_to_cart), 0)) AS cart_to_checkout_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(SUM(has_begin_checkout), 0)) AS checkout_to_purchase_rate,
SAFE_DIVIDE(SUM(has_purchase), NULLIF(COUNT(*), 0)) AS session_conversion_rate
FROM session_daily
GROUP BY date
ORDER BY date;
🤖 Prompt for AI Agents
In `@data-activation/template-resources/sql-query-library.mdx` around lines 363 -
374, The query in the session_daily aggregation selects date plus aggregate
expressions (aliases sessions, sessions_with_view_item, view_to_cart_rate, etc.)
but lacks a GROUP BY, causing BigQuery to fail; update the SQL in the
session_daily query block to add a GROUP BY date (grouping by the selected date
column) before the ORDER BY date so the aggregates are computed per date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant