← All notes

Web basics

How to remove tracking parameters from a URL

Shorten a shared link while keeping the parts that make it work.

A copied link can include both the information needed to open a page and labels describing where a visitor came from. Removing familiar campaign labels makes the link easier to read. It does not make a visit anonymous.

Start with a copy

Consider this invented product link:

https://example.com/item?color=blue&utm_source=newsletter&utm_campaign=spring#details

Here, color=blue selects a variation, the two utm_ parameters label a campaign, and #details points to a section. A more compact version keeps the useful selection and section:

https://example.com/item?color=blue#details

Remove only what you recognize

  1. Keep the original link until you have checked the replacement.
  2. Remove known campaign parameters, including the connecting & where needed.
  3. Open the edited link and confirm the page, selected options, and section still match.

A URL's query begins after ?; its fragment begins after #. Deleting everything after the question mark can remove search terms, pagination, or required access information. Avoid editing signed links and password-reset links.

For a repeatable cleanup

In JavaScript, use new URL(link) and delete selected names with url.searchParams.delete("utm_source"). URL serialization can change encoding, so it is unsuitable when the exact original bytes must remain intact.

A shorter address still exposes the destination and any information you leave in it. Check the whole link before sharing.

Further reading