Sub topic 3
Tagging links with UTM parameters
This chapter assumes you know what a URL and its query string are, and that you have seen a social media post or ad creation screen. You do not need GA4 installed yet. Later chapters cover installing it and reading the reports.
Why links need labels
When someone clicks a link in a social post, the browser may send a referrer, which is the address of the page the visitor came from. Referrers are often missing or generic. An in-app browser might report only l.instagram.com, a link shortener, or nothing at all. If you run five Instagram posts and two Instagram ads, your analytics cannot tell them apart from the referrer alone.
UTM parameters solve this. A UTM parameter is a key-value pair you add to the query string of a link. The name comes from Urchin Tracking Module, an early analytics product. Google Analytics reads these values when the visitor lands and stores them with the session. The parameters do not change the page that loads. They only label the visit.
Here is a tagged landing page URL:
https://example.com/spring-sale?utm_source=instagram&utm_medium=paid_social&utm_campaign=spring_sale_2026&utm_content=carousel_aThe part before the ? is the page. Everything after it is the query string, with pairs joined by &.
The five parameters
| Parameter | Question it answers | Example | Required for GA4 |
|---|---|---|---|
| `utm_source` | Which site or platform sent the visitor? | `instagram` | Yes |
| `utm_medium` | What kind of traffic is it? | `paid_social` | Yes |
| `utm_campaign` | Which campaign or initiative? | `spring_sale_2026` | Recommended |
| `utm_content` | Which ad, post, or creative variant? | `carousel_a` | No |
| `utm_term` | Which keyword? (mainly paid search) | `running_shoes` | No |
GA4 treats utm_source, utm_medium and utm_campaign as the core set. Google's own documentation lists source, medium and campaign name as the values to use for manual tagging, so supply all three on every link. Use utm_content whenever you test more than one post or creative against the same campaign. You rarely need utm_term for social.
GA4 also supports utm_id, utm_source_platform, utm_creative_format and utm_marketing_tactic. Most teams skip them. utm_id matters mainly when you import cost data from ad platforms and need to join it to sessions.
What each parameter should hold
Source
Use the platform name in lowercase, one spelling per platform: instagram, facebook, linkedin, x, tiktok, youtube, reddit. Pick x or twitter once and keep it. Do not put the account or the campaign in the source.
Medium
Medium is the most important value because GA4 uses it, together with source, to assign the session to a default channel group. Social traffic is placed in Organic Social or Paid Social by rules that check the source against a list of known social sites and the medium against patterns.
Practical rules:
- Use
paid_socialfor ads. Google's channel rules treat mediums matching paid patterns such ascpc,ppc,paidsocialorpaid_socialas paid, sopaid_socialis safe and readable. - Use
socialfor organic posts. A medium ofsocial,social-network,social-media,smor similar is recognized as organic social. - Do not invent mediums like
instagram_postorfb_ad. They fall into the Unassigned or Referral channels and your channel reports will be wrong.
Campaign
The campaign name groups all links belonging to one initiative. Use a pattern that sorts well, such as theme_period: spring_sale_2026, webinar_oct_2026. If you also use email or search for the same initiative, reuse the same campaign name there so you can see the full picture.
Content
Use content to separate individual links inside a campaign: carousel_a, video_15s, founder_quote, bio_link. Name the thing that differs, so that a comparison between two values means something.
Naming conventions
Analytics is case sensitive in these fields. Instagram, instagram and INSTAGRAM show up as three separate rows in reports. A single stray capital letter splits your data, and you cannot merge the rows afterward.
Adopt these rules and write them down in a shared document:
- Use lowercase only.
- Use underscores instead of spaces (spaces become
%20in the URL and look messy). - Use a fixed vocabulary for source and medium, and keep the list short.
- Avoid personal data such as email addresses or names in any value. Values appear in reports and can be sent to third parties.
- Keep values short and readable, since people read them in reports.
- Never reuse a campaign name for a different initiative.
A simple tracking sheet is enough to enforce this. Each row holds the base URL, the five values and the final URL built by a formula. Team members copy from the sheet and do not type parameters by hand.
Building tagged URLs reliably
Typing query strings by hand causes errors. A small helper function builds the URL, lowercases the values and encodes them correctly.
function buildTaggedUrl(baseUrl, tags) {
const url = new URL(baseUrl);
Object.keys(tags).forEach(function (key) {
const value = String(tags[key]).trim().toLowerCase().replace(/\s+/g, '_');
if (value) url.searchParams.set(key, value);
});
return url.toString();
}
console.log(buildTaggedUrl('https://example.com/spring-sale', {
utm_source: 'Instagram',
utm_medium: 'paid_social',
utm_campaign: 'Spring Sale 2026',
utm_content: 'carousel_a'
}));
// https://example.com/spring-sale?utm_source=instagram&utm_medium=paid_social&utm_campaign=spring_sale_2026&utm_content=carousel_aURL and searchParams take care of the ? and & separators and of percent-encoding. The helper also keeps any query parameters the base URL already has, because set adds to the existing string.
Where tags go, and where they must not
Tag every link you control that points to your site from a place that does not pass a reliable referrer:
- Links in organic posts, captions and comments.
- The link in a profile bio, with a distinct
utm_contentsuch asbio_link. - Link stickers in stories, and pinned posts.
- Influencer and partner links.
- Email and messaging app links shared from a social campaign.
- Paid ads, either typed into the destination URL or added through the ad platform's URL parameter field.
Do not tag links between pages of your own site. When a visitor clicks an internal link that carries UTM values, GA4 starts a new session and attributes it to the tag, overwriting the original source. Your social conversions then appear to come from your own site, and you lose the real origin.
Paid ads and dynamic values
Ad platforms can fill in values for you using placeholders in a URL parameters field. Facebook and Instagram ads support macros like {{campaign.name}}, {{adset.name}} and {{ad.name}}. This keeps names in sync with the ad platform, but it also means any uppercase letters or spaces in those names reach your analytics. Name ads in lowercase with underscores from the start, or hard-code the values.
Some ad platforms also add a click ID such as fbclid or ttclid. These are separate from UTM parameters and are covered in a later chapter. Do not remove them to "clean up" the URL.
Keeping the tags after the landing page
UTM values exist in the URL only on the landing page. If the visitor moves on to a form on another page, the query string is gone. GA4 keeps the session's attribution on its own, but your form, CRM or back-end database does not see it unless you save the values.
This script stores the values for the session so you can attach them to a form later:
const params = new URLSearchParams(window.location.search);
const keys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
const utm = {};
keys.forEach(function (k) {
if (params.get(k)) utm[k] = params.get(k);
});
if (Object.keys(utm).length > 0) {
sessionStorage.setItem('utm', JSON.stringify(utm));
}Because the script writes only when a UTM parameter is present, a visitor who clicks around the site keeps the first values. A later visit without parameters does not erase them. Note that sessionStorage is cleared when the tab closes. Use a first-party cookie or localStorage if you need the values to last longer, and check the consent rules in the privacy chapter before you do.
Edge cases and failure modes
- Redirects strip parameters. A redirect from
httptohttps, from a short link, or from awwwto a non-wwwhost can drop the query string if configured badly. Test the final URL after all redirects, not the one you typed. - In-app browsers and privacy features. Some apps open links in their own browser, where analytics scripts or cookies behave differently. Tags usually survive, but the session may look like a new user each time.
- Link shorteners. They are fine for UTM links as long as they redirect with the full query string intact. Tag the long URL first, then shorten it.
- Case and spacing. As noted,
Socialandsocialcreate two rows. Fix the source of the error, because past data cannot be re-labeled. - Reserved words. Setting
utm_source=director usingutm_medium=(none)can distort reports. Do not use them. - Overriding good data. A visitor who arrives from an email link tagged
utm_medium=socialis counted as social. Tag by where the link is placed, not by what you hope it will do. - Organic social without tags. Untagged social visits often appear as Referral, for example from
t.coorl.facebook.com, or as Direct when no referrer is passed. Tagging makes these visits attributable. It cannot recover visits that happened before you tagged. - Long URLs and encoding. If a value contains
&,#or?, encode it. The helper above does this throughsearchParams. A raw#cuts off everything after it, because the browser treats it as the start of a fragment.
Checking that a tag works
- Open the tagged URL in a private browser window.
- In GA4, open Reports, then Realtime, and look for the session under traffic source.
- Confirm that source, medium and campaign match what you typed, with no extra capitals.
- After 24 to 48 hours, open Reports, Acquisition, Traffic acquisition and set the dimension to Session source / medium. Check the default channel group column too.
A source that appears as (not set) usually means the parameters were lost along the way or are misspelled.
How the pieces fit together
Summary of rules
- Always set source, medium and campaign. Add content to separate variants.
- Use lowercase, underscores and a short fixed vocabulary.
- Use
socialfor organic andpaid_socialfor ads. - Tag external links only. Never tag internal links.
- Save the values if a later page needs them.
- Test after redirects and check the channel group.
Exercise
Your team posts the same product video on LinkedIn twice in one week: once as an organic post and once as a paid ad. Both go to https://example.com/demo for the campaign "Product Demo Q4". Write the two tagged URLs so that GA4 separates them by channel, and say what goes wrong if the paid link uses utmmedium=LinkedInAd.
Show answer
Organic: https://example.com/demo?utmsource=linkedin&utmmedium=social&utmcampaign=productdemoq4&utmcontent=videoorganic Paid: https://example.com/demo?utmsource=linkedin&utmmedium=paidsocial&utmcampaign=productdemoq4&utmcontent=videoad Both share the same source and campaign, so you can compare them within the campaign, while the medium decides the channel (Organic Social versus Paid Social). With utmmedium=LinkedIn_Ad, the medium does not match a paid or social pattern, so GA4 cannot put the session in Paid Social. It would most likely land in Unassigned or Referral, and the uppercase letters would also create a separate row from any lowercase variant.
Exercise
A visitor lands on https://example.com/pricing?utmsource=facebook&utmmedium=social&utmcampaign=autumnlaunch, then clicks an internal link to your signup page. A teammate has added the same UTM parameters to that internal link. Why is this a problem, and what should the link look like instead?
Show answer
GA4 reads the UTM values on the second page as a new campaign visit, so it starts a new session and overwrites the original attribution with the values on the internal link. Reports then credit your own site's tagging and hide the real origin. The internal link should have no UTM parameters, for example https://example.com/signup. If you need the original values on the signup form, save them on the landing page with sessionStorage and read them when the form is submitted.