Cleaning Tracking Parameters from URLs

easy
Unit 11 · Stdlib0/3 to milestone

Implement clean_url(url) that removes tracking query parameters and normalises the URL:

  • drop parameters starting with utm_ and the exact names fbclid, gclid, mc_eid, ref
  • keep the remaining parameters (including repeated ones) but sort them by name (stable for equal names)
  • lower-case the scheme and host; remove a trailing ? if no parameters remain; drop the #fragment

Use urllib.parse (urlsplit, parse_qsl, urlencode, urlunsplit).

#urls#stdlib2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Cleaning Tracking Parameters from URLs · TechGradify