Categorizing Referring Domain Data in GA4 Using Google Tag Manager
Google Analytics (GA4) provides useful traffic source reporting, but referring domain data can quickly become messy. The same platform may appear in multiple forms such as linkedin.com, www.linkedin.com, or lnkd.in. Google referrals may appear as google.com, mail.google.com, or docs.google.com.
When these variations are not cleaned up, referral reporting becomes fragmented. Instead of clearly seeing which platforms drive traffic, analytics reports fill up with dozens or even hundreds of inconsistent domains.
This article explains how to categorize referring domain traffic in GA4 using Google Tag Manager. The approach normalizes messy referrer values and assigns them to clear traffic categories such as social platforms, search engines, internal traffic, AI tools, or spam domains.
The result is much cleaner referral reporting and a much easier way to analyze where your traffic actually comes from.

The Problem With Referring Domain Data in GA4
Referring domains represent the website that sent a visitor to your website. In theory this sounds simple, but in practice the data can become messy very quickly.
One platform may appear under multiple domain variations. Mobile apps, redirect services, and shortened links can all generate slightly different referrer values. The result is fragmented reporting that makes it harder to compare traffic sources over time.
For example, LinkedIn traffic may appear under several variations.
linkedin.com
www.linkedin.com
lnkd.in
Each variation appears as a separate referrer in GA4, even though they all represent the same platform.
The same issue appears across many other platforms including Google, Pinterest, Medium, and social networks.
Normalization and Categorization Explained
This solution uses two related steps.
First, referring domains are normalized. This means multiple domain variations are cleaned into a single consistent value.
Second, those normalized values are categorized into meaningful traffic groups.
The workflow looks like this.
Raw referrer
→ Normalized domain
→ Traffic category
For example.
lnkd.in
→ linkedin
→ social
mail.google.com
→ google
→ search
marketingwithdave.com
→ internal
→ internal
startraffic.online
→ spam
→ spam
This process dramatically simplifies referral reporting.

Why Categorizing Referrers Is Valuable
GA4 already identifies traffic channels such as Organic Search, Social, and Referral. However, those channels do not always show which specific platform generated the visit.
Categorized referring domains allow you to see traffic at a much more meaningful level.
Instead of only seeing social traffic, you can more clearly separate traffic from platforms such as LinkedIn, Instagram, Pinterest, or X.
This is especially helpful if you promote content across multiple platforms and want to measure which ones actually drive visits.
It also allows you to quickly separate legitimate traffic from spam referrals or internal visits.
Categories Worth Tracking
A good first implementation should classify several common types of traffic.
Search engines such as Google, Bing, DuckDuckGo, and others.
Social platforms such as LinkedIn, Instagram, Pinterest, TikTok, Medium, Reddit, and X.
AI tools such as ChatGPT, Claude, and Perplexity. These platforms are increasingly appearing in referral data as AI assistants begin linking directly to websites.
Internal traffic coming from your own domain.
Spam domains that generate junk referrals.
Any domain not yet reviewed should fall into a category called not-classified. This makes it easier to identify domains that need to be reviewed later.
When This Approach Is Especially Useful
This setup is particularly helpful if you publish content regularly across multiple platforms.
It is also valuable if you want to identify AI-generated traffic, remove spam domains from reports, or clearly separate internal traffic from real visitors.
If you build dashboards in Looker Studio or export traffic data to spreadsheets, normalized referrer categories make analysis much easier.
Creating the Referrer Normalization Variable in GTM
The normalization logic is implemented using a Custom JavaScript variable in Google Tag Manager.
Create a new variable using the Custom JavaScript variable type and paste the following script.
function() {
var ref = document.referrer;
if (!ref) return 'direct';
var host = '';
try {
host = new URL(ref).hostname.toLowerCase();
} catch (e) {
return 'not-classified';
}
host = host.replace(/^www\./, '');
if (host.indexOf('marketingwithdave.com') > -1) return 'internal';
if (host.indexOf('google.') > -1) return 'google';
if (host.indexOf('bing.com') > -1) return 'bing';
if (host.indexOf('duckduckgo.com') > -1) return 'duckduckgo';
if (host.indexOf('linkedin.com') > -1 || host.indexOf('lnkd.in') > -1) return 'linkedin';
if (host.indexOf('facebook.com') > -1) return 'facebook';
if (host.indexOf('instagram.com') > -1) return 'instagram';
if (host.indexOf('pinterest.com') > -1 || host.indexOf('pin.it') > -1) return 'pinterest';
if (host.indexOf('tiktok.com') > -1) return 'tiktok';
if (host.indexOf('medium.com') > -1) return 'medium';
if (host === 't.co' || host.indexOf('twitter.com') > -1 || host === 'x.com') return 'x-twitter';
if (host.indexOf('chatgpt.com') > -1 || host.indexOf('chat.openai.com') > -1) return 'chatgpt';
if (host.indexOf('claude.ai') > -1) return 'claude';
if (host.indexOf('perplexity.ai') > -1) return 'perplexity';
if (host.indexOf('startraffic.online') > -1) return 'spam';
return 'not-classified';
}
Name the variable something descriptive such as JS – Referrer Normalized.
Adding the Variable to Your GA4 Tag
Open your GA4 Google Tag or page_view tag in Google Tag Manager.
Add a configuration parameter with the following values.
Parameter name: referrer_normalized
Value: {{JS – Referrer Normalized}}
This sends the normalized value to GA4 with each page view.
Test the implementation in GTM Preview mode before publishing.
Creating the GA4 Custom Dimension
After publishing the GTM changes, create a custom dimension in GA4.
Use the following settings.
Dimension name: Referrer Normalized
Scope: Event
Event parameter: referrer_normalized
This allows the normalized value to appear in GA4 reports and explorations.
Important GA4 Limitation
GA4 custom dimensions are not retroactive. Historical referral data will not be reprocessed.
The categorized values will only appear for traffic collected after the implementation goes live.
Expanding the Classification Over Time
Your first version does not need to classify every possible domain.
Start with the platforms you already know are important. Over time, review domains that appear under not-classified and add additional rules as needed.
This gradual approach allows the classification system to evolve alongside your traffic patterns.
Visualizing the Workflow
A simple diagram can help illustrate the process.
Raw Referrer
→ Normalized Domain
→ Traffic Category
This visual representation works well as a blog image and helps readers quickly understand how the transformation occurs.
Final Thoughts
Referring domain data in GA4 often becomes fragmented and difficult to analyze. Normalizing and categorizing referrer values provides a simple way to transform messy domain data into clear traffic insights.
With a small amount of logic in Google Tag Manager, referral traffic can be organized into meaningful categories that are much easier to analyze in GA4 dashboards and reports.
If you regularly share content across multiple platforms or want to better understand where your visitors originate, categorizing referring domain traffic is one of the most useful analytics improvements you can implement.
Categorizing Referring Domain Data in GA4 Using Google Tag Manager Read More »










