Sub topic 9
Tagging links and attributing results
This chapter assumes you know the core metrics from the previous chapter (CTR, CPM, CPA, ROAS) and can read a URL. It covers how to label links so your analytics tool can tell organic traffic from paid traffic, and what "attribution" can and cannot tell you.
Why untagged links cause trouble
Social platforms show you their own numbers: clicks, reach, conversions they claim. Your website analytics tool (for example Google Analytics) shows what happened on your site. These two views rarely match, and without labels on your links, the analytics tool often lumps social visits together as "social" or, worse, as "direct" traffic.
A tag is a short piece of text added to the end of a URL. It tells your analytics tool where a visit came from. With consistent tags you can answer questions such as:
- Did the spring sale video bring more visitors as a paid ad or as an organic post?
- Which creative version led to more purchases?
- Is organic social worth the staff time compared with paid?
How UTM parameters work
UTM stands for Urchin Tracking Module. A UTM parameter is a key and value pair added after a ? in a URL. Several pairs are joined with &. When someone clicks the link, the analytics tool reads the pairs and stores them with that visit.
There are five standard parameters.
| Parameter | Meaning | Required | Example value |
|---|---|---|---|
| `utm_source` | The platform or site that sent the visit | Yes | `instagram` |
| `utm_medium` | The type of channel | Yes | `paid_social` or `organic_social` |
| `utm_campaign` | The campaign name | Yes | `spring_sale` |
| `utm_content` | Which creative or link variant | No | `video_a` |
| `utm_term` | A keyword, mostly used in search ads | No | `running_shoes` |
Here are two links to the same page. Only utm_medium differs.
https://example.com/spring-sale?utm_source=instagram&utm_medium=paid_social&utm_campaign=spring_sale&utm_content=video_a
https://example.com/spring-sale?utm_source=instagram&utm_medium=organic_social&utm_campaign=spring_sale&utm_content=video_aBecause source, campaign and content match, you can compare the same creative across the two channels. Because medium differs, you can split paid from organic. This is the main reason to tag organic links as well as paid ones.
Naming rules that keep data clean
Tags are plain text, so small differences create separate rows in your reports. Instagram, instagram and ig count as three different sources. Agree on rules and keep them in a shared document.
- Use lowercase only. Analytics tools treat
Spring_Saleandspring_saleas different values. - Use underscores or hyphens instead of spaces. Pick one and keep it.
- Fix a short list of allowed
utm_sourcevalues, one per platform. - Fix a short list of allowed
utm_mediumvalues, such asorganic_social,paid_social,influencerandemail. - Name campaigns after the plan in your content calendar so reports line up with planning.
- Use
utm_contentfor the creative name or number, so you can compare variants. - Never put personal data, such as an email address, in a tag. URLs are logged in many places.
A simple tracking sheet with one row per link, and columns for each parameter, is enough to start. Many teams add a formula that joins the columns into a final URL so nobody types a tag by hand.
Building tagged URLs in code
If you create many links, generate them. The function below builds a URL, lowercases the values, and replaces spaces with underscores. It also keeps any query string already on the page.
from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode
def tag_url(url, source, medium, campaign, content=None, term=None):
def clean(value):
return value.strip().lower().replace(" ", "_")
parts = urlsplit(url)
query = dict(parse_qsl(parts.query))
query["utm_source"] = clean(source)
query["utm_medium"] = clean(medium)
query["utm_campaign"] = clean(campaign)
if content:
query["utm_content"] = clean(content)
if term:
query["utm_term"] = clean(term)
return urlunsplit((parts.scheme, parts.netloc, parts.path,
urlencode(query), parts.fragment))
print(tag_url("https://example.com/spring-sale", "Instagram", "paid social",
"Spring Sale", "Video A"))
print(tag_url("https://example.com/spring-sale", "Instagram", "organic social",
"Spring Sale", "Video A"))The output is two links in the same pattern as the earlier example, with only utm_medium different.
Where tags go wrong
Most tracking problems come from a short list of mistakes.
- Tagging internal links. If you add UTM tags to links between pages on your own site, a new session starts and the original source is overwritten. Use tags only on links that bring people in from outside.
- Tagging links in a bio or a pinned post inconsistently. A bio link is clicked by organic visitors for months. Give it a stable tag such as
utm_medium=organic_socialandutm_campaign=bio_link, and update the campaign name only when the offer changes. - Relying on platform defaults. Some platforms add their own click identifiers. These help the platform match clicks to conversions, but they do not replace your own UTM tags. Check whether your ad platform offers automatic tagging and whether it conflicts with manual tags in your setup.
- Shared links without tags. When a visitor copies a tagged link and shares it, the tags travel with it. A friend's visit then looks like a paid visit. This inflates paid numbers slightly. It is hard to remove, so treat paid numbers as approximate.
- Redirects that drop parameters. Link shorteners and some redirects remove the query string. Test each type of link by clicking it and checking the final URL.
- Dark social. People share links in private messages and apps that do not pass referrer data. These visits show up as direct traffic. Tags on the link help only if the tagged link itself was shared.
What attribution means
Attribution is the rule for deciding which touchpoint gets credit for a conversion. A customer might see an organic post on Monday, click a paid ad on Wednesday, and buy after an email on Friday. Each of the three could claim the sale.
Common models:
| Model | Who gets credit | Typical effect |
|---|---|---|
| Last click | The final touchpoint before the conversion | Favors channels near purchase, such as search and email |
| First click | The first recorded touchpoint | Favors awareness channels |
| Linear | All touchpoints equally | Spreads credit, hides which step mattered |
| Position-based | More credit to first and last, less to the middle | A compromise between first and last click |
| Data-driven | Credit based on a statistical model of your own data | Needs enough conversions to be reliable |
Social often looks weak under last-click models because it tends to introduce people to a brand early. It also gives credit to the wrong place when someone sees an ad, does not click, and later searches for the brand. That visit is credited to search or direct.
Platform numbers versus analytics numbers
Ad platforms usually report conversions using an attribution window, a set number of days after a click or a view. A platform may count a purchase made one day after someone merely saw an ad ("view-through"). Your analytics tool, using UTM tags, counts only visits that arrived through a tagged click. So the platform number is usually higher.
Neither is wrong. They answer different questions. Use platform numbers to compare ads inside that platform. Use analytics numbers to compare channels against each other, with the same model applied to every channel.
Worked example
Suppose the spring sale ran for two weeks. Analytics, with last-click attribution, shows:
| Medium | Sessions | Orders | Revenue | Spend |
|---|---|---|---|---|
| `paid_social` | 4,000 | 40 | $2,000 | $800 |
| `organic_social` | 2,500 | 15 | $750 | $0 media, about $600 staff time |
Paid ROAS is 2,000 / 800 = 2.5. Organic revenue per session is $0.30, against $0.50 for paid. The paid link converts at 1.0% (40 / 4,000) and the organic link at 0.6% (15 / 2,500). With these numbers, you could say paid traffic converts better, but you should be careful. Organic posts reach people who already follow you, who may also have been warmed up by earlier ads. The ad platform may also report a higher count than the 40 orders shown here, because it counts view-through purchases. You can compute ratios from raw totals with the function from the metrics chapter.
def social_metrics(impressions, clicks, spend, conversions, revenue):
ctr = clicks / impressions if impressions else 0.0
cpm = spend / impressions * 1000 if impressions else 0.0
cpa = spend / conversions if conversions else None
roas = revenue / spend if spend else None
return {"ctr": ctr, "cpm": cpm, "cpa": cpa, "roas": roas}
print(social_metrics(impressions=50000, clicks=750, spend=400.0, conversions=20, revenue=1200.0))This prints a CTR of 0.015, a CPM of 8.0, a CPA of 20.0 and a ROAS of 3.0.
Going beyond last click
Tagging gives you a consistent record, but it cannot prove cause. Three practical ways to test whether a channel adds sales that would not have happened anyway:
- Holdout test. Hide ads from a random slice of your audience and compare their conversions with the group that saw them. The difference estimates the real lift.
- Geographic test. Run ads in some regions and not others, then compare sales.
- Survey. Add a "How did you hear about us?" question at checkout. It catches word of mouth and dark social that tags miss.
Use these occasionally, not for every campaign. They cost time or reach, but they check whether your tagged reports are telling the truth.
A tagging checklist
- Write the allowed values for source and medium and share them.
- Tag every external link you control, organic and paid.
- Use a different
utm_contentfor each creative variant. - Click each link before launch and confirm the tags appear in the landing page URL.
- Check the analytics real-time report to confirm the visit is recorded with the right source and medium.
- Choose one attribution model for cross-channel comparisons and write it down.
- Review reports monthly for stray values such as typos and capital letters.
Exercise
A team tags organic Instagram posts with utmsource=Instagram&utmmedium=social and paid Instagram ads with utmsource=instagram&utmmedium=paid_social. Name two problems this creates in reports, and give corrected tags for the organic posts.
Show answer
First, the capital "I" in "Instagram" makes analytics treat it as a different source from "instagram", so organic and paid visits split across two rows. Second, "social" is too vague as a medium; it does not separate organic from paid, and it may be grouped with other social traffic. Corrected tags: utmsource=instagram&utmmedium=organicsocial, plus a utmcampaign and, where useful, a utm_content value.
Exercise
Your ad platform reports 60 purchases from a campaign. Analytics, using tagged links and last click, shows 40 purchases from utmmedium=paidsocial. Give two reasons the numbers differ, and say which number you would use to compare paid social with email.
Show answer
The platform counts view-through conversions (people who saw but did not click) and uses its own attribution window, while analytics counts only tagged click visits and credits the last click. Some purchasers may also have clicked another channel last, such as search or email, so analytics credits them elsewhere. To compare paid social with email, use the analytics number, because the same attribution model is applied to both channels.