Sub topic 9
How GA4 decides a session's referral source
This chapter explains how GA4 picks the source and medium for a session, and why a visitor returning from a payment page can end up labelled as a referral from that page. It assumes you can read GA4 reports, know that a session is a group of events from one visit, and have seen the Traffic acquisition report. You do not need to have configured anything yet. The next chapter uses what you learn here to set up the unwanted referrals list.
What GA4 stores for a session
Every session has a source and a medium. The Traffic acquisition report shows them as the dimensions Session source and Session medium. Examples are google / organic, newsletter / email, (direct) / (none) and paypal.com / referral.
GA4 does not store one attribution decision per session. It reads attribution signals from the events in the session. Almost all of the time, the first event with usable signals decides the session's source and medium.
The signals are:
- Campaign parameters in the page URL, such as
utm_source,utm_mediumandutm_campaign. - Click identifiers added by auto-tagging, such as
gclidfor Google Ads. - The
page_referrerparameter, which holds the URL of the page the visitor came from. It comes from the browser'sdocument.referrer.
If none of these signals is present, GA4 labels the session (direct) / (none).
The order of precedence
GA4 checks the signals in a fixed order and stops at the first one that applies.
- Campaign parameters and click IDs. If the landing URL carries UTM parameters or a recognized click ID, GA4 uses them. The referrer is ignored, even when it is a different site.
- The referrer. If there are no campaign signals and the referrer is a domain other than your own, GA4 uses the referrer's hostname as the source. Known search engines get the medium
organic. Known social networks and other recognized sources are classed by their own rules. Any other external domain gets the mediumreferral. - Nothing. If there is no referrer, or the referrer is your own site, the session is
(direct) / (none).
Two consequences follow from this order:
- A tagged link always beats the referrer. If your payment provider's return link carried a
utm_source, the session would show that value, and the unwanted referrals list would have no effect on it. (direct) / (none)is a fallback, not a measurement. It means GA4 found no signal. Missing referrers, such as HTTPS to HTTP transitions, some apps and privacy settings, all end up there.
Where the referrer comes from
The page_referrer parameter is sent with page_view and other events. The browser decides its content, and gtag.js does not change it. Referrer behavior has a few details that matter later:
- Browsers may trim the referrer to the origin only, for example
https://www.paypal.com/instead of the full path, depending on the sending site's referrer policy. - A site can suppress the referrer completely with
Referrer-Policy: no-referrer. The visit then looks direct. - On a single-page application, GA4 sets
page_referrerto the previous virtual page. It does not use a document referrer, so an incorrect setup can produce odd referrer values. Check this before blaming the source list.
You can see the raw value in DebugView. Open the page_view event and read the page_referrer parameter. This is the quickest way to confirm which domain GA4 saw.
Why a payment gateway creates a problem
Take a typical checkout. The visitor arrives from a Google search, browses, and clicks Pay. The browser leaves your site and opens the gateway's page. The visitor enters card details and is sent back to your confirmation page.
On the confirmation page, page_referrer is the gateway's domain, for example https://www.paypal.com/. Which attribution that gets depends on session continuity:
- If the visitor returns within the session timeout (30 minutes of inactivity by default), the return is usually part of the original session. The session keeps its first attribution of
google / organic. Thepurchaseevent still happens in that session. - If the visit to the gateway outlasts the timeout, or the visitor's session ended for another reason, the return starts a new session. That session has no campaign signals and an external referrer, so GA4 assigns
paypal.com / referral.
The second case is the problem. The purchase gets credited to paypal.com / referral and the real acquisition channel loses the revenue. You will see a referral source with an unusually high conversion rate and a very short time since the previous session. The same pattern appears with single sign-on pages, 3-D Secure bank pages and hosted booking engines.
A list of unwanted referrals tells GA4 to ignore those domains as referrers. The return then does not create a referral attribution. Attribution falls back to what the user had before, or to direct.
What counts as a referrer, and what does not
| Situation | Resulting session source and medium |
|---|---|
| Link from another website, no UTM | `that-site.com / referral` |
| Link from Google search results | `google / organic` |
| Link with `utm_source=news&utm_medium=email` from any page | `news / email` |
| Link from your own domain | Not a referral; the session continues or shows direct |
| Domain listed in cross-domain measurement | Ignored as a referrer; counted as part of your site |
| Domain on the unwanted referrals list | Ignored as a referrer |
| Page with `Referrer-Policy: no-referrer` | `(direct) / (none)` |
The cross-domain row is easy to confuse with the unwanted referrals list. Cross-domain measurement links your own sites into one user journey and passes a _gl parameter on links between them. The unwanted referrals list covers third-party sites you do not own and that do not carry the parameter. If a domain is yours, configure cross-domain measurement. If it is a vendor, use the unwanted referrals list.
Writing a pattern for a domain
The unwanted referrals list takes a domain and a match type. The typical choices are contains, equals, begins with, ends with and matches regular expression. Plain matches are easier to maintain. Use a regular expression only when one pattern replaces several entries.
This pattern matches paypal.com and any subdomain of it, such as www.paypal.com or checkout.paypal.com:
^(.+\.)?paypal\.com$Read it in three parts:
^and$anchor the match to the whole hostname. Without them,notpaypal.com.evil.examplewould also match.(.+\.)?is an optional group that allows any subdomain followed by a dot.paypal\.comhas an escaped dot, so it matches only a literal dot and not any character.
A "contains paypal" rule is simpler but broader. It also matches an unrelated site like paypal-fan-blog.example. For payment and login domains this is usually acceptable. For anything where an unrelated site might share the string, prefer an anchored pattern.
Ignoring the referrer in code
If you control a page and never want its referrer to count, you can tell the tag to drop it. The ignore_referrer parameter on the configuration call does this:
gtag('config', 'G-XXXXXXXXXX', {
'ignore_referrer': 'true'
});This applies to every visit that loads this page's tag, for any referrer, not for chosen domains only. On a dedicated landing page that you only reach from a payment provider, this is a blunt but dependable choice. On a normal landing page it hides real referral traffic. For most sites the unwanted referrals list is the safer tool, because it names the exact domains.
Worked example: reading a suspicious report
You open Reports, then Acquisition, then Traffic acquisition, and set the primary dimension to Session source / medium. You see:
| Session source / medium | Sessions | Purchases |
|---|---|---|
| `google / organic` | 8,400 | 120 |
| `(direct) / (none)` | 3,100 | 45 |
| `checkout.stripe.com / referral` | 410 | 96 |
The third row has few sessions and almost one purchase for every four. Real referral traffic does not convert like this. The pattern points to a payment domain that starts new sessions on return. The steps to confirm it are:
- Open DebugView on a test purchase and read
page_referreron the confirmation page'spage_view. - In the Explore workspace, compare the landing page for the
stripe.comsessions. If it is always the thank-you page, the diagnosis holds. - Add
stripe.comto the unwanted referrals list.
The change is not retroactive. Old sessions keep their wrong attribution. New sessions after the change should not show checkout.stripe.com / referral, and the purchases should move to the original channel or to direct.
Common errors
- Adding the domain and expecting history to change. Tag settings apply only to data collected afterward. Plan to annotate the date in your reports.
- Adding your own domain to the unwanted referrals list. Your own site is already not a referral. If you see self-referrals from your own domain, the cause is more often a missing cross-domain setup or a subdomain that runs a different tag.
- Forgetting subdomains. An equals rule for
paypal.comdoes not matchwww.paypal.com. Check what the hostname really is in DebugView. - Expecting UTM links to be filtered. A tagged return link overrides everything. Remove the UTM parameters from return URLs your own code builds.
- Raising the session timeout to hide the problem. A longer timeout reduces the number of split sessions but changes session counts everywhere. Fix the referrer instead.
Exercise
A visitor lands from a Google search, clicks Pay, spends 40 minutes on a bank page, and returns to your site. Your property uses the default session timeout and has no unwanted referrals list. What source and medium does the returning session most likely show, and what single setting change would prevent it?
Show answer
The 40 minutes exceed the 30-minute default timeout, so the return starts a new session with no campaign parameters and an external referrer. GA4 therefore labels it with the bank's hostname as the source and referral as the medium. Adding the bank's domain to the unwanted referrals list in the web stream's tag settings stops GA4 from using that domain as a referrer for sessions collected afterward.
Exercise
Your payment provider's return link is https://example.com/thanks?utm_source=pay&utm_medium=gateway. You add the provider's domain to the unwanted referrals list. Why do the purchases still appear under pay / gateway?
Show answer
Campaign parameters take precedence over the referrer. GA4 reads the utm_source and utm_medium values first and never evaluates the referrer, so the unwanted referrals list does not apply. Removing the UTM parameters from the return URL is the fix.