How to Add a Subdomain to Google Analytics

Cody Schneider8 min read

Tracking traffic across your main website and a subdomain - like from yourblog.com to shop.yourblog.com - can feel like trying to solve a puzzle. The good news is that with Google Analytics 4, this process is far more straightforward than it used to be. This guide will walk you through exactly how to set up and verify subdomain tracking in GA4, ensuring you get a complete picture of your user's journey.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Why Proper Subdomain Tracking in Google Analytics is a Must-Have

Before jumping into the setup, it's worth understanding why this matters. When a user moves from your main domain to a subdomain (or vice versa), Google Analytics can mistakenly see this as two separate visits from two different users. This fractures the data and creates several big problems:

  • Inaccurate User Counts: A single person visiting your blog and then your main site might be counted as two unique users, inflating your audience metrics.
  • Broken Session Data: The user's session ends on the first domain and a new one starts on the second. You completely lose the ability to see the natural path they took across your digital properties.
  • Poor Attribution: If a user clicks an ad that sends them to blog.yourcompany.com, and then they navigate to yourcompany.com to sign up, the original ad campaign might not get the proper credit for the conversion. It will likely be credited to "(direct)" traffic, making your marketing campaigns look less effective than they truly are.

Properly configuring subdomain tracking solves this. It stitches the journey together, treating a visit across blog.yourcompany.com and yourcompany.com as a single, continuous session from one user. This gives you a clear, holistic view of user behavior from their first touchpoint to their final conversion.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Subdomain Tracking in GA4: The Automatic Approach

If you're familiar with the old Universal Analytics, you might remember needing to adjust tracking codes and set up complex referral exclusion lists. Thankfully, GA4 simplifies this immensely.

The core principle of subdomain tracking in GA4 revolves around one simple concept: using the exact same Measurement ID and GA4 tag across all of your subdomains and your primary domain.

Your GA4 Measurement ID is the unique identifier that looks like G-XXXXXXXXXX. When the same tag containing this ID is present on every page of your main domain and all related subdomains, GA4 automatically handles cookie management to recognize the same user as they navigate between them. The technical term for this feature is "automatic cross-domain measurement," and while the name is a bit misleading (as domains and subdomains are different), this is the elegant feature that makes it all work seamlessly.

How to Verify Your Subdomain Tracking is Working Correctly

While GA4 is designed to handle this automatically, you still need to verify that your setup is correct. Here's how to confirm everything is configured properly.

Step 1: Check Your GA4 Tag Installation

First, confirm that the exact same Google Analytics tracking tag is installed on every page of your main site (e.g., yourcompany.com) and your subdomain (e.g., blog.yourcompany.com). You can do this in a couple of ways:

  • Right-Click "View Page Source": Open your website and a subdomain page, right-click, and select "View Page Source." Use Ctrl+F (or Cmd+F on Mac) to search for your Measurement ID (G-XXXXXXXXXX). It should be present in the code on both pages.
  • Use Google Tag Assistant: The Tag Assistant extension for Chrome is a surefire way to verify your tags. Navigate to your site and the subdomain, enable the extension, and confirm that the same GA4 Measurement ID is detected and firing correctly on both.

Whether you've installed the code directly, via Google Tag Manager (GTM), or through a website builder like Shopify or WordPress, the key is consistency. Using one GTM container for your entire web presence is often the easiest and most scalable way to manage this.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 2: Review Your Data Stream Settings

This is the most critical step and where the magic happens in GA4. You need to tell Google Analytics which domains belong together.

  1. Log in to your Google Analytics account and go to the Admin section (the gear icon in the bottom left).
  2. Under the "Property" column, click on Data Streams.
  3. Select the web data stream connected to your website.
  4. Under "Google tag," click on Configure tag settings.
  5. On the next screen, under "Settings," click on Configure your domains.
  6. Here, you'll see a list for your domain configurations. You don't need to add every single subdomain. You only need to add your root domain. For instance, if you have yourcompany.com, blog.yourcompany.com, and shop.yourcompany.com, just add a condition where "Domain contains" yourcompany.com.

