How to Add a Subdomain to Google Analytics
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.
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 toyourcompany.comto 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.
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.
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.
- Log in to your Google Analytics account and go to the Admin section (the gear icon in the bottom left).
- Under the "Property" column, click on Data Streams.
- Select the web data stream connected to your website.
- Under "Google tag," click on Configure tag settings.
- On the next screen, under "Settings," click on Configure your domains.
- 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, andshop.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.
- 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.
- In your GA4 account, go to Reports > Realtime.
- 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:
- Navigate to Reports > Engagement > Pages and screens.
- By default, this report shows you page paths (e.g.,
/contact-us,/blog/new-post), but it doesn't separate them by subdomain. - Click the small plus sign (
+) next to the "Page path and screen class" primary dimension to add a secondary dimension. - 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.
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.
- Click on Explore in the left sidebar and start a new Free-form exploration.
- In the "Variables" column, click the + next to "Dimensions." Import Hostname and Page path and screen class.
- Click the + next to "Metrics." Import metrics like Sessions, Total users, and Views.
- Drag Hostname over to the "Rows" area in the "Tab Settings" column.
- 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-XXXXXXXXXXMeasurement 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!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.