Sub topic 3
Referrers and UTM Parameters as Attribution Signals
This chapter covers the two signals GA4 uses to decide where a visit came from: the HTTP referrer and UTM parameters. It explains how each is produced, which one wins when both are present, and what that means for visits from AI assistants such as ChatGPT, Gemini, Perplexity, Copilot, and Claude.
Prerequisites assumed: you can navigate GA4 standard reports, you know that a referrer is the page a visitor came from, and you know that a UTM parameter is a tag added to a URL. You do not need to write code to follow the main ideas. The later code samples need basic JavaScript.
Two signals, two different origins
GA4 does not know where a visitor came from by magic. It reads clues sent with each visit. For AI traffic, two clues matter most.
| Signal | Who sets it | Where it lives | Reliability |
|---|---|---|---|
| Referrer | The visitor's browser | `Referer` HTTP header and `document.referrer` | Depends on the browser, the app, and the referring site's policy |
| UTM parameters | Whoever builds the link | The URL query string | Reliable when present, but present only if someone added them |
The difference matters. A referrer is automatic but fragile. UTM parameters are deliberate but rare. AI assistants sometimes provide one, sometimes both, and sometimes neither.
The referrer
When a user clicks a link, the browser can tell the destination site which page the click came from. This value is the referrer. On your page you can read it with document.referrer. GA4 captures it as the page_referrer event parameter on events such as page_view.
The referrer you see is controlled by the referring site's Referrer-Policy. Common values:
no-referrer: nothing is sent.origin: only the scheme and host are sent, for examplehttps://chatgpt.com/.strict-origin-when-cross-origin: the browser default in modern browsers. Cross-site links get only the origin, and only when the link does not downgrade from HTTPS to HTTP.
For AI tracking, this means you will usually see the assistant's host name but not the conversation URL or the prompt. That is a good thing for privacy, and it limits what you can learn.
The referrer is also a hostname, not a product name. One assistant can use several hosts. ChatGPT has appeared as chatgpt.com and chat.openai.com. Perplexity may appear as perplexity.ai or www.perplexity.ai. Always check which hosts appear in your own data instead of assuming a list.
UTM parameters
UTM parameters are query-string tags that tell analytics tools about a campaign. GA4 recognises these:
| Parameter | Maps to GA4 dimension | Example |
|---|---|---|
| `utm_source` | Session source | `chatgpt.com` |
| `utm_medium` | Session medium | `referral` |
| `utm_campaign` | Session campaign | `spring_launch` |
| `utm_term` | Session manual term | `running shoes` |
| `utm_content` | Session manual ad content | `hero_link` |
A full URL looks like this:
https://example.com/guide?utm_source=chatgpt.com&utm_medium=referralSome AI assistants append utm_source to the links they output. Behaviour differs by product and changes over time, so treat any statement about a specific assistant as something to verify in your data, not as a fixed fact. Check your own reports for utm_source values before you build rules on them.
You can also add UTMs yourself. If you publish a link to your content inside a prompt template, a custom GPT, or a plugin description, you control the tags. That is the only case where you can guarantee a clean label.
Which signal wins
GA4 assigns source and medium at the session level. When a session starts, it checks signals in a rough order of priority:
- Click identifiers such as
gclid(Google Ads auto-tagging). - Manual UTM parameters on the landing page URL.
- The referrer, which GA4 matches against its known lists of search engines, social networks, and shopping sites.
- If nothing is found, the session is
(direct) / (none).
The result is that UTM parameters override the referrer. If a visitor arrives from chatgpt.com with utm_source=newsletter&utm_medium=email, GA4 records newsletter / email, not chatgpt.com / referral.
This is a simplification. GA4 has more rules, including how it treats a session that starts with no signal when an earlier session had one. The model above is enough for diagnosing AI traffic.
What an AI visit looks like in GA4
Here are the four patterns you will meet. The first two are easy to count. The last two are the hard ones, covered further in a later chapter.
| Pattern | Source / medium in GA4 | Cause |
|---|---|---|
| Referrer only | `chatgpt.com / referral` | Browser sent the host, no UTM |
| UTM added by assistant | `chatgpt.com / (not set)` or another medium | Assistant appended `utm_source` without a medium, or with a different one |
| Referrer stripped | `(direct) / (none)` | App or policy removed the referrer, no UTM |
| Different host than expected | `copilot.microsoft.com / referral` or a regional domain | Assistant uses multiple hostnames |
The second pattern is worth a note. If a link has utm_source but no utm_medium, GA4 may show a medium of (not set). Because the default channel group rules often depend on medium, such sessions can land in Unassigned. A rule that only checks for medium referral will miss them. This is why a custom channel group should match on source, not medium alone.
Reading the signals in your own data
You can see both signals without any code. In GA4, open Reports > Acquisition > Traffic acquisition. Change the primary dimension to Session source / medium and search for terms such as chatgpt, gemini, perplexity, copilot, claude, and openai. Note every variation you find.
To see the raw referrer, you need event-level data. Two options exist:
- Explorations: build a free-form exploration with
Page referreras a dimension. This requires registeringpage_referrerif it is not already available.page_referreris collected automatically, but custom dimension registration may be needed for some report surfaces. - BigQuery export: read
page_referrerfromevent_params, which a later chapter covers.
Comparing session source with page referrer is a useful check. If session source is (direct) but the page referrer on the first page view is an AI host, GA4 and the browser disagree, which often points to a redirect or a tagging problem on your site.
Capturing the referrer yourself
Because session attribution can hide the real referrer, you can add a second signal under your control. The snippet below reads document.referrer and sends a custom event if the host is a known assistant.
const AI_HOSTS = {
'chatgpt.com': 'ChatGPT',
'chat.openai.com': 'ChatGPT',
'gemini.google.com': 'Gemini',
'perplexity.ai': 'Perplexity',
'www.perplexity.ai': 'Perplexity',
'copilot.microsoft.com': 'Copilot',
'claude.ai': 'Claude'
};
let host = '';
try {
host = new URL(document.referrer).hostname;
} catch (e) {}
const assistant = AI_HOSTS[host];
if (assistant) {
gtag('event', 'ai_assistant_visit', { assistant_name: assistant });
}Points to note about this code:
new URL('')throws an error, so thetry/catchhandles direct visits where the referrer is empty.- The match is on the exact hostname. A new subdomain will not match until you add it.
- It runs on every page load, not once per session. A visitor who reloads the page, or who navigates internally with a referrer that stays the same, can trigger the event repeatedly. Add a session check, such as
sessionStorage, if you want one event per visit. - The
gtagfunction must already be defined on the page, which it is if the GA4 tag is installed with the standard snippet.
Tagging with a custom event is the subject of a later chapter. Here it serves to show that the referrer is available to you as data.
Common errors
- Trusting the default channel group. GA4's default groups do not include an AI channel. AI sessions land in Referral, Direct, Unassigned, or occasionally Organic Search or Organic Social depending on source lists.
- Matching one hostname. Hostnames change. Review your source list at least quarterly.
- Ignoring case and
www.GA4 source values are lower-case, but thewww.prefix varies. Use a regex such as.*(perplexity\.ai).*rather than an exact match. - Tagging internal links with UTMs. If your own pages carry UTM links to each other, a new campaign overwrites the true source and starts a new session. Never use UTMs on internal links.
- Expecting an exact count. Some visits have no referrer and no UTM. They cannot be identified from these two signals.
When you control the link
If you can place a link yourself, add UTMs. This is the only way to be sure an AI-related visit is labelled. Use consistent, lower-case values:
https://example.com/guide?utm_source=chatgpt&utm_medium=ai_assistant&utm_campaign=custom_gptKeep the naming consistent across links. ChatGPT, chatgpt, and chatgpt.com count as three separate sources in GA4 reports. Choose one spelling, document it, and apply it everywhere.
Summary
The browser supplies the referrer. Link authors supply UTM parameters. GA4 uses UTM parameters first, the referrer second, and records (direct) / (none) when it finds neither. AI assistants may provide either signal, both, or neither, and the hostnames and tagging behaviour can change. The practical consequences are to inspect the real values in your own data, match on source rather than medium alone, and accept that some AI visits cannot be identified from these signals.
Exercise
A visitor clicks a link in an AI assistant. The landing URL is https://example.com/page?utm_source=newsletter&utm_medium=email, and document.referrer is https://chatgpt.com/. What source and medium does GA4 record for the session, and why? What would you do to still detect the AI origin?
Show answer
GA4 records newsletter / email, because manual UTM parameters take priority over the referrer. The referrer is still available as page_referrer on the event, so you can detect the AI origin with a custom event that reads document.referrer and sends something like ai_assistant_visit, or by querying page_referrer in the BigQuery export.
Exercise
Your custom channel rule says "Medium exactly matches referral AND Source matches regex chatgpt". You notice sessions from ChatGPT with source chatgpt.com and medium (not set) in Traffic acquisition. Why are they missed, and how should the rule change?
Show answer
The sessions have no medium referral, so the first condition fails and they fall to Unassigned. Change the rule to match on Source alone with a regex such as .*(chatgpt\.com|chat\.openai\.com).*, and remove the medium condition.