feat(db): resolve profile_id via profile_aliases in funnel & conversion - #329
Merged
Merged
Conversation
Stitch anonymous -> identified profiles at read time so funnels/conversions that start on an anon event (logInInitiate, $ae_first_open, _first_event) and end on an identified event (logIn, trialStarted) connect into one user. - conversion.service: resolve profile_id at the event-source CTE (buildSingleEventCte) via a shared `al` alias map; start/end dedup, the ASOF join and the end-in-start prefilter all use the canonical id automatically. - funnel.service: resolve at the group level (post-union) so custom events are handled too; also resolves the time-to-convert path. Self-gating: no env/allowlist - a no-op for projects with no aliases (coalesce keeps the raw id). Skipped for session-level grouping, cohorts (cohort joins match raw profile_id) and, in conversion, custom events (would mix raw/resolved). Raw column qualified as events.profile_id so the SELECT output alias does not bind into the join key. Validated on dashreels: logInInitiate->logIn 0.19% -> 76.8% (7d); _first_event->logIn 71% with 20s median time-to-convert.
harshitsaamu
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Resolve anonymous
profile_id→ canonical (backend_userid) at read time via theprofile_aliasesidentity map, so funnels/conversions that start on an anon event (logInInitiate,$ae_first_open,_first_event) and end on an identified event (logIn,trialStarted) stitch into a single user instead of reading as two separate people.This is the read side of the identity-merge work (write path shipped earlier: forked #322 + proxy alias emit). Nothing read
profile_aliasesuntil now.How
conversion.service.ts— resolveprofile_idat the event-source CTE (buildSingleEventCte) via a sharedalalias map (argMax(profile_id, created_at)per alias).start_events/end_eventsdedup, the ASOF join and the end⊆start prefilter then all use the canonical id automatically.funnel.service.ts— resolve at the group level (post-union), so custom events are handled with no special-casing; the time-to-convert path is resolved too.Gating (no hack — self-gates on data)
There is no env var / allowlist. The resolution is a no-op for projects with no aliases (
coalesce(nullIf(al.canonical,''), profile_id)just returns the raw id), so projects withoutprofile_aliasesrows are byte-identical to before. The only conditions are correctness, not config:profile_id);The raw column is qualified as
events.profile_idso the SELECT output alias (alsoprofile_id) doesn't bind into the join key.Validation (dashreels, dev)
logInInitiate → logIn(7d)_first_event → logIn(1d)$ae_first_open → trialStarted(1mo)Typecheck clean on both files.
Out of scope / follow-ups
🤖 Generated with Claude Code