Product Event Model: dbt Funnel and Quality Marts on 885K Events
event tracking · dbt · DuckDB · product analytics
Project snapshot
- Built: Built staged event models with a composite user-session key, deterministic event ordering, and separate funnel and quality marts.
- Stack: Python, DuckDB, dbt, SQL, pytest
- Result: 20,699 of 490,633 user-session pairs (4.2%) contained view-cart-purchase events; 165 of 885,129 events had no session ID.
- Recommendation: Use the user-session pair as the session grain, keep missing-session rows visible, and agree on event names, identity, and activation definitions before a live funnel.
- Code: dbt models and REES46 loader
Business question
Product teams cannot improve a customer journey if event names, identity, and session grain are unclear. A funnel can look precise while counting repeated events as people or silently excluding activity that cannot be tied to a session.
The decision is whether this public event model is reliable enough to demonstrate a safe measurement foundation. It is not a claim about a live product’s conversion.
Data and preparation
The REES46 Electronics behaviour export covers 24 September 2020 to 28 February 2021 in the loaded file. Each row is one recorded event. Event types are view, cart, and purchase.
The model checks event keys, event types, timestamps, and session coverage. It preserves the 165 rows with missing session IDs in the quality output and excludes them from session metrics.
Findings
Only 4.2% of user-session pairs contain a full recorded event sequence
The model finds 490,633 user-session pairs. Of these, 488,586 include a view, 41,232 include a cart event after a view, and 20,699 include a purchase event after that cart. That is 4.2% of pairs for the full sequence, and 50.2% from view-cart to purchase-event. These counts use the composite user-session grain, not raw event rows.
The event mix supplies context. It counts records, not unique users or sessions.
Views dominate the recorded activity, with fewer cart and purchase events. These counts describe events only; a user conversion rate needs a session or user denominator.
Session coverage is a visible quality check
The 165 rows without session IDs can still support event-volume reporting, but should not be silently included in a session funnel. Keeping them visible shows the size of that boundary.
The model keeps each measure at its proper grain
This separation reduces the risk of duplicating events when a downstream analysis joins event, user, or session summaries.
Result
The checks support event-level counts and an ordered funnel at the user-session pair grain: 20,699 of 490,633 pairs contain view, then cart, then purchase events. Another 165 event rows have no session ID and remain visible outside session measures. The export does not verify that a purchase event represents a completed order. No live activation or retention effect was measured.
Recommendation: use the user-session pair as the session grain, document the order of view, cart, and purchase events, and keep the 165 unassigned event rows visible. Before publishing a live funnel, product, engineering, and analytics should agree on event names, required properties, session identity, and what counts as an activated user. Add source-freshness, accepted-value, uniqueness, and session-coverage checks.
Data lineage and model checks
REES46 CSV
↓ analytics/load_rees46.py
DuckDB raw.events
↓ dbt staging
stg_rees46_events
├→ int_rees46_ordered_events → fct_product_funnel
└→ mart_event_quality
The intermediate model orders events by event time, source row number, then event ID. The staging model forms the session key from user ID and session ID; the funnel and quality marts keep their outputs separate.
This excerpt from analytics/models/marts/fct_product_funnel.sql only counts a cart after a view in the same identified session:
with first_view as (
select
user_session_key,
min(event_number) as view_event_number,
min(event_time) as viewed_at
from {{ ref('int_rees46_ordered_events') }}
where event_type = 'view'
group by 1
), first_cart as (
select
ordered.user_session_key,
min(ordered.event_number) as cart_event_number,
min(ordered.event_time) as carted_at
from {{ ref('int_rees46_ordered_events') }} as ordered
inner join first_view using (user_session_key)
where ordered.event_type = 'cart'
and ordered.event_number > first_view.view_event_number
group by 1
)
| Test | Protection |
|---|---|
stg_rees46_events.event_id schema tests | Event IDs are present and unique. |
stg_rees46_events.event_type schema tests | Values are present and limited to view, cart, or purchase. |
assert_event_dates_are_valid.sql | Event timestamps stay within the accepted range. |
assert_purchase_events_have_prices.sql | Purchase events have a nonnegative price. |
assert_rees46_session_key_is_pair_grain.sql | A composite session key maps to one user and one raw session ID. |
fct_product_funnel schema tests | Event date, event count, and purchase-session rate are present. |
test_rees46_loader_persists_a_stable_source_row_number | The loader keeps a stable row number for source ordering. |
What this can't tell you
This historical public browsing export is not current product telemetry or verified orders. It cannot establish live funnel conversion, activation, or retention effects.
Read technical details
Technical appendix
The pipeline keeps each layer focused: raw events → typed staging → ordered user-session pairs → separate funnel and quality marts. The composite key combines user ID and session ID because 214 raw session IDs map to multiple users. Sequence order is event time, then source row for timestamp ties. A test checks that each composite key maps to one user and one raw session ID.