By listing your root domain here, you're telling GA4 that any user navigating between any subdomain under that parent domain should be treated as part of the same journey. Click "Save" when you're done.

Step 3: Test and Monitor with Realtime Reports

The easiest way to see if your work paid off is to use the Realtime report.

  1. In a new browser window (or even better, a Chrome Incognito window), open two tabs. Navigate to a page on your main domain in the first tab and a page on your subdomain in the second.
  2. In your GA4 account, go to Reports > Realtime.
  3. Watch the "Users by page title and screen name" card. You should see your activity appear within a minute or two. As you click around on both your main domain and subdomain pages, you should see the report update to show your interactions on both properties, all under your single user session.

If you see your pageviews from both yourcompany.com and blog.yourcompany.com appearing in the same report, your cross-subdomain tracking is working correctly!

Separating Main Domain vs. Subdomain Traffic in Your Reports

Once everything is consolidated, you'll naturally want to analyze the performance of your subdomain separately from your main domain. For instance, you might want to see how many users landed on the blog versus the main homepage.

Using the "Hostname" Dimension

The key to splitting up this data is the Hostname dimension. The hostname is simply the domain or subdomain a user was on when they viewed a page.

Here’s a quick way to see this in a standard report:

  1. Navigate to Reports > Engagement > Pages and screens.
  2. By default, this report shows you page paths (e.g., /contact-us, /blog/new-post), but it doesn't separate them by subdomain.
  3. Click the small plus sign (+) next to the "Page path and screen class" primary dimension to add a secondary dimension.
  4. Search for and select Hostname.

The report will now update to show a second column, clearly listing whether the pageview occurred on yourcompany.com, blog.yourcompany.com, or any other subdomain you're tracking. This simple trick lets you instantly splice your traffic and analyze performance at a more granular level right from the standard reports.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Creating a Custom Report in "Explorations"

For more flexible analysis, the Explore section in GA4 is your best friend. You can quickly build a custom report showing traffic by hostname.

  1. Click on Explore in the left sidebar and start a new Free-form exploration.
  2. In the "Variables" column, click the + next to "Dimensions." Import Hostname and Page path and screen class.
  3. Click the + next to "Metrics." Import metrics like Sessions, Total users, and Views.
  4. Drag Hostname over to the "Rows" area in the "Tab Settings" column.
  5. Drag your metrics (like Sessions) over to the "Values" area.

Just like that, you've created a clean table showing a performance summary for each of your subdomains and your main domain. You can add the "Page path" dimension to the rows as well to drill down even further.

Common Issues and Pitfalls with Subdomain Tracking

If things aren't working as expected, check these common trouble spots:

  • Different Measurement IDs: This is the number one mistake. You absolutely must use the identical G-XXXXXXXXXX Measurement ID across your main domain and all subdomains. A different ID means a different dataset.
  • Incorrect "Configure your domains" settings: A simple typo here can break everything. Double-check that you've correctly entered your root domain without any spelling errors or extra characters.
  • Cookie Consent Banners: If your cookie consent tool is configured differently on your main vs. subdomain, it might prevent the GA4 cookie from being set properly, breaking the tracking linkage between them.
  • Caching Delays: If you recently made changes, website caching (or your browser's cache) might be serving an old version of the page. Clear your cache and try again.

Final Thoughts

Properly setting up subdomain tracking in Google Analytics 4 is one of the most effective ways to get a true, unified view of your customer journey. By ensuring you're using a single Measurement ID and correctly configuring your domain settings, you eliminate data silos and pave the way for much smarter, more accurate analysis.

Of course, Google Analytics is just one part of your data stack. True insights come from connecting GA data with information from your ad platforms, CRM, and storefronts like Shopify. For that, a modern approach is needed. Here at Graphed, we make this simple by connecting all your tools effortlessly. Instead of juggling a dozen tabs, you can just ask questions in plain English - like "Show me which blog posts lead to the most Shopify sales?" - and instantly get a real-time dashboard visualizing the answer. It’s all about turning scattered data points into a clear, actionable story without the manual drudgery.

Related Articles

How to Enable Data Analysis in Excel

Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!