Skip to content

Citations: query-keyed URLs (YouTube watch) lose their identity — broken links and merged counts #557

Closed

Description

@gkhngyk

Problem

Citation URL aggregation normalizes URLs by stripping the query string and fragment (to dedupe ?utm_… noise) before bucketing:

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:

  1. 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 /watch URL instead of the video.
  2. Merged counts — every distinct YouTube video the brand is cited in collapses into one youtube.com/watch row; 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:

  1. 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 both citations.ts and tracking.ts — the two copies exist today and have already drifted once. (Note: it can't be exported from citations.ts directly — that file is 'use server', which only allows async action exports.)
  2. 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.com path /watch → keep v. Structure it as a small host→params table so future cases are one-line additions.
  3. 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=abc links 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=abc with extra utm_… params still buckets with plain ?v=abc.
  • Non-query-keyed URLs bucket exactly as before.
  • yarn lint, yarn typecheck, yarn format:check pass from web/.

Activity

  1. added
    bug
    good first issue
    on Jul 29, 2026
  2. abdullah91111 commented on Jul 29, 2026

    @abdullah91111
    Contributor

    will work on it

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions