Sub topic 11
Tagging links and attributing results to channels
This chapter assumes you know the three funnel stages, the owned, earned, and paid channel types, and the stage metrics from earlier chapters. It also assumes you have used a web analytics tool such as Google Analytics and can read short Python. The chapter covers how to label each link so analytics can tell channels apart, and how credit for a conversion gets divided among the channels involved.
Why tagging matters
Your analytics tool sees a visit only as a request to a page. It can often read the referrer, which is the site the visitor came from. It cannot tell which email, which ad, or which campaign the visitor clicked. Tagging fixes this by adding labels to the link itself.
Without tags, results land in vague buckets. Visits from a newsletter may show up as "direct". Visits from a paid social ad may show up as "social" with no campaign attached. You then cannot compare the metrics you defined for each stage, such as reach for awareness or conversion rate for conversion, by channel.
The UTM parameters
UTM parameters are the standard tags. They are query-string fields that start with utm_. Analytics tools read them when the visitor lands and store them with the session.
| Parameter | Answers the question | Example value |
|---|---|---|
| `utm_source` | Where did the click come from? | `newsletter`, `linkedin` |
| `utm_medium` | What kind of channel is it? | `email`, `cpc`, `social` |
| `utm_campaign` | Which campaign is it part of? | `spring_launch` |
| `utm_content` | Which variant or placement? | `hero_button`, `video_a` |
| `utm_term` | Which keyword (paid search)? | `crm_software` |
The first three are the ones to always set. The last two are optional and useful for A/B tests and keyword reporting.
A fully tagged link looks like this:
https://example.com/pricing?utm_source=newsletter&utm_medium=email&utm_campaign=spring_launchThe page is /pricing. The tags say the visit came from the newsletter, through the email medium, as part of the spring launch campaign.
Tags should carry the funnel stage
The three standard fields do not record the funnel stage. You have two common options:
- Put the stage in the campaign name, for example
spring_launch_awarenessandspring_launch_conversion. - Keep a lookup table outside analytics that maps each source and medium pair to a stage, and join it when you report.
The campaign-name approach is easier to read in any tool. The lookup table keeps names shorter and lets you reclassify a channel later. Pick one and write it down.
Naming conventions
Analytics tools treat tag values as plain text and compare them exactly. Email, email, and e-mail become three separate rows in your reports. Agree on a convention before the first link goes out:
- Use lowercase only.
- Use underscores instead of spaces.
- Use a fixed list of mediums (
email,cpc,social,display,referral), not free text. - Use one pattern for campaigns, such as
<name>_<stage>or<year>_<name>_<stage>. - Keep the list in a shared sheet, and change it only deliberately.
Building tags in code
Generating links in code removes typos. This function adds the tags, lowercases the values, and keeps any query parameters the URL already has.
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
def tag_url(url, source, medium, campaign, content=None, term=None):
parts = urlsplit(url)
query = dict(parse_qsl(parts.query))
tags = {
"utm_source": source,
"utm_medium": medium,
"utm_campaign": campaign,
"utm_content": content,
"utm_term": term,
}
for key, value in tags.items():
if value:
query[key] = value.strip().lower().replace(" ", "_")
return urlunsplit(
(parts.scheme, parts.netloc, parts.path, urlencode(query), parts.fragment)
)
print(tag_url("https://example.com/pricing", "Newsletter", "email", "spring launch"))The call prints https://example.com/pricing?utm_source=newsletter&utm_medium=email&utm_campaign=spring_launch. The input had a capital letter and a space, and the output has neither.
How a tag travels to a report
The tag is only recorded on the visit. A purchase that happens on a later visit is linked back to the earlier visits through a cookie or a login. That link is the weak point, and the failure modes below explain why.
Where tagging goes wrong
- Tagging internal links. If a banner on your own site points to another page with UTM tags, analytics starts a new session and overwrites the original source. A visitor who arrived from a paid ad then appears to have come from your banner. Tag only links that enter your site from outside.
- Inconsistent values. Mixed case and spelling variants split one channel across several rows.
- Untagged channels. Some links cannot be tagged by you. Examples are organic social shares, links in PDFs that people forward, and some messaging apps. This traffic appears as "direct", which is often called dark social.
- Auto-tagging conflicts. Ad platforms can add their own click identifiers. If you also add manual UTM tags, the two can disagree. Check your analytics tool's rule for which one wins, and use one method per platform.
- Lost parameters. Redirects, link shorteners, and some form flows drop the query string. Test a link by clicking it and checking the final URL.
- Blocked or expired tracking. Browsers that limit cookies, and visitors who decline consent, shorten or remove the history that connects visits.
- Personal data in tags. Never put an email address or a name in a tag. The URL is stored in logs and may be shared.
From tags to attribution
Attribution is the rule that decides which channels get credit for a conversion. Tags tell you who touched the person. The attribution model tells you how to divide the credit among those touches.
| Model | How it assigns credit | Tends to favor |
|---|---|---|
| First touch | All credit to the first channel | Awareness channels |
| Last touch | All credit to the final channel before converting | Conversion channels |
| Linear | Equal credit to every touch | A balanced view, but ignores order |
| Position-based | More credit to the first and last touches, less to the middle | Both ends of the journey |
This choice connects to the stage metrics. Under last touch, branded search and retargeting look excellent, because they sit next to the purchase. Awareness channels such as video and paid social look weak, even when they started the journey. If you budget from last-touch reports alone, you will cut the channels that fill the top of the funnel.
A small attribution calculator
This function divides one conversion across an ordered list of touches under three models.
def attribute(touches, model):
n = len(touches)
if n == 0:
return {}
if model == "first":
weights = [1.0] + [0.0] * (n - 1)
elif model == "last":
weights = [0.0] * (n - 1) + [1.0]
elif model == "linear":
weights = [1.0 / n] * n
else:
raise ValueError(f"unknown model: {model}")
credit = {}
for channel, weight in zip(touches, weights):
credit[channel] = credit.get(channel, 0.0) + weight
return credit
journey = ["paid_social", "email", "branded_search"]
for model in ("first", "last", "linear"):
result = attribute(journey, model)
print(model, {k: round(v, 2) for k, v in result.items()})For this journey, first gives all credit to paid_social, last gives it all to branded_search, and linear gives each channel 0.33. Email, the consideration channel, gets credit only under linear.
You can reuse the cost per acquisition idea from earlier chapters here. Divide a channel's spend by its attributed conversions. The same spend produces a different CPA under each model, so say which model a CPA was computed with.
Edge cases to plan for
- Cross-device journeys. A person may click an ad on a phone and buy on a laptop. Without a login to link the two, the laptop visit shows up as direct.
- Long cycles. If your sales cycle is 60 days and your tracking window is 30, early touches are dropped. Match the window to the real buying time.
- Offline conversions. Phone orders and in-store sales have no UTM tags. A common fix is to ask "how did you hear about us?" or to import sales records into analytics with a click identifier.
- Self-reported source. What people say and what tags show often differ. Treat the gap as information. Dark social and word of mouth tend to show up only in the self-reported answers.
A checklist before launch
- Does every external link in the campaign carry
utm_source,utm_medium, andutm_campaign? - Are all values lowercase and from the agreed list?
- Does the campaign name or a lookup table show the funnel stage?
- Did you click each link and confirm the tags survive to the final page?
- Do you know which attribution model the report uses?
Exercises
Exercise
A banner on your homepage links to /pricing with utmsource=homepage&utmmedium=banner. Many of your visitors reached the homepage from paid search. What goes wrong in your reports, and what should you do?
Show answer
The tagged internal link starts a new session and replaces the original source, so conversions that began with paid search are credited to "homepage / banner". Remove the UTM tags from the internal link. If you want to measure banner clicks, use an event or an internal-promotion feature in the analytics tool instead.
Exercise
Using the attribute function with the journey ["display_ads", "webinar", "email", "retargeting"], what credit does the webinar receive under first, last, and linear attribution?
Show answer
First: 0, because only display_ads gets credit. Last: 0, because only retargeting gets credit. Linear: 0.25, because each of the four touches receives 1/4 of the conversion.
Exercise
Your last-touch report shows that retargeting has the lowest CPA and paid social the highest. A colleague suggests moving all of the paid social budget to retargeting. Give two reasons to be careful.
Show answer
First, retargeting can only reach people who already visited, and paid social may be what brought them. Cutting it shrinks the pool that retargeting depends on. Second, last touch gives all the credit to the final channel, so it undervalues awareness work. Compare against first-touch or linear views, and test the change on a small budget before shifting everything.