A campaign URL carries two kinds of extra information after the main address: the query string, where UTM parameters live, and the fragment identifier, which points to a place inside the page. They look similar because both follow a separator character, but browsers, servers and analytics tools treat them completely differently. Mixing them up is one of the most common reasons tracking data goes missing or a link lands on the wrong part of a page.
Anatomy of a campaign URL
Take a typical example: https://example.com/sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring#pricing. Everything before the question mark is the address the server uses to find the page. The query string begins at ? and contains key-value pairs joined by &. The fragment begins at # and is handled by the browser after the page loads.
What UTM parameters actually do
UTM parameters are five conventional query keys — utm_source, utm_medium, utm_campaign, utm_term and utm_content — that analytics platforms read to attribute a visit to a source, channel and campaign. They are not a web standard; they are a naming convention that Google Analytics popularized and that most other analytics tools now recognize. The server receiving the request usually ignores them, which is why adding them rarely changes what a visitor sees.
Because they are plain query parameters, they must follow query-string rules: lowercase values are the common convention, spaces should be encoded (or replaced with hyphens or underscores), and characters such as &, ? and # must be percent-encoded if they appear inside a value.
What a fragment identifier does
A fragment identifier tells the browser to jump to a matching element on the page, typically an anchor such as id="pricing". It is never sent to the server in the HTTP request, so server-side logs and most analytics setups do not see it. Fragments are also used by single-page applications for client-side routing and by some scripts to pass state.
This has two practical consequences for campaigns. First, a fragment cannot carry tracking data on its own — analytics will not record it. Second, if you place a fragment before your UTM parameters, everything after the # becomes part of the fragment and the parameters stop working.
Correct order: query string first, fragment last
The fragment must always be the final part of a URL. The correct pattern is:
- Base URL with path:
https://example.com/sale - Question mark and UTM parameters:
?utm_source=...&utm_medium=...&utm_campaign=... - Fragment at the very end:
#pricing
If you need to keep an existing fragment on a landing page while adding tracking, insert the query string before the #, not after it. Many campaign builders and spreadsheet formulas get this wrong, so check the finished link before sending it out.
Common mistakes that break tracking
- Fragment before parameters:
page#section?utm_source=x— the parameters are swallowed by the fragment. - Inconsistent naming:
utm_sourcein one link andsourceorUTM_Sourcein another splits your reports. Pick a convention and document it. - Unencoded special characters: an unescaped
&inside a value cuts the parameter short and creates a new, meaningless key. - Duplicate keys: appending UTM parameters to a URL that already has them produces conflicting values, and analytics tools may record only one.
- Tracking internal links: UTM parameters on links between your own pages restart sessions and overwrite the original source, which distorts attribution.
Shortening campaign URLs without losing the data
Long UTM strings are hard to read, easy to truncate in chat apps and email clients, and can look suspicious. A link shortener solves the presentation problem by mapping a compact short url to the full destination, including the query string and fragment. When you shorten link targets for a campaign, the redirect must preserve the complete original URL — parameters, encoding and fragment — or the tracking you carefully built disappears.
Two details are worth checking with any url shortener you use. First, confirm that it forwards query strings and fragments unchanged rather than stripping them. Second, decide whether you want the tracking parameters baked into the destination or appended dynamically by the shortener; the first is simpler and more portable, the second lets you reuse one short link across channels. Either approach works, but mixing both on the same link creates duplicates.
A quick pre-flight checklist
- Does the URL contain exactly one
?before the parameters and no#until the very end? - Are all five UTM keys spelled consistently and in lowercase?
- Are spaces and special characters encoded?
- Does the fragment match an actual element ID on the landing page?
- After shortening, does the short link resolve to the identical full URL, fragment included?
- Have you tested the link in a private browser window and confirmed the visit appears in analytics with the expected source and campaign?
Treat the query string as the place for tracking and the fragment as the place for navigation, keep them in that order, and verify the final redirect. That is enough to keep campaign data intact from the first click to the report.