Repository navigation
Closed
Labels
Description
Problem
Citation URL aggregation normalizes URLs by stripping the query string and fragment (to dedupe ?utm_… noise) before bucketing:
- web/src/lib/actions/citations.ts — the overview's URL aggregation (
parsed.search = '') - web/src/lib/actions/tracking.ts —
getPromptDetail's Top Sources URL aggregation keeps its own copy of the same rule
For sites whose page identity lives in the query string this is wrong. YouTube is the visible case: https://www.youtube.com/watch?v=<id> normalizes to https://www.youtube.com/watch, so:
- Broken links — clicking a YouTube row on the Citations page (or the title link on the per-URL detail page from Citations: per-URL detail page (cited-in answers, prompt breakdown, owned-URL bridges) #535) opens the bare
/watchURL instead of the video. - Merged counts — every distinct YouTube video the brand is cited in collapses into one
youtube.com/watchrow; its citation totals are the sum across different videos, and the per-URL detail page aggregates them as if they were one page.
(youtu.be/<id> and /shorts/<id> are path-keyed and unaffected.)
Fix
Make the normalization host-aware instead of blanket-stripping:
- Move the URL normalization helper (and the loose host+path match key) into a plain lib module, e.g.
web/src/lib/citations/normalize.ts, and import it from bothcitations.tsandtracking.ts— the two copies exist today and have already drifted once. (Note: it can't be exported fromcitations.tsdirectly — that file is'use server', which only allows async action exports.) - Keep the general rule (drop query + fragment, strip one trailing slash), but preserve identity parameters for known query-keyed hosts. v1 list:
youtube.com/m.youtube.compath/watch→ keepv. Structure it as a small host→params table so future cases are one-line additions. - No migration needed: all aggregations are computed at read time, so historical results re-bucket correctly as soon as the rule changes.
Acceptance
- A citation of
youtube.com/watch?v=abclinks to the actual video from the Citations page, the prompt detail Top Sources tab and the per-URL detail page. - Two different videos produce two distinct URL rows with separate counts;
?v=abcwith extrautm_…params still buckets with plain?v=abc. - Non-query-keyed URLs bucket exactly as before.
yarn lint,yarn typecheck,yarn format:checkpass fromweb/.
Activity
abdullah91111 commentedon Jul 29, 2026
will work on it