To deduplicate AI citations, store the exact URL an engine cited, derive a normalized key from it, and group by that key when you report. The key comes from a fixed set of rules: lowercase the host, drop fragments, strip tracking parameters, apply one trailing-slash rule, then optionally resolve the page's declared canonical. Never overwrite the raw URL. The key decides what counts as one source, and the raw value lets you redo that decision later.
Why variants inflate your numbers
One page can be cited under several strings: with and without ?utm_source=..., with http or https, with a trailing slash, with a # fragment. A naive report counts each string as a separate source. That inflates "unique sources cited" and splits one page's citation history across rows, so trends look weaker than they are.
Google's documentation describes the same problem on the search side. It treats URLs with the same content as duplicates and consolidates them around one canonical URL [1]. Search Console Help says Google picks one canonical from the duplicates and usually does not show the others in results [2]. Your reporting should apply the same logic to cited URLs.
What to record for every citation
Store one row per citation event, before any cleanup:
| Field | Purpose |
|---|---|
raw_url | Exactly what the engine returned. Never edited. |
normalized_key | Output of your normalization rules. Used for grouping. |
canonical_url | Declared canonical from the fetched page, if you resolve it. Nullable. |
engine | Which AI engine produced the answer. |
prompt_id | Which tracked prompt produced it. |
observed_at | Timestamp of the run. |
Keeping raw_url is what makes every later change safe. If you decide next quarter to treat a parameter differently, you re-run the key derivation over stored rows. One citation-tracking tool's documentation describes the same split: it matches citations on a URL with utm_ parameters removed, and a repeat citation of that URL, including from different engines, lands in one row [4].
Normalization rules, in order
Apply these in a fixed order so the same input always produces the same key.
- Lowercase the scheme and host. Paths can be case-sensitive, so leave them alone.
- **Treat
httpandhttpsas one.** Pickhttpsfor the key. - Drop the fragment. Fragments are not separate documents. The tool above also strips quote-link fragments and YouTube timestamps for some engines [4], which is a sign engines can append them.
- Remove tracking parameters. Strip
utm_*[4] and the click identifiers you see in your own data, such asgclid,fbclidandmsclkid. - Keep parameters that change content.
?id=42or?page=2can point to a different page. Use an explicit list of parameters to remove, not a rule that drops every query string. - Sort the remaining parameters so
?a=1&b=2and?b=2&a=1match. - Apply one trailing-slash rule and one
wwwrule, the same ones the site enforces. Our guide to www, non-www and trailing slashes covers choosing and enforcing them.
A minimal implementation:
from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode
TRACKING_PREFIXES = ("utm_",)
TRACKING_KEYS = {"gclid", "fbclid", "msclkid"}
def normalized_key(raw_url: str) -> str:
p = urlsplit(raw_url.strip())
host = p.netloc.lower() # apply your www rule here too
path = p.path or "/"
if path != "/" and path.endswith("/"):
path = path.rstrip("/") # your site's trailing-slash rule
params = [
(k, v) for k, v in parse_qsl(p.query, keep_blank_values=True)
if not k.lower().startswith(TRACKING_PREFIXES)
and k.lower() not in TRACKING_KEYS
]
query = urlencode(sorted(params))
return urlunsplit(("https", host, path, query, ""))
Before and after:
raw_url | normalized_key |
|---|---|
http://Example.com/guide/?utm_source=chat | https://example.com/guide |
https://example.com/guide#section-2 | https://example.com/guide |
https://example.com/guide?utm_medium=ai&gclid=abc | https://example.com/guide |
https://example.com/products?id=42 | https://example.com/products?id=42 |
The first three rows collapse into one source. The fourth stays separate because its parameter selects content.
Resolving canonical variants
Some variants cannot be caught by string rules: a print version, a parameterized sort order, a page reachable under two paths. For these, fetch the cited page and read its rel="canonical". Google recommends absolute URLs in that tag, not relative paths [1], so a well-formed canonical can be compared directly against your keys.
Treat the canonical as a grouping hint:
- If the fetch succeeds and a canonical is present, set
canonical_urland run it throughnormalized_keytoo. - If the fetch fails, the page redirects somewhere unexpected, or there is no canonical, fall back to the normalized key and flag the row for review.
- If the canonical points to a different domain, do not merge automatically. Review those rows by hand.
Then define the group key as normalize(canonical_url) when present, otherwise normalized_key. To check which URL Google actually selected for a page, see the canonical tags guide.
Count events and sources separately
Deduplication changes what "one" means, so say which count a number is.
- Distinct sources: the number of unique group keys cited. This is the one deduplication directly affects.
- Citation events: rows per group key, split by engine, prompt and date. Keep these. A page cited by two engines is one source with two engines, not one engine's win.
Within a single prompt run, count a group key once even if the answer links it twice. Across runs, keep each run as its own event so you can see change over time. For why single-run percentages need caution, see why "you appear in X% of answers" is dishonest. Deduplication does not fix that, but it removes one source of inflation.
Also decide whether your own domain's pages and third-party pages that mention you share a report. Names and links are different events, covered in AI citation vs mention.
Fixing history
If your analytics tool collects landing-page URLs, removing tracking parameters there only helps going forward. One analytics vendor's guidance says the change applies only to new data because past data is not reprocessed [5]. Do not rely on that fix for old rows.
Store raw URLs in your own table, then re-run the key derivation across all rows whenever the rules change. Version the rules (key_version on each row) so you can tell which rows used which logic.
What to do next
- Add
raw_url,normalized_keyandkey_versioncolumns to your citation table, and backfill the key from existing rows. - Write the strip list from parameters actually present in your data, starting with
utm_*. - Add the canonical lookup for rows whose keys still look like duplicates, and flag failed lookups.
- Report distinct sources by group key. Report citation events as a separate column, never summed with the first.
- Spot-check the largest groups each month. Any group that merges unrelated pages means a parameter rule is too aggressive. Fix the rule, bump
key_version, and regenerate the keys.