Sub topic 1
Why Tag Campaign Links
When you send people to your site from an email, an ad, or a social post, Google Analytics 4 (GA4) has to work out where each visit came from. Often it can't tell. This chapter explains why that happens, what UTM tagging changes, and when tagging is worth doing. Later chapters cover each parameter, the naming rules, and the reports in detail.
Prerequisites
This chapter assumes you already have the following:
- Basic familiarity with URLs and query strings. You know that
?a=1&b=2after a path carries key-value pairs. - A GA4 property with the web data stream installed, so page views already arrive in your reports.
- The ability to open GA4 reports, including the Reports and Explore areas.
- Optional: a browser with developer tools, for the console snippet near the end.
The attribution problem
Every GA4 visit needs an answer to the question "how did this person arrive?" GA4 calls this answer the traffic source. It is stored as dimensions such as source, medium, and campaign. Each dimension is a label attached to your data so you can group and filter it.
Without help from you, GA4 infers the traffic source from two signals:
- The HTTP referrer. This is the address of the page where the visitor clicked the link, which the browser sends along with the request.
- Google Ads auto-tagging, which appends a click ID to ad links. A later chapter covers it.
The referrer is unreliable for campaign work. It is missing or misleading in many common situations:
- Email clients. Desktop apps such as Outlook usually send no referrer. Webmail may send one, so a newsletter click can show up as a plain referral from a mail domain.
- Mobile apps. Many in-app browsers and messaging apps send no referrer, or send a generic one.
- Documents and offline media. A link in a PDF, a QR code on a poster, or a URL typed in from a printed flyer has no referring page.
- Protocol downgrades and privacy settings. A link from an HTTPS page to an HTTP page loses its referrer, and a site can set a strict referrer policy that strips it.
- Redirects and link shorteners. The referrer may be the shortener's domain, not the page that held the link.
When no referrer exists, GA4 records the visit as Direct. In the reports this appears as source (direct) and medium (none). Direct traffic then becomes a catch-all. It holds people who really did type your address, and also every email click, app click, and QR scan that lost its origin.
What a UTM tag does
A UTM tag is a set of query-string parameters you add to a link's destination URL. "UTM" stands for Urchin Tracking Module, a name inherited from the analytics product that Google's earlier tools grew out of. GA4 still reads these parameters.
The three core parameters are:
| Parameter | Answers the question | Example value |
|---|---|---|
| `utm_source` | Who or what sent the visitor? | `newsletter` |
| `utm_medium` | By what kind of channel? | `email` |
| `utm_campaign` | As part of which effort? | `spring_sale_2026` |
Two more parameters, utm_term and utm_content, add detail. utm_term records a keyword, and utm_content tells apart links that share a campaign. The next chapter defines all five.
Because the tag travels inside the URL, it doesn't depend on a referrer. Whatever app, document, or poster carried the link, the parameters arrive with the click. You are replacing a guess with a statement: you tell GA4 where the visit came from.
Here is a landing page URL tagged with the three core parameters plus utm_content, to tell apart links inside the same email:
https://example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale_2026&utm_content=hero_buttonThe part before the ? is the normal page address. Everything after it is the tag. Visitors land on the same page as before. Only the analytics changes.
Where tagging fits in the data flow
Tagging happens before GA4 is involved at all. You decide the values when you build the link, and GA4 only reads them when the page loads.
Two consequences follow from this flow.
- The landing page must keep the parameters in its URL. A redirect that drops the query string loses the tag before GA4 sees it.
- GA4 can't fix a bad tag after the fact. If you typed
utm_source=Newsletteron one link andutm_source=newsletteron another, GA4 stores two separate values, and the data stays split. This is why a later chapter is devoted to naming conventions.
A before-and-after example
Suppose you send a spring sale newsletter with one link in a hero button and one in a text footer. You send it to 20,000 subscribers, and 600 click through.
Without tags, your Traffic acquisition report might show:
| Session source / medium | Sessions |
|---|---|
| (direct) / (none) | 310 |
| mail.google.com / referral | 190 |
| outlook.live.com / referral | 60 |
| Other | 40 |
You can't read a newsletter result from this. The clicks are spread over several rows and mixed with unrelated visits. You can't compare this send with the last one, and you can't tell which button worked.
With tags on both links, the same visits look like this:
| Session source / medium | Session campaign | Sessions |
|---|---|---|
| newsletter / email | spring_sale_2026 | 600 |
The campaign now has one row you can find, trend, and compare. Add utm_content=hero_button and utm_content=footer_link to the two links, and you can split that row by link position.
The figures above are illustrative. The pattern is real, though: untagged email and app traffic gets scattered across Direct and referral rows, while tagged traffic is gathered under names you chose.
Building a tagged URL in code
You can type tags by hand, but this invites typos and inconsistent case. Teams that send many links usually use a spreadsheet template, a link-builder tool, or a small function. The function below requires the three core parameters, lowercases values, replaces spaces with underscores, and lets URLSearchParams handle encoding.
function buildCampaignUrl(baseUrl, { source, medium, campaign, id, term, content }) {
if (!source || !medium || !campaign) {
throw new Error('source, medium and campaign are required');
}
const url = new URL(baseUrl);
const params = {
utm_source: source,
utm_medium: medium,
utm_campaign: campaign,
utm_id: id,
utm_term: term,
utm_content: content,
};
for (const [key, value] of Object.entries(params)) {
if (value) {
url.searchParams.set(key, value.trim().toLowerCase().replace(/\s+/g, '_'));
}
}
return url.toString();
}
console.log(buildCampaignUrl('https://example.com/spring-sale', {
source: 'newsletter',
medium: 'email',
campaign: 'Spring Sale 2026',
content: 'hero button',
}));
// https://example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale_2026&utm_content=hero_buttonNotice the design choices:
- The function throws if a core parameter is missing. A link with only
utm_sourceis a common cause of messy reports, and failing early is cheaper than cleaning data later. - It uses
url.searchParams.set, not string concatenation. This encodes special characters correctly and replaces a parameter that already exists in the base URL, so you don't create a duplicate. - It normalizes values in one place, so every link built through it follows the same rules. A later chapter explains why the rules matter.
The function also accepts a utm_id value. That parameter is covered in a later chapter. You can ignore it for now.
Confirming the tag survived
A tag only helps if it is still in the URL when the page loads in the visitor's browser. After you click a tagged link, run this in the browser console on the landing page:
const params = new URLSearchParams(window.location.search);
const utm = Object.fromEntries(
[...params].filter(([key]) => key.startsWith('utm_'))
);
console.log(utm);
// { utm_source: 'newsletter', utm_medium: 'email', utm_campaign: 'spring_sale_2026', ... }If the object is empty, the parameters were lost before GA4 could read them. The usual causes are a redirect that drops the query string, a link shortener configured to strip parameters, or an email platform that rewrites links. Fix those before you check anything in GA4. A later chapter shows how to test with Realtime and DebugView.
When tagging is worth it, and when it is not
Tag links you control and place outside your own site. These are the common cases:
- Email newsletters and automated email sequences.
- Links in social posts you publish, including organic posts and bios.
- Partner, affiliate, and sponsorship links.
- QR codes on print or packaging.
- Links in PDFs, slide decks, and app messages.
- Paid ads on platforms that don't auto-tag, such as most non-Google ad networks.
Leave these untagged:
- Links between pages on your own site. A UTM tag on an internal link makes GA4 treat the click as a new campaign arrival, which overwrites the real source of the session. This is one of the most damaging tagging mistakes, and a later chapter returns to it.
- Organic search results. You can't tag a link you don't control, and GA4 already recognizes search engines from the referrer.
- Google Ads links when auto-tagging is on. Auto-tagging supplies richer data than UTM values, and a later chapter explains how the two interact.
Limits of tagging
UTM tags give you accurate labels, with some limits you should know from the start:
- GA4 reports what the tag says. It does not check that the tag is true. A link tagged
utm_medium=emailthat you actually post on social media will be reported as email. - Values are case-sensitive in GA4 reports, so
Emailandemailappear as different rows. - The tag is visible in the address bar. Visitors can copy and share the full URL, including your parameters, so a tagged link posted by a reader will credit the original campaign for visits it did not drive.
- Tags describe the click, not the person. They don't replace consent management. If a visitor declines analytics storage, your measurement may be reduced however well you tagged.
- A tag says where a session started. Credit for conversions that happen later depends on GA4's attribution settings, which are outside this chapter.
Summary of the working model
- Without tags, GA4 relies on the referrer, which is often missing, so much campaign traffic lands in Direct or generic referral rows.
- A UTM tag is a set of query-string parameters you add. It states the source, medium, and campaign of a visit regardless of the referrer.
- You choose the values, so you also own their quality. GA4 stores what it receives.
- Tag external links you control. Don't tag internal links.
- Check that parameters survive redirects before you trust the reports.
Exercise
Your team sends a monthly PDF report by email. The link inside the PDF currently points to https://example.com/report with no parameters, and clicks appear under (direct) / (none) in GA4. Give a tagged URL that would attribute these visits to a campaign named "monthly report" from the source "pdf_report" over the medium "email", and explain why the untagged version showed up as Direct.
Show answer
Tagged URL: https://example.com/report?utmsource=pdfreport&utmmedium=email&utmcampaign=monthly_report (values lowercase, spaces replaced by underscores). The untagged clicks showed as Direct because a link inside a PDF has no referring web page, so the browser sends no referrer and GA4 has nothing to infer the source from. The UTM parameters travel in the URL itself, so GA4 can read them even without a referrer.
Exercise
A colleague tags the link in the site's own top navigation with utmsource=website&utmmedium=nav&utm_campaign=menu so they can measure menu clicks. What goes wrong in the data, and what should they do instead?
Show answer
When a visitor who arrived from, say, organic search clicks that internal link, GA4 reads the UTM parameters as a new campaign arrival and replaces the session's original source with website / nav. The real source is lost, and the reports overcount "website" traffic. Internal link clicks should be measured with events (for example a click event with a descriptive parameter), not with UTM tags.