Sub topic 3
Building a Tagged URL Correctly
Assume you understand URL query strings, have a GA4 web data stream installed, and can open GA4 reports. A tagged URL is a normal page URL with campaign information added as query parameters. When a visitor follows the link, GA4 can use those values to identify where the visit came from and which campaign link they used.
Start with the three core parameters
For manually tagged links, use these parameters together:
| Parameter | Meaning | Example |
|---|---|---|
| `utm_source` | The platform or publisher that sent the visitor | `newsletter` |
| `utm_medium` | The marketing method or traffic type | `email` |
| `utm_campaign` | The promotion or campaign name | `spring_sale_2026` |
For example:
https://example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale_2026The question mark starts the query string. Each parameter has a name and value. An ampersand separates parameters.
Use utm_content when one campaign contains multiple links to the same destination. It can distinguish a hero button from a footer link:
https://example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale_2026&utm_content=hero_buttonUse utm_term when you need to identify a paid search keyword or another term associated with the link. Do not add optional parameters merely to fill space. Every value should answer a reporting question.
Build the URL in the right order
Start with the final landing page URL. Add the query string after the path, then add the UTM parameters.
A URL may already have query parameters. In that case, start the UTM section with &, not ?:
https://example.com/spring-sale?ref=partner&utm_source=partner_site&utm_medium=referral&utm_campaign=spring_sale_2026A URL fragment, such as #pricing, belongs at the end. UTM parameters must appear before the fragment:
https://example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale_2026#pricingA fragment usually controls a position or state in the browser. It is not sent to the server, so placing campaign parameters after it can prevent them from being read correctly.
For repeated work, generate URLs instead of editing them by hand. This JavaScript helper requires the three core parameters, normalizes their values, and lets URLSearchParams encode special characters:
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_buttonThis helper uses the URL’s existing query string safely. It also encodes characters that have a special meaning in URLs.
Check redirects and the final landing page
Campaign parameters must survive every redirect between the clicked link and the page where the GA4 tag runs. A shortened URL, tracking service, consent system, or HTTP-to-HTTPS redirect can remove or replace query parameters.
Trace the link in a browser and inspect the final address. You can also 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);You should see the expected values. If the final URL has no UTM parameters, fix the redirect or link before investigating GA4 reports.
Exercise
Write a tagged URL for https://shop.example.com/product for a social post promoting a winter sale. Use social, organic, winter_sale_2026, and instagram_post for the source, medium, campaign, and content values.
Show answer
https://shop.example.com/product?utm_source=social&utm_medium=organic&utm_campaign=winter_sale_2026&utm_content=instagram_post