Sub topic 11
Tracking clicks with UTM parameters
Platform dashboards tell you how many people clicked a link. They don't tell you what those people did next. UTM parameters close that gap by labeling each link, so your web analytics tool can attribute the resulting visits to a specific post, campaign, or channel.
This chapter assumes you know what a link click and click-through rate are, and that you have access to a web analytics tool such as Google Analytics 4 (GA4). Basic comfort with URLs and a little Python helps for the code example.
What UTM parameters are
A UTM parameter is a short key-value pair added to the end of a URL. "UTM" stands for Urchin Tracking Module, named after the analytics product Google acquired and built into Google Analytics. The parameters have no effect on the page that loads. Your analytics tool reads them when the visit begins and stores them with the session.
There are five standard parameters:
| Parameter | Purpose | Example value |
|---|---|---|
| `utm_source` | Where the traffic comes from | `linkedin` |
| `utm_medium` | The type of channel | `social` |
| `utm_campaign` | The campaign or initiative | `spring_sale` |
| `utm_content` | Which variant or post within the campaign | `post_a` |
| `utm_term` | A keyword, mostly used for paid search | `running_shoes` |
For social media posts, the first three do most of the work. utm_content lets you separate two posts, two images, or two calls to action inside one campaign. utm_term is rarely needed outside paid search.
GA4 treats source, medium, and campaign as the core set. A link with only utm_source can produce incomplete or confusing reports, so set all three every time.
An annotated example
Here is the link from the spine, tagged for a LinkedIn post:
https://example.com/spring-sale?utm_source=linkedin&utm_medium=social&utm_campaign=spring_sale&utm_content=post_aReading it from left to right:
https://example.com/spring-saleis the real destination.?starts the query string.- Each
key=valuepair is joined to the next with&. - If the destination already has a query string, such as
?ref=home, you append your parameters with&instead of a second?. - If the URL has a fragment (the
#sectionpart), the query string must come before it.
Anyone who clicks this link lands on the sale page. In your analytics tool, that session is recorded as source linkedin, medium social, campaign spring_sale, with content post_a.
How a click becomes an attributed visit
Two systems measure the same click from different sides. The platform records the click on its side. Your analytics tool records the visit when the page loads. UTM parameters are the label that connects the two.
The two counts measure different things. The platform's link clicks measure intent to visit. The analytics sessions measure visits that actually loaded and were recorded. Expect the session count to be lower, and don't treat the gap as an error without checking the causes below.
Why clicks and sessions rarely match
A gap between platform link clicks and analytics sessions is normal. Common causes:
- Abandoned loads. The user closes the tab or goes back before the page finishes loading, so the analytics script never runs.
- Consent banners. If a visitor declines tracking, the session may not be recorded at all.
- Bots and link previews. Some platforms and messaging apps fetch links automatically. Platforms may filter these from click counts, while analytics tools may or may not do so.
- In-app browsers. Many apps open links in an embedded browser. It may block scripts or cookies, which can change how the visit is attributed.
- Different definitions. A platform's "link click" may differ from other click types, as covered in the earlier chapters on clicks and platform definitions.
A gap of 10 to 30 percent is not unusual. A much larger gap, or one that suddenly changes, is worth investigating. For example, a broken redirect or a missing analytics tag on the landing page can cause one.
Building links with a script
Typing UTM links by hand leads to typos, and typos split your data into separate rows. A small helper makes links consistent. This script uses only the standard library:
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
def clean(value):
"""Lowercase, trim, and replace spaces so values stay consistent."""
return value.strip().lower().replace(" ", "_")
def add_utm(url, source, medium, campaign, content=None, term=None):
"""Return url with UTM parameters added, keeping any existing query."""
parts = urlsplit(url)
query = parse_qsl(parts.query, keep_blank_values=True)
utm = {
"utm_source": source,
"utm_medium": medium,
"utm_campaign": campaign,
"utm_content": content,
"utm_term": term,
}
query.extend((key, clean(val)) for key, val in utm.items() if val)
return urlunsplit(
(parts.scheme, parts.netloc, parts.path, urlencode(query), parts.fragment)
)
print(add_utm(
"https://example.com/spring-sale",
source="LinkedIn",
medium="social",
campaign="Spring Sale",
content="post_a",
))
print(add_utm(
"https://example.com/pricing?ref=home#plans",
source="x",
medium="social",
campaign="spring_sale",
))The first call prints the exact link from the example above. The second shows that an existing ?ref=home is kept and the #plans fragment stays at the end:
https://example.com/spring-sale?utm_source=linkedin&utm_medium=social&utm_campaign=spring_sale&utm_content=post_a
https://example.com/pricing?ref=home&utm_source=x&utm_medium=social&utm_campaign=spring_sale#plansThe clean function lowercases every value. That matters because of the next topic.
Naming conventions
UTM values are case-sensitive in reports. LinkedIn, linkedin, and Linkedin appear as three separate sources. The same goes for spring_sale and spring-sale. This is the most common cause of messy UTM data.
Agree on a convention before the first link goes out, and write it down. A workable convention:
- Use lowercase only.
- Use underscores instead of spaces or hyphens, and never mix the two.
- Use a fixed list of sources (
linkedin,instagram,facebook,x) and a fixed list of mediums (social,paid_social,email). - Name campaigns after the initiative, optionally with a date, such as
spring_sale_2026. - Keep a shared spreadsheet that logs every tagged link with its post and owner.
Use a different medium for paid and organic posts. If both use social, you can't separate paid results from organic ones in reports. Using paid_social for ads keeps them apart.
Gotchas and limits
UTM tagging is simple, but it has real limits.
- Never tag internal links. If a link on your own website carries UTM parameters, a click on it starts a new session in many setups and overwrites the original source. A visitor who arrived from LinkedIn would then appear to come from your own site.
- UTMs are visible. Anyone can read and edit the URL. Don't put names, emails, or other personal data in a value.
- Links get shared. If a user copies your tagged link and pastes it into a private chat or email, those visits still count as
linkedin. This is part of "dark social," traffic that is hard to attribute. - Shorteners and redirects. A link shortener is fine if the final URL keeps its query string. Test the link, because some redirects drop parameters.
- Long URLs. Tagged links look messy in a post. Platforms usually shorten them in the preview, or you can use a shortener.
- Organic platform traffic. Many platforms send some visits with a referrer but no UTM. Analytics may then label them as plain referral traffic, so untagged links produce less reliable numbers than tagged ones.
- Don't track what you won't use. Every parameter adds a dimension to the data. Add
utm_contentonly when you will actually compare variants.
Using the data
Once tagged traffic arrives, you can compare post-level results by looking at what happens after the click. In GA4, the session source/medium and session campaign reports show the tags. From there you can look at:
- Sessions by campaign, to compare how many visits each effort produced.
- Engagement on the site, such as engaged sessions or time on page, to judge visit quality.
- Conversions, such as sign-ups or purchases, to connect the post to a business result.
This changes how you judge a post. A post with a high click-through rate that sends visitors who leave at once may be less useful than a post with fewer clicks that produces sign-ups. UTM tracking is what lets you see that difference. It extends the funnel from the platform's click count to an outcome on your site.
When you report, state which numbers came from the platform (impressions, reach, link clicks) and which came from analytics (sessions, conversions). Don't divide one by the other without saying so. Dividing analytics sessions by platform impressions, for example, mixes two systems with different counting rules.
Exercise
A team posts the same sale link on LinkedIn on Monday as utm_source=LinkedIn and on Wednesday as utm_source=linkedin. Both use utm_medium=social and utm_campaign=spring_sale. What problem will they see in their analytics report, and how do they prevent it?
Show answer
Analytics treats values as case-sensitive, so the two posts appear as two separate sources, and the LinkedIn totals are split across two rows. To prevent it, agree on a lowercase-only naming convention, keep a shared log of tagged links, and generate links with a helper that lowercases every value. For existing data, add the two rows together when reporting.
Exercise
A post shows 400 link clicks on the platform, but analytics shows 310 sessions for the tagged link. Is this necessarily a tracking error? Name two possible causes.
Show answer
No. A gap like this is normal, because the platform counts clicks and analytics counts only visits where the page loaded and the tracking ran. Possible causes include users leaving before the page loads, visitors declining consent so no session is recorded, in-app browsers blocking scripts, and bots or link previews being counted differently. It is worth investigating only if the gap is unusually large or changes suddenly.
Exercise
Write the correct tagged URL for a Facebook post in the summer_launch campaign, variant video_1, pointing to https://example.com/launch?ref=home, with medium social.
Show answer
https://example.com/launch?ref=home&utmsource=facebook&utmmedium=social&utmcampaign=summerlaunch&utmcontent=video1 (the existing query string is kept and the new parameters are joined with &).