Last updated on December 2nd, 2014

Tracking multiple subdomains in Google Analytics is a little tricky since there is no “easy” button to push. You will need to configure analytics properly to track and display data correctly.

In this guide you will learn how to install Google Analytics to properly track subdomains and configure Google Analytics to best display the subdomain data. This guide helps you configure Google Analytics to view all of your subdomain data in one place.

Things to Remember

This is advanced Google Analytics configuration. If you would like to hire me to help, please contact me for more info. It’s not too late, you can email me and have me do it for you instead of spending days trying to do it yourself.

Install Google Analytics for Multiple Subdomains

The first step in setting up Google Analytics to track multiple subdomains is to install the correct code.

If you are using Universal Analytics then your code is already correct. If you are setting up analytics for the first time then Google will give you the correct code.

If you are not using Universal Analytics; then simply go to Admin -> Property -> Tracking Info and make sure ‘Subdomains of [yoursite]’ is set to On. This will add the following code: _gaq.push([‘_setDomainName’, ‘yoursite.com’]);

You can also manually add the code to your analytics code if you are comfortable doing so.

Note: the code is the same for all of your subdomains. There is no need to adjust it for each subdomain.

Once you install this code on all of your subdomains Google Analytics will begin reporting data from each one. You have more work to do to best display and view this data. Keep reading.

Display Subdomains In Your Analytics Data (Optional, recommended)

In the previous section you set Google Analytics up to track multiple subdomains; this section we will work on displaying the data properly.

By default Google Analytics does not show the domain or subdomain in your data. This poses a problem when tracking multiple subdomains because you will not be able to tell the difference between subdomains in the data.

If you have pages that have the same path on any two subdomains, you will not be able to tell the difference between them in the data. This includes the home page which will only display a forward slash.

For example, if you have two pages like this: www.yoursite.com/contact-us and subdomain.yoursite.com/contact-us they will both appear as /contact-us in your data.

We need to create a filter that will display the subdomain in our data.

Note: this filter will conflict with destination goals. If you are using destination goals, you will need to make sure the destination is exactly the same as the page in the page list (Behavior -> Site Content -> All Pages)

There are two different ways to do this filter

It is important to remember that filters in Google Analytics do not alter historical data. This will be important to consider when choosing which filter to enter.

The filter that you should enter will depend on how you want to handle your historical data.

If you want to show the full path for all of your subdomains moving forward (including www or whatever your “main” domain is) follow the filter below.

google analytics show domain name filter

If you want to only show the full path for a specific subdomain (this option may be more friendly with your historical data) then do the exact same filter above EXCEPT for the Hostname field enter (subdomain.yoursite.com) with the parenthesis.

After applying one of these filters you will be able to differentiate traffic between subdomains.

Set Up Views For Each Subdomain (Optional, recommended)

Quick note on views. A view is what Google Analytics uses to refer to profiles of data. You can create unique views that will allow you to manipulate the data in different ways for that view without effecting other views.

To best organize your data I recommend creating a view for each subdomain and then another view that collectively allows you to display the data for all of the subdomains.

If you have been following along closely so far; we have already created a view that collects data on all of the subdomains and configured Google Analytics to display our subdomain data. Let’s create a view for each subdomain by going to Admin -> Views -> Create New View.

Once you have created each view, we need to apply filters to make sure each view is only collecting data on their assigned subdomain.

To apply a filter that ensures that we track only traffic for the view’s designated subdomain, go to Admin -> Views -> Filters -> New Filter and refer to the screenshot below.

Google Analytics Filter Include Only Traffic to Hostname

Applying this filter to your profile will ensure that this profile only tracks traffic for the specified subdomain. In this case, www.yoursite.com. Remember, www is a subdomain itself. Repeat this filter for each profile that you created where you need to isolate a subdomain.

Wrap Up

In this guide we learned:

1) Common pitfalls and things to remember (probably a good idea to review the “Some Things to Remember” section)

2) How to install Google Analytics properly for tracking subdomains.

