Sub topic 2
How GA4 records source, medium, and channel
This chapter assumes you can navigate GA4 reports, know what a referrer and a UTM parameter are, and have at least Editor access to a property. It explains how GA4 turns a visit into three labels: source, medium, and default channel group. Later chapters depend on these labels, because AI assistant visits are often mislabeled when the rules are not understood.
The three labels
GA4 describes where a session came from with three related values.
- Source is the origin of the visit, such as
google,newsletter, orchatgpt.com. - Medium is the category of the origin, such as
organic,cpc,email, orreferral. - Default channel group is a bucket such as Organic Search, Referral, or Direct. GA4 assigns it from rules that read the source and medium.
Source and medium are raw labels. The channel is a derived summary. When a visit lands in the wrong channel, the cause is usually in the source or medium, or in the rule order.
Where the values come from
GA4 does not look at a cookie that says "this visitor came from ChatGPT". It reads two things that arrive with the first events of a session.
- Campaign parameters in the page URL. These are
utm_source,utm_medium,utm_campaign,utm_term,utm_content, plusgclidfor Google Ads auto-tagging. They arrive inside thepage_locationevent parameter. - The referrer. This is the page the browser reports as the previous page, taken from
document.referrer. It arrives in thepage_referrerevent parameter.
GA4 applies them in a fixed order of precedence:
- Campaign parameters in the URL, when present. They override the referrer.
- The referrer, when no campaign parameters exist. A recognized search engine gives source = the engine and medium =
organic. Any other external host gives source = the hostname and medium =referral. - Neither signal. The session is
(direct) / (none).
Example signals and results
| Landing URL | Referrer | Source / medium |
|---|---|---|
| `/guide` | `https://www.google.com/` | `google / organic` |
| `/guide` | `https://www.perplexity.ai/` | `perplexity.ai / referral` |
| `/guide?utm_source=chatgpt.com` | `https://chatgpt.com/` | `chatgpt.com / (not set)` |
| `/guide?utm_source=newsletter&utm_medium=email` | none | `newsletter / email` |
| `/guide` | none | `(direct) / (none)` |
The third row matters for AI traffic. Some assistants append utm_source to the links they output. When utm_source is present without utm_medium, the medium becomes (not set). The UTM wins over the referrer, so the visit is no longer a clean referral. Check this against your own data in a later chapter instead of assuming it.
Session scope and why it matters
GA4 stores traffic labels at several scopes, and reports mix them.
| Dimension | Scope | Meaning |
|---|---|---|
| Session source, Session medium, Session source / medium | Session | Where this session came from |
| Session default channel group | Session | Channel of this session |
| First user source, First user medium | User | Where the user was first acquired |
| Source, Medium (traffic acquisition reports) | Session-based in those reports | Same as the session dimensions |
Use session-scoped dimensions to ask "which sessions came from an AI assistant?". Use first-user dimensions to ask "which people did we first meet through an AI assistant?". A returning visitor who was first acquired through ChatGPT but who comes back by typing your address will be counted as (direct) in session dimensions and as ChatGPT in first-user dimensions. Mixing the scopes in one table produces numbers that look inconsistent but are correct.
A session keeps its first label
GA4 sets the source and medium once, from the first event of the session that carries traffic information. Later events in the same session do not change it. A new campaign parameter in the middle of a session does not start a new session, which differs from Universal Analytics. A session ends after 30 minutes of inactivity by default (the timeout is configurable in the data stream settings), and the next visit is evaluated from scratch.
How the default channel group is assigned
The default channel group is a list of rules, evaluated from top to bottom. The first matching rule wins. If no rule matches, the session is Unassigned. The rules that matter most here are:
| Channel | Simplified condition | Column | Column |
|---|---|---|---|
| Direct | Source exactly matches `(direct)` and medium is `(none)` or `(not set)` | ||
| Organic Search | Source is a known search site, or medium is `organic` | ||
| Organic Social | Source is a known social site, or medium is one of `social`, `social-network`, `social-media`, `sm`, `social network`, `social media` | ||
| Referral | Medium matches `^(referral | app | link)$` |
| Email, Display, Paid Search, and others | Medium matches specific values such as `email` or `cpc` | ||
| Unassigned | None of the above matched |
Some details have consequences for AI traffic:
- The rules read both source and medium. A session with source
chatgpt.comand medium(not set)does not match Referral, because Referral needs a medium ofreferral,app, orlink. Unless another rule matches, it lands in Unassigned. - A session with source
perplexity.aiand mediumreferrallands in Referral. A hostname that GA4 classifies as a social or search source can land in Organic Social or Organic Search instead, whatever you expect. - The default rules are fixed and cannot be edited. To change the result, you create a custom channel group, which is covered in a later chapter.
Referral exclusions
GA4 has a List unwanted referrals setting under Data stream > Configure tag settings. A referrer whose domain matches the list is ignored as a source, so the session does not get that referrer. It is used for payment gateways and your own subdomains so a checkout redirect does not replace the real source.
Do not add AI assistant domains to this list. Doing so would turn those visits into Direct instead of preserving the label. The list is for sources you want to discard.
A model you can run
The function below reproduces the decision order described above for the cases in this chapter. It is a teaching model, not Google's implementation. It ignores gclid, most of the search and social lists, and many other rules.
from urllib.parse import urlparse, parse_qs
SEARCH_HOSTS = {"google.com", "www.google.com", "bing.com", "www.bing.com"}
def classify(landing_url, referrer):
query = parse_qs(urlparse(landing_url).query)
if "utm_source" in query:
source = query["utm_source"][0]
medium = query.get("utm_medium", ["(not set)"])[0]
elif referrer:
host = urlparse(referrer).hostname or ""
source = host.removeprefix("www.") if host.startswith("www.perplexity") else host
medium = "organic" if host in SEARCH_HOSTS else "referral"
else:
source, medium = "(direct)", "(none)"
if source == "(direct)" and medium in ("(none)", "(not set)"):
channel = "Direct"
elif medium == "organic":
channel = "Organic Search"
elif medium == "email":
channel = "Email"
elif medium in ("referral", "app", "link"):
channel = "Referral"
else:
channel = "Unassigned"
return source, medium, channel
cases = [
("https://example.com/guide", "https://www.google.com/"),
("https://example.com/guide", "https://www.perplexity.ai/"),
("https://example.com/guide?utm_source=chatgpt.com", "https://chatgpt.com/"),
("https://example.com/guide", ""),
]
for landing, ref in cases:
print(classify(landing, ref))Running it prints:
('google.com', 'organic', 'Organic Search')
('perplexity.ai', 'referral', 'Referral')
('chatgpt.com', '(not set)', 'Unassigned')
('(direct)', '(none)', 'Direct')The first line shows google.com where GA4 would show google. GA4 normalizes known search engines to short names, and this model does not. Use it only to see the order of the checks.
Seeing the labels in your own property
Open Reports > Acquisition > Traffic acquisition. Change the primary dimension to Session source / medium to see the raw labels, then back to Session default channel group to see the buckets. Compare them. Any row that appears in one view in a way you did not expect points to a rule or a signal worth investigating.
For one specific visit, use Admin > DebugView with a test device. Select the session_start or page_view event and read page_location and page_referrer. These two parameters are the inputs described above. If a visit looks wrong in the reports, they explain why.
Common errors
- Reading channel as truth. The channel is derived. If
chatgpt.comappears under Unassigned, the data is not lost. The source and medium are present, and the channel rules did not match. - Mixing scopes. Comparing first-user source counts against session source counts gives different totals by design.
- Expecting a referrer on every click. Apps, privacy settings, and some link types remove the referrer. Those sessions become Direct. The next chapters treat this in detail.
- Treating UTM as optional. A UTM parameter overrides the referrer. Whatever it contains, including a missing medium, is what GA4 records.
- Excluding the sources you want to measure. The unwanted-referrals list removes sources from attribution.
Exercise
A visitor clicks a link in an AI assistant. The landing URL is https://example.com/pricing?utm_source=chatgpt.com, and the browser reports the referrer https://chatgpt.com/. What are the session source, medium, and default channel group, and why is the channel not Referral?
Show answer
Source is chatgpt.com, because the UTM parameter takes precedence over the referrer. Medium is (not set), because no utm_medium was supplied. The default Referral rule requires the medium to match referral, app, or link, so it does not match. No other rule matches either, so the session is Unassigned.
Exercise
A returning user was first acquired through a Perplexity link. Today they type your address into the browser and start a new session. In a report using Session source / medium and another using First user source / medium, what does each show for this session's user?
Show answer
The session report shows (direct) / (none) for today's session, because there is no referrer and no UTM. The first-user report shows perplexity.ai / referral, because first-user dimensions keep the source from the user's first session.
Exercise
Why should you not add chatgpt.com to the unwanted referrals list if you want to measure ChatGPT visits?
Show answer
The list tells GA4 to ignore matching referrers as a traffic source. Visits from chatgpt.com would then have no usable source and would be recorded as Direct, which hides the AI traffic you want to measure.