How to Fix Redundant Hostnames in Google Analytics

Cody Schneider8 min read

Seeing different versions of your domain in your Google Analytics reports - like yourdomain.com, www.yourdomain.com, and even dev.yourdomain.com - is a common snag that fragments your data and makes honest analysis nearly impossible. When Google Analytics sees these as separate websites, your traffic, conversions, and other key metrics get split, giving you a distorted view of your performance. This article will show you how to find these redundant hostnames and walk you through a few different methods to clean them up for good.

GraphedGraphed

Your AI Data Analyst to Create Live Dashboards

Connect your data sources and let AI build beautiful, real-time dashboards for you in seconds.

Watch Graphed demo video

Why Redundant Hostnames Are a Big Deal

At first glance, seeing a few different hostnames might seem like a minor formatting issue. But in reality, it fundamentally undermines the integrity of your data. Google Analytics uses the hostname to identify where a hit or an event came from. If you have multiple hostnames, GA treats each one as a distinct source. Imagine trying to calculate your store's total daily sales, but you have three separate cash registers, and each one prints its own report. You'd have to manually add them all together to see the full picture - and that's exactly what happens inside Google Analytics.

This data fragmentation leads to several problems:

  • Inaccurate Reporting: Your pageviews, sessions, and user counts get divided across the different hostnames. A report for yourdomain.com might show 5,000 sessions, while www.yourdomain.com shows another 3,000. Your actual total for that page is 8,000, but without combining them, you're making decisions based on incomplete data.
  • Broken User Journeys: If a user lands on www.yourdomain.com and then navigates to a page on yourdomain.com, Google Analytics might see this as one user leaving and a new user arriving from a referral. This inflates your session count, skews your time-on-site metrics, and makes it impossible to track a customer's true path to conversion.
  • Cluttered and Confusing Data: Beyond your primary domains, you might also find junk hostnames from development servers (like staging.yourdomain.com), translation services (translate.googleusercontent.com), or even plain old referral spam. This noise makes your reports harder to read and trust.

Cleaning this up isn't just a housekeeping task, it's essential for getting reliable insights you can confidently act on.

Free PDF Guide

AI for Data Analysis Crash Course

Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.

How to Find the Hostname Report in Google Analytics 4

Before you can fix the problem, you need to see what you're dealing with. In Google Analytics 4, the hostname report is a bit tucked away compared to its Universal Analytics predecessor. Here’s how to find it step-by-step:

  1. In the left-hand navigation, go to Reports.
  2. In the "Reports" menu, click on Tech, then select Tech details.
  3. By default, this report probably shows "Browser" as the primary dimension. Click the dropdown menu at the top of the report chart and select Hostname.

Now, you should see a list of every hostname that has sent data to your GA4 property, along with metrics like users, sessions, and engagement rate for each. Take a close look at this list. You will likely see a mix of valid hostnames you want to keep, redundant versions you want to consolidate, and junk traffic you want to get rid of entirely.

Identifying Your Valid Hostnames vs. Unwanted Ones

Your goal is to create one clear, consolidated source of truth. As you review your list, categorize each hostname:

  • Primary Hostnames (Keep & Consolidate): These are the main domains your site runs on. It's usually yourdomain.com and www.yourdomain.com. Your goal here is to make them report as one.
  • Valid Subdomains (Decide to Keep Separate or Consolidate): You might have legitimate subdomains like blog.yourdomain.com or shop.yourdomain.com. Depending on your business, you might want these to report as part of your main site or keep their data separate. The fixes below will let you choose.
  • Development Hostnames (Exclude): Traffic from hosts like dev.yourdomain.com, staging.yourdomain.com, or localhost should be completely filtered out. Developer testing activity has no place in your production data.
  • Third-Party Hostnames (Exclude): You might see entries from services like checkout.paypal.com, translate.googleusercontent.com, or other external services that are part of your user flow but aren't actually part of your website. These often dilute your data and are best excluded. Your payment gateway is not your website.
  • Spam Hostnames (Exclude): Ghostly entries from domains you don't recognize at all are referral spam and should be banished immediately.

Once you have your list, it's time to take action.

Solution 1: Consolidate www vs. non-www with 301 Redirects (The Best Way)

The single best way to fix the yourdomain.com vs. www.yourdomain.com issue is not within Google Analytics at all. It's on your web server. You should choose one version as your "canonical" domain (most people choose the non-www version) and set up a permanent 301 redirect to send all traffic from the other version to it. This means if anyone types www.yourdomain.com into their browser, your server automatically redirects them to yourdomain.com.

This is a fundamental SEO best practice that prevents duplicate content issues, and as a bonus, it cleans up your Google Analytics data permanently. All traffic will be funneled through the one true hostname before it is ever tracked. How you implement this depends on your hosting provider, but most offer simple tools in their C-panel or configuration settings to set this up.

GraphedGraphed

Your AI Data Analyst to Create Live Dashboards

Connect your data sources and let AI build beautiful, real-time dashboards for you in seconds.

Watch Graphed demo video

Solution 2: Create a Data Filter in GA4 to Exclude Unwanted Hosts

For hostnames you want to block entirely - like development servers or known spam - you can use GA4's Data Filters. These filters are applied as data is processed and can prevent unwanted traffic from ever appearing in your reports. This is perfect for filtering out your internal or developer traffic.

Here’s how to set it up:

  1. Click the Admin gear icon in the bottom-left corner.
  2. In the Property column, go to Data Settings > Data Filters.
  3. Click Create Filter.
  4. Choose the Traffic type filter. GA4 provides two built-in types: "Internal Traffic" and "Developer Traffic." Choose Developer Traffic.
  5. Under "Filter operation," select Exclude.
  6. Give your filter a name, like "Exclude Staging Server Hostname".
  7. In the filter details, use the following parameters:
  8. Finally, set the filter state to Active and save. Activating the filter applies it permanently going forward (it won’t change your historical data). You can create separate filters for each hostname you want to block.

Tip: For getting rid of spammy domains, a great place to start is the "List Unwanted Referrals" setting. To find it, go to Admin > Data Streams > [your web stream] > Configure tag settings > Show more > List unwanted referrals. Add spam domains here. This works slightly differently than the data filter by preventing sessions from being credited to those spam referrers, which helps clean up your traffic acquisition reports.

Solution 3: Force a Consistent Hostname with Google Tag Manager (Advanced)

If you can't set up 301 redirects, an effective alternative for consolidating www and non-www hostnames is to use Google Tag Manager (GTM). This method programmatically cleans the hostname before the data is sent to Google Analytics. It essentially tells GTM, "Hey, if you see www. at the beginning of a hostname, just chop it off before you send the pageview."

Free PDF Guide

AI for Data Analysis Crash Course

Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.

Step 1: Create a Custom JavaScript Variable in GTM

This variable will check the hostname and remove the 'www.' part if it exists.

  1. In GTM, go to Variables and click New under "User-Defined Variables."
  2. Name it something clear, like "JS - Cleaned Hostname".
  3. Choose Custom JavaScript as the variable type.
  4. Paste the following code into the code block:
function() {
  var hostname = window.location.hostname,
  if (hostname.startsWith('www.')) {
    return hostname.substring(4),
  }
  return hostname,
}
  1. Click Save.

Step 2: Update Your GA4 Configuration Tag

Now, you need to tell your main GA4 tag to use this new variable for the hostname instead of the default one.

  1. In GTM, go to Tags and open your primary Google Analytics: GA4 Configuration tag.
  2. Under Fields to Set, click Add Row.
  3. For the Field Name, enter hostname.
  4. For the Value, click the brick icon and select your newly created variable, {{JS - Cleaned Hostname}}.
  5. Click Save.

Remember to test your changes using GTM's Preview mode and then publish your container. From that point on, all hits sent to Google Analytics from your GTM tag will report a clean, non-www hostname, neatly consolidating your data.

Final Thoughts

Cleaning up redundant hostnames in Google Analytics transforms your reports from a cluttered mess into a reliable source of truth. By combining server-side redirects for your main domains and using GA4 filters and Google Tag Manager for the rest, you can ensure your data is accurate, consolidated, and ready to yield actionable insights about your website's performance.

Instead of manually finding and filtering data inside GA4 or setting up complex GTM rules, tools can help automate this entire process. At Graphed, we connect directly to your data sources like Google Analytics and automatically clean and unify the data behind the scenes. We're designed to handle messy data so you can get one clear, consolidated view of your entire business. That way, you're free to focus on asking questions and getting answers, not on data janitor duty.

Related Articles