3) How to display our subdomains in our data.

4) How to create views for each subdomain to individually display their data.

Need a hand?

I can take a look at your website, sundomains, and analytics and help you configure it correctly for a one time fee. Please contact me for more info.

Share this:





FreshBooks

84 Responses to Guide To Tracking Multiple Subdomains In Google Analytics

  1. Stef says:

    What if you have more than 100 sub domains. Is there a way to view data per domain without creating a profile for each unique domain?

    • Eric says:

      Perhaps the best way would be to apply the filter to your Google Analytics account that I describe above that will allow you to view the subdomain in your page list. Then you can use the search function in Google Analytics to isolate the subdomain you want to view.

      Note: a Google Analytics account cannot have more than 50 Views.

  2. Kelsey says:

    I am using a single GA account to track one domain and several subdomains but I haven’t updated my GA code to include this: _gaq.push([‘_setDomainName’, ‘yoursite.com’]);

    By not including this code snippet, what effects would this have on your data?

    • Eric says:

      The default configuration is to track a single domain. That line of code tells Google Analytics to share cookie information between subdomains.

      If you do not implement that line of code, your own site could appear as a referrer if a user accesses more than one subdomain in one visit.

  3. Hranush says:

    I have implemented the set up as described and also the filter set up. Should I create the filter for each sub domain or just one config applies for all the sub domains? Analytics gives the option to implement the filter on the sites. So should i use this option for further configuration?

  4. Poulpator says:

    Hi,

    I have more than 200 subdomain.
    And a need to know each unique visitor per subdomain.
    Is there a way to view data per domain without creating a profile for each unique domain?

    Regards from French Alps

    • Eric says:

      Do you have Google Analytics installed on these subdomains?

      If yes, the best advice I can give you is to apply the filter that I mentioned in the post for displaying subdomains in your main profile. If you apply that filter then you can at least see the subdomains in your main Google Analytics profile.

  5. Karen Nenon says:

    Hi- In your post you say “Do not create a new Google Analytics account for each subdomain.” Can you address creating a new web property and contrast that to using profiles instead? Many of the GA reference sites show examples of web properties being used for things like blog.example.com or m.example.com. We implemented two web properties for primary and m. and are finding out that maybe we cannot get a total data view of the primary domain and the subdomain. Maybe this is the main advantage of doing the one “account/web property” and profile technique instead? Is this correct?
    Thanks,
    Karen

    • Eric says:

      Hi Karen,
      I think you answered your own question.

      If you have the subdomains separated out into their own account then you have no easy way to get an over view of the entire site with all subdomains. Maybe you want to be able to view your blog.website.com, m.website.com, and http://www.website.com all at once. In this scenario you have to piece information together from the various accounts.

      That is why I recommend creating one GA account and then creating a new profile for each subdomain while keeping one “master” profile that has data for every subdomain.

      Hope that helps.

      Eric

  6. Elaine Xu says:

    Hey Eric, Great post! Thank you so much!!

    I’ve a question – might seem extremely dumb.
    When you say add this line to the tracking code,
    _gaq.push([‘_setDomainName’, ‘yoursite.com’]);”

    do i add this to both the main domain, or only to the tracking code for the subdomain?

    Thanks in advance for the answer!
    -elaine

    • Eric says:

      You add that to your tracking code in all your subdomains and main domain. Keep it at ‘yoursite.com’ for across all. Hope that helps!

  7. Nate says:

    I’ve set up my two sites (http://www.natecarrier.com and http://blog.natecarrier.com) with a single Google Analytics account as the post describes. I noticed later, though, that in order to view the organic search queries of search engine traffic, you need to link the GA web property to your Webmaster Tools site (see http://googlewebmastercentral.blogspot.com/2011/02/linking-google-analytics-to-webmaster.html). From what I’ve found (and my own attempts), you can only link the GA web property to one Webmaster Tools site. This means that I can link my GA account to my www site on Webmaster Tools, but not to my blog site. Without being able to link both, I can only see organic search queries that led to my www site, but not my blog site. That’s unfortunate.

    Are there any solutions or workarounds to this problem? All I can think of is toggling the association back and forth whenever I want to view reports of search queries for one or the other. It doesn’t look like the association can be made at the profile level, only the property level.

    • Nate says:

      Looks like I was mistaken. The organic search report is populated regardless of whether you have set up Webmaster Tools (and therefore works for both subdomains). However, the reports under Search Engine Optimization do require Webmaster Tools, as far as I can tell, you can only see reports for the subdomain you’ve chosen to associate.

  8. Kyle Akerman says:

    I have to track a website that has ~1000 subdomains.

    Can I put the same code on each page and then use your filtering tips?

    I’m afraid I will run into issue with the limits on accounts and profiles, etc.

  9. Great guide! So when I got this setup for my multiple subdomains, and want to define conversion goals based on target addresses. Normally for http://www.mysite.com/thanks.html I would enter just /thanks.html, but how do I enter the target page when multiple subdomains? There might actually be TWO pages with /thanks.html (one on each domain).

  10. Nick says:

    Thanks for this informative post Eric!

    I followed your instructions but have a couple of issues I am hopeful you can help me with (or others who read your blog)

    First, some context:
    * three profiles: (mydomain.com, sub1.mydomain.com, sub2.mydomain.com) .
    * default profile (mydomain.com) has the filter “Show Hostname” set as per your instructions.

    Question #1 – I can view both hostname for each of the three domains in the “realtime” view for the profile “mydomain.com”, but I do not see the hostname when I view the “realtime” view the other profiles (sub1… and sub2…). Can you suggest why?

    Question #2 – As I mentioned above I can view the realtime reports for each profile, but I cannot see the “standard reports” for each profile which is all of my historical records, other than the default profile (mydomain.com). Can you suggest how I enable this?

    Again, my thanks for your insightful post.

    Regards, Nick

    • 1) Are you sure you set up the hostname filter correctly for sub1 and sub2? If you have 3 profiles, remember that you must set the hostname filter in each profile. Is this problem just in the realtime view? Or does the filter appear to be working correctly otherwise? Maybe a better question is, do you need the filter for these profiles? Theoretically you wouldn’t need to see the hostname in sub1 and sub2 if you set up the profile correctly.

      2) If I understand your question correctly, one thing to keep in mind is that when you create a new profile or create a new filter, it only takes effect from that moment forward. Unfortunately Google Analytics does not port over your old data when you create a new profile and it does not adjust your historical data when you create a new filter. Perhaps this is a point I should make in my main post.

      I hope that answers your questions. Thanks for commenting!

      • Nick says:

        Thanks Eric for your response.

        1) The domain, and subdomains appear in the realtime view only, not the Standard reports (e.g. Standard Reports > Content). Each profile has been setup with the same filter to view host name (Hostname (.*), RequestURL (.*), and RequestURL ($A1$B1). When I view the individual subdomain’s profile you are right I do not need to see the hostname, but when I view the primary host’s domain where I want to see the totals across all sites it would be handy see this in the Content reports.

        2) This answers my question – I had hoped to see the historical reports with the added hostname.

        Again, my thanks,

        Nick

  11. Piyush says:

    What is use of $A1$B1 here ???

  12. Muskie says:

    I’ve got it mostly working. My original and only profile before was http://www.muschamp.ca, I deleted a filter that was on that profile and then created a profile just to include www. traffic. I created the filters and profiles for all the other subdomains and then a new master profile but I kept my original http://www.muschamp.ca profile.

    The problem I’ve noticed after letting people hit against my website for a couple hours is the original http://www.muschamp.ca profile still contains traffic from blog.muschamp.ca etc. I thought it was old data so I switched to just showing today’s data and let several hours past but it still seems to be showing everything.

    Every other profile that I created following the article seems to be performing as expected. Should I delete my original http://www.muschamp.ca profile and create a new http://www.muschamp.ca profile or will this eventually go away?

    Thanks again for posting this technique, it is a good way to deal with multiple subdomains.

    • The thing to remember is that the filters do not effect data that was created prior to entering the filter. When you create a filter it only effects data from that moment forward. So your old data will still show normally while new data takes the filter into account.

      • Muskie says:

        Giving it another day then only looking at today’s traffic seems to have done the trick. Thanks again.

      • Muskie says:

        Took a look at my analytics today and it looks good, but what about Webmaster Tools? Now that I have multiple profiles is there a good way to associate each subdomain that I’ve claimed in Webmaster tools with the profiles I’ve created in Google Analytics.

        It seems Google analytics expects me to have only one Webmaster tool verified domain. I’ve uploaded the file to each subdomain and made Webmaster Tools happy but the keyword suggestions seem odd both for “All traffic” and for other profiles…

        • Muskie says:

          It doesn’t seem possible to get webmaster tools to share keyword display data for subdomains using this technique. The All Traffic profile gets data and then for the subdomains they seem to get the same data as the All Traffic ie the default profile.

          • It is not surprising that Google Webmaster Tools would have trouble with this. You may need to create a new site in Google Webmaster Tools and verify each subdomain independently (one Webmaster Tools account for www and another for blog). I’m not entirely sure that would fix the problem, I doubt GA and Webmaster Tools communicate this stuff well to each other.

  13. Catherine A says:

    This is a fantastic post! Quick question, however – we are on the new Universal Analytics that Google recently rolled out. There is no section in Settings where you can find Tracking Code -> One domain with multiple subdomains. Does this post solely apply to Google’s Classic Analytics product? Again, thank you so much for your fantastic post!

    • I’m not really sure Catherine, I’m afraid I do not have any experience with the new Universal Analytics.

      • Just a Developer says:

        First of all, thank you for exactly what I was looking for.

        Secondly, this was the exact scenario I found myself in. Having several hundred sub-domains and using the new Universal Analytics.

        Just to clarify, no changes are needed to the Google provided .js snippet.

        Your solution got me 90% where I wanted to be.

        My tip/modification

        Field A: (.*).yourdomain.com
        Field B: (.*)
        Constructor: \[$A1\]$B1

        This outputs something a bit more useful for myself (and saves a lot of characters by omitting the domain (which is always the same).

        The new URI output:
        [subdomain]/the/destination/path

        Again, thank you!

    • Cindy says:

      Hey there,

      I’m trying to set this up too, but I just noticed this message when you get the tracking code: “This tracking code can be used on example.com or any sample.com sub-domain…”

      I guess there’s no need to change or add anything now. I just hope that the profiles instruction is still the same.

  14. kurt says:

    When implementing this…..it may be obvious, but which analytics code snippet do we use on the subdomain? The one specifically the “main” profile, or the code from the subdomain profile?

    So, for the main profile, the setAccount reads like this.

    _gaq.push([‘_setAccount’, ‘UA-xxxxxxx-1′]);

    on the subdomain, it reads

    _gaq.push([‘_setAccount’, ‘UA-xxxxxxx-12′]);

    • The analytics code should be the same for both the main domain and sub domain. In the example you posted, that is two separate GA “properties” (one level higher than “profiles”)

  15. Karl says:

    Hi!

    What if I would like to separate one of my subdomains into a dedicated profile. If I use a new GA code I will lose my previous data. Can I pull out a sub-domain w/o losing previous data? Is there a way to import/ recover the old data?

    Thanks in advance!

    Karl

  16. Anthony says:

    In each of the profile settings you can configure the Website’s URL, do I use the main URL for each profile or do I use the sub domain address for the mobile one? Does it matter?

  17. Tried implementing this. It affected real time analytics tracking (where nothing appears on real time data even though people were visiting our pages) which in the process affected our traffic reports too. Had to remove the filters. :(

  18. Muskie says:

    I discovered a new quirk of this technique. In my “All Traffic” I created a goal, a destination goal. It says don’t use the entire path, just use /filename.html so I did that. I could never achieve the goal. Then I went to my www. profile created the goal and voila it said 17% of my viewers in the last 7 days had complete my hypothetical new goal.

    I don’t know if this applies to all goals, but apparently to destination goals the fancy filter profile affects your ability to create destination goals.

    Cheers,

  19. Alex says:

    I applied your recommendation to our account a few months back and I’m happy to say that everything looks good so far.

    However, I noticed that when I look in the Master profile with subdomain traffic under Site Content, I see pages listed twice with and without the www prefix.

    i.e.

    http://www.example.com/page1
    example.com/page1

    Do you have any suggestions on how I can reconcile theses pages? And are the pageviews being double counted to these pages?

    Thanks,

    Alex

    • My guess is that you can literally visit either version of those pages. Typically, it is recommended that you redirect the non-www version of the site to www. So, a user shouldn’t be able to visit both www and non-www.

  20. April Holle says:

    Eric,

    It would be really helpful if you could include a screenshot of what it looks like once you’ve applied the filter for the subdomain details on the main account.

    Just a suggestion to help out others like myself who aren’t familiar what “what you get” when everything is set up correctly.

    Thanks for the great helpful article!

  21. Pik says:

    Hi, I have some troubles with the “Set Up Profiles For Each Subdomain” step. The main domain is being tracked well. I am adding a subdomain.
    I have already put the new tracking code to both main domain and subdomain.

    When you say to create a new profile for all the subdomains you mean a real profile or a new entity? Please see here: http://imageshack.us/a/img6/849/emno.png

    If you need a real profile, so I have to create it here: http://imageshack.us/a/img17/5200/nm6e.png

    I have the main domain (all web site data) and 1 subdomain. Does it mean that I have to just add 1 profile? Or two profiles?

    • If I were you, I would create 3 profiles. 1 for the main domain, 1 for the sub domain, and 1 that combines them. You could easily get by with only 1 profile that collects data on both of them if you wanted to, just make sure to do the ‘display subdomains’ filter.

  22. Todd says:

    Great post Erik.
    Question for you. How would you set up cross domain goals and funnels when GA only allows you to define the path when defining a goal?

    Please let me know if this does not make sense.

    Thank you in advance.

    • You can input the exact string that you see in Behavior -> Site Content -> All Pages. So if your page was /something/something.html before the filter, and after the filter it is subdomain.domain.com/something/something.html then you would use subdomain.domain.com/something/something.html for the goal.

  23. ravey says:

    Hi, I did this exercise and it works great. (I’m building my subdomain now so it’s not tracking yet) So I have only two domains I’m tracking http://www.soccertalk.us and ALL (which incorporates www. and the subdomain I’m creating) I’m only tracking the www. and ALL right NOW. But, I noticed that the numbers from www. and ALL don’t show the same numbers even though my subdomain shop.soccertalk.us isn’t created yet. I would assume the www. and ALL would be showing the same unique visitors? There is a pretty large discrepancy. Please advise if you don’t mind:) Thank you.

  24. Johnny says:

    Hi Eric,

    Thank you for the helpful explanations. I have a question, I’ve been able to set-up cross domain tracking successful but now have a problem excluding a domain in one of my filters.

    The entry goes something like this: (www\.|^)domain\.com

    The problem is that I wanted to exclude only the “domain.com” and I’ve realized it’s also excluded my Brazilian domain “domain.com.br”.

    How can I edit my entry to so that it only excludes the “.com” version and not the “.com.br” version?

    Thank you!
    Johnny

  25. Kacey says:

    Hi Eric,

    I have a set up like you describe. One profile is rolling up the main domain plus the two subdomains and I have separate profiles for the two subdomains. My question is I also want a profile that excludes the subdomains so that I have a view of only the main domain. Is this possible and if so how?

    thanks for your time.

  26. René says:

    Thank you for this guide, I found it very helpful.

    I have a domain with 2 subdomains, and I set it up as you described. But I later started to wonder if it’s necessary to create the individual views for each subdomain. Couldn’t you just use Custom Segments on the main View, that filters on the hostname? What is the benefit of creating a separate View for each subdomain, compared to creating Custom Segments?

    Best regards
    René

  27. Thanks for writing and sharing this! One thing to update perhaps: Google has changed their language from “profile” to “view”. So you’re not creating a new “profile” but a “view”. About view filters

  28. PHNX Boards says:

    Hey, I’m tracking my main domain (www.phnxboards.com) and it’s store subdomain (store.phnxboards.com) and I created a filter according to your instructions so I can see the full path. My problem is now I see the http://www.phnxboards.com/ in front of every page, even though it is the home page and it should just appear in Google Analytics as /. I want all pages off the main domain (for example, http://www.phnxboards.com/about) to appear as /about, and all pages on on the store (for example store.phnxboards.com/collections/all) to appear with the subdomain so I can tell when people are on the store. I’ve been researching how to do this for hours and am stumped and confused. Any help would be much appreciated! Thanks, PHNX Boards.

  29. Hannes says:

    Hi,

    A simple but maybe stupid question: I have just the standard tracking set up (no setDomainName) on one domain and one subdomain. What are the problems with sorting the pageviews by pagetitle? (The subdomain has a different pagetitle than the index page on the domain so i can easily differentiate between the two in Analytics)

  30. Al McCann says:

    Thanks Eric, this post has been super helpful.

    I am using the new Universal Analytics. Is it correct that there is no need to modify the tracking code on the pages by adding:

    _gaq.push([‘_setDomainName’, ‘yoursite.com’]);

    I having problems filtering the subdomains and wanted to rule out this.

    Thanks!

  31. nate says:

    Eric,

    Thanks for the info. I’ve followed all the instructions, but I am still not seeing any goal conversions for the main view (soundslides.com) when I click on the subdomain (soundslides.com/store) it is only here that I can see when the form is successfully filled out. Any help would be appreciated.

    • I’m not sure but take a close look at your filters and make sure they are not conflicting with each other. Also look at if they are exact match and make sure they match exactly if so.

      Is it a destination goal? It appears that others are having an issue with destination goals. I may have to look into this further.

  32. Jim Shook says:

    Great post Eric, thanks :)

    Should the subdomain use the same Account number as the main domain (and just add the _setDomain call)?

    Or should it have its own account (new UA-) and _setDomain with that code?

    Jim

  33. Fredrik Johansson says:

    Hi Eric,

    Thanks for a great post. One quick question: In your pre defined filter setup, is there a reason why you go for ‘that contain’ instead of ‘that are equal to’?

    Thanks!

  34. Emily says:

    I’m not seeing any option in Analytics under Tracking Info re: tracking subdomains. All I see is code for Universal Analytics. Has this been updated in the last 2 weeks? It seems like the only option is to manually add the set domain code to all pages of the site, whereas in the past Analytics would do it for you automatically as you explain here. Thoughts?

  35. Jim says:

    First off, this is an excellent looking guide and I’m sure it works for all you techies. But Google Analytics makes things like this far too complicated for mere mortals like myself. So I look for alternatives. There may be another way around this – instead of having subdomains, why not just have folders? Then you can just do a redirect from your old subdomain to the new folder. e.g change “blog.yousite.com” to “yoursite.com/blog”
    No need to mess with GA code if you have simple folders.

  36. Jacob says:

    Any update on the goals issue? I too am not able to track goals using this method.

    • Yes. This is a bit tricky, but for destination goals you need to make sure that the string you enter as the destination matches exactly what displays as a page in Google Analytics. For example, if you used the filter to show the subdomain, your destination goal that used to be /something/goal.html will now be subdomain.domain.com/something/goal.html

      • phidgt says:

        Thank you, thank you, thank you!
        After searching and reading about sub-domain tracking for what seems like forever, I finally ended up here.

        You, sir, are the only person who makes sense on the Internet.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>