Out of the box, Google Analytics handles being deployed across multiple domains or subdomains extremely poorly. This is easily the most common critical problem in Google Analytics, despite its being relatively easy to fix.
Depending on your situation, one or more of a few simple steps may be appropriate. Look for the entry in the left-hand column below that best describes your situation, and make sure you've taken the steps listed on the right:
Situation | Implementation Check-list |
Single subdomain |
|
Multiple subdomains or domains, which are treated as separate sites | |
Multiple subdomains on a single domain which are treated as a single site | |
Multiple domains with one or more subdomains that are treated as a single site |
As a word of warning, several steps in this document differ according to the tracking code in use, and in these cases I suggest options for each tracking code type. If you're unsure of your current implementation:
- ga.js / doubeclick.js: Your source code will contain several "_gaq.push" commands
- analytics.js tracking code: Your source code will contain "ga('create'" and "ga('send'" commands
- Google Tag Manager: You have an analytics tag in your Google Tag Manager account (which I will assume is set to "Universal Analytics")
If you have updated your Google Analytics interface to Universal Analytics but you're still using the old code, you should follow the recommendations for the old (ga.js / doubleclick.js) tracking code here.
Using separate tracking IDs
Tracking IDs are the unique codes that you're given when you create a Google Analytics property, and look something like "UA-123456-1". Any page with that tracking ID, regardless of the site it's on, will send data to that property.
While it is possible to use the same tracking ID across multiple domains or subdomains and then view them each in isolation using filtered views, the only advantage of doing so is having access to one aggregated view. For the data in this aggregated view to be meaningful, it will need to ignore self-referrals, and this is configured at the property level, meaning that all views will ignore self-referrals, thus leaving the (sub)domain-specific views with a load of "direct" traffic that actually came from sister sites.
This means that you end up choosing between incorrect data in your aggregate view and incorrect data in your specific view. If you do want to be able to have meaningful data in both specific and aggregate views, you could consider having one tracking ID that's used across all sites and additional tracking IDs for each individual site. For details on implementation, check Google's guidelines here (and also here if you use Google Tag Manager).
Ignoring self-referrals
A "self-referral" is when one of the sources of traffic to your own site is your own site. They make it very difficult to work out what channels are being effective in driving conversions, because they leave you with missing data for some sessions.
Self referrals don't just screw up your attribution data. They also trigger new sessions, thus ruining your key metrics and making it extremely hard to track the routes individuals take through your site. Fortunately, they're really easy to deal with.
If you have the old ga.js (or doubleclick.js) tracking code, simply add your domains as ignored referrers in your tracking code:
If you need to ignore multiple domains using ga.js or doubleclick.js tracking code, add multiple lines like this one. In either case, make sure that they come between the "setAccount" and "trackPageview" lines.
If you're using analytics.js tracking code, it's even easier:
Navigate to Admin -> Tracking Info -> Referral Exclusion list, and you can add any referrers you want to ignore. Note that although this feature can appear in your Google Analytics user interface even if you're using the old ga.js tracking code, it will only work with analytics.js.
Prepend hostname to request URIs
A "hostname" is the name that Google Analytics gives to the subdomain that a pageview originated from. Request URIs are the names you see in reports when you set a dimension like "landing page", "page" or "previous page path".
Any view that includes data from multiple domains or subdomains runs the risk of aggregating data from multiple pages and considering them the same page. For example, if your site includes "blog.example.com/index.html" and "example.com/index.html", these will be merged in reports under "/index.html", and you'll never have any idea how effective or otherwise your blog and homepage are.
You can overcome this using an advanced filter:
In the example, this means that we'd see "www.example.com/index.html" as a page in reports, rather than just "/index.html", and metrics that rely on telling the difference between the pages will report their real levels.
Note that you'll have to update any destination based goals after implementing this filter (shout-out to Sharon in the comments for pointing this out to me).
Ga.js / doubleclick.js only: Set domain name
For users of the new analytics.js tracking code or a Universal Analytics tag in Google Tag Manager, this step is unnecessary: Unless configured to do otherwise, the cookie is now automatically stored at the highest level possible so as to avoid being subdomain-specific. However, when using the old tracking code, Google Analytics needs a cookie location to be set in the tracking code so that it doesn't lose it when moving between subdomains.
All this means in practice is a simple additional line in your tracking code, between the "_setAccount" and "_trackPageview" lines:
This should always be set to your domain without any subdomain - e.g. moz.com, distilled.net - not
www.moz.com or www.distilled.net.
Cross-domain linking
By default, Google Analytics looks for a cookie on the same domain as the page. If it doesn't find one, it assumes that a new visit has just begun, and starts a new session. When moving between domains, the cookie cannot be transferred, so information about the session must be passed by "decorating" links with tracking information.
Don't panic; this recently got dozens of times easier with the advent of the autoLink plugin for analytics.js. If your site spans multiple domains and you're not already using Google's latest analytics tracking code, this feature should justify the upgrade on its own.
If you can't upgrade for any reason, I won't cover the necessary steps for the old ga.js tracking code in this post, but you can find Google's documentation here.
If you're using on-page analytics.js tracking code, you can implement the autoLink plugin by making some modifications to your tracking code:
- Tells analytics.js to check whether the linker parameter exists in the URL and is less than 2 minutes old
- Loads the autoLink plugin
- The autoLink command is passed domains and two parameters. The first sets whether the linking parameters are in the anchor (rather than the query) portion of the URL, and the second enables form decoration (as well as link decoration).
In Google Tag Manager, it's easier still, and just requires two additional options in your Universal Analytics tag:
In conclusion
Setting up analytics to properly handle multiple domains or subdomains isn't difficult, and not bothering will invalidate your data. If you have any questions or tips, please share them in the comments below.
Great post, this was very handy as we recently added a subdomain and I needed to look at best practice suggestions on how to track the data in GA.
One thing to note, by following your implementation, when I created the filter to prepend the hostname to the request URI, this broke all my Destination based Goals in GA. (Unless I did something wrong...) It was easy to fix, I just added the hostname to the beginning of the URI for all destination based goals. But it might be handy to make a note in the article that people should double check their goal set up to make sure things are still working.
That's a great point, thanks.
EDIT: This has now been updated.
Tom, there's a "View Filter" screenshot under the Prepend hostname to request URIs section. Where do I find this? Is this something that needs to be set up prior to implementing the code (new installation) or is this something that is filtered out afterwards.
I found out where this is... the account level filtering. Not under the property or view level.
I also broke my Google Analytics Destination Goals when I created the URI filter. I do not fully understand how to fix it. I tried adding the host name to the Destination Goal (i.e. example .com/thank-you vs. /thank-you) but that didn't fix it. Can you clarify what you mean by "I just added the hostname to the beginning of the URI for all destination based goal." and include a screenshot? Thank you so much!
It looks like it fixes it when I change the rule for the goal from "begins with" to "regular expression."
Excellent Guide. Thanks Moz.
Uhm thanks nice infos but... I have a DRUPAL multidomain and multisites structure with shared db and dns: every site (as www.aaaa.com or like www.xxxx.net or subdomain like red.xxx.net ) has a indipendent template and I can put content where I want to publish it (in one or 20 or in all of them). Unfortunately I can't use multiple G.A. tracking ID because I have only one Drupal Google Analytics Module where put it! One module for many domains and sub-domains). I asked Google support but... nothing, they haven't solution. Have you any suggest to resolve my issues?! How I check my sites and shared contents with 'differents' domains?! Sorry for my bad english :-) Max
Use GTM and set triggers for each separate hostname (basically your site) - this way each site / hostname (doable via lookup table variable) can send GA hits to a separate property.
Max, in order to track this you need a bit of jquery knowledge as well as some code. This is the current format you need to have.
//on example.com
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_trackPageview']);
</script>
...
//ever link you should have the onclick= atached
<a href="www.blog-hosting-service.com/myBlog"
onclick="_gaq.push(['_link', 'www.blog-hosting-service.com/myBlog']); return false;">
View My Blog</a>
//this code should go on your blog
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'blog-hosting-service.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
...
<a href="www.example.com"
onclick="_gaq.push(['_link', 'www.example.com']); return false;">
View My Site</a>
...
So basically you need to change every everywhere to add the on click, this can get a bit tedious, so I did a bit of jquery magic to get this done automatically.
//on blog
$(document).ready(function(){
var links = $('a:[href*="www.example.com"]'); links.each(function() {
var url = $(this).attr('href');
console.log(url);
$(this).attr('href','#');
$(this).attr('onclick', '_gaq.push(["_link", "' + url + '"]); return false');
}); })
great! I like this. why Moz does not offer readers a favorite box? so we can add all the posts we like into it, and it is quite convenient for us to study in details later
Two thumbs up for the notion. These things are a real treat, knowledge wise and harder to find :)
I'd like to add a thanks to Distilled London, read a couple of articles coming from you guys and they've all been great
Great blog.
Was hoping to find info about multiple properties across one site and was wondering if anyone can help me.
I have an universal analytics code on my site but I do not own the account, only have limited access.
I have created a new analytics account and was wondering if anyone knew how to edit the code to track two analytics properties (accounts). Hoping to use the new account from now on but continue to track the old account for historical comparisons.
Thanks
Take a look at "Working with multiple tracking objects" here -
https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced
Thanks Tom.
Hi Tom,
What is the syntax for this in Universal Analytics?
What in particular are you referring to? I've tried to cover UA, GA classic and GTM throughout the guide.
I have configured Advance Filter to track the sub-domains record as follow :
Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: $A1$B1
After that, I am able to see sub-domains record and View Full Page URL In Reports. But when I check reports in All page (e.g. Behavior >> All Pages) or selecting Landing Page as a Primary Dimension. Further I click on Icon given next to displayed Full URL to visit to same domain page, in browser the page opened but the double domain name comes so page not open successfully.
For example :
In landing page list following URL given :
www.sitegeek.com/compareHosting/arvixe_vs_hostgat...
If I click on icon given next the displayed URL, in browser following URL will open
https://sitegeek.comwww.sitegeek.com/compareHosti...
Is First Domain with HTTPs coming from 'View' where this is taken ?
How Can I remove double domains?
Thanks,
Rajiv
There's no solution here I'm afraid - I recommend retaining a view without this filter if you want to retain this functionality.
Brilant post ! I have a Wordpress multidomain and this article and this article will help me a lot in my SEO.
Hi Tom,
Thank you for your valuable information.
We have a current CMS website with it's Google analytics account. The access I have to this Google analytics account is minimum because it is managed by a third party.
I am going to create a new website from scratch in WordPress with the same domain name that the old CMS site.
Please, Tom could you explain how to set up a new Google Analytics account for the new WordPress website using the current domain name/URL website?
I hope you can help me with my query please.
Thank you in advance for your support!
Hello! How would you recommend to structure the account for an ecommerce that has multiple subdomains based on language? For example www.example.com/en for English /it for Italian, etc. I´d like to have the data separately. Thanks!
Hi TOM, Thanks for such a detailed post!. In my case I have a website and a couple of subdomains for a blog and some landing pages. I used different tracking IDs for the main site and each subdomain. Considering this scenario, do I still have the risk of self-referrals? I can see a bunch of "direct traffic" in the main site's analytics.
I've migrated to Universal Analytics and it seems to be tracking my domain and subdomain. I have one subdomain- forum.mydomain.com. I would simply like to setup a view that only allows traffic from that subdomain and none from the mydomain.com. Do I create a Include for the subdomain and an Exclude for the domain?
Hi Tom,
Great post!
I have tried to figure out what checklist to use - perhaps you can help me?
One of my clients have an affiliate site where visitors leave domain 1 via an iframe to book and pay (on the second domain - where I also inserted my G.A tracking code) where the conversion (e-commerce tracking) happens.
My initial guess is that it is option 4 in your checklist. But my tracking code is almost similiar to yours (and I have done all 3 steps that you suggesteed).
But something is wrong:
ALL the e-commerce conversions are - according to Google Analytics - coming from the source "direct traffic". That is off course not the case since they have great rankings in Google, are spending a lot on AdWords and so on...
Hope you can help me out?
Best regards,
Christan
Hi there,
this is the best article about conversions tracking still! However I use a little bit another modification of the GA code from support.google.com/analytics/answer/1034342 - I put the 1st code on site.com and another code on secure.abookingservice.net. Now I can see my destination conversions in our default View (there were just 'site.com / referral' and 'direct / none' before) but there are no conversions (just zero) in my New Filtered View. I created this View by copying that default view and added that Filter "Prepend hostname to request URIs" - it's 100% similar to that we can see here or on Google Support pages. There are no any other filters. I tried to embed secure.abookingservice.net, https://secure.abookingservice.net, https://secure.abookingservice.net or just /booking.php (Destination Begins with) - nothing helps... What's wrong? Any ideas? Thanks.
Thanks for the information, I have been very useful since I was looking for information on the subject and finally I could find something interesting
NIce article.
Im kind of new in google analytics, after I make the changes in the article for the case of Multiple domains with one or more subdomains that are treated as a single site, when I accomplish an objective and the user came thru one of the subdomains this conversión registers as a Referral.
Is this the way it shoulds works?
Thank you for the extremely helpful article. After reviewing your article and numerous others I'm still having trouble getting cross domain tracking working for two different site domains (e.g., abc.com and xyz.com). I'm hoping you might be able to help or recommend a someone/company that could provide assistance. abc.com is set up using GTM and zyx.com with Universal Analytics code as you outlined in your article. I followed all the steps above exactly and when I review the Site Content | All Pages report on abc.com I still only see visited content for abc.com. I expected that I would see pages for both abc.com and xyz.com. And yes, I can confirm there has been site traffic on xyz.com. I can see the ga ID passed from abc.com to xyz.com and see the GA ID from abc.com in the GA cookie on xyz.com. I confirmed the debug messages in the browser console are not reporting any Universal Analytics error messages. Could my issue be the fact that the ga('send', 'pageview'); command needs to be the last line of code after the require and linker:autoLink commands? Is there anything else I may be missing?
Hi there, old post I know but I just wanted to clarify using the Referral Exclusion List for the 1 domain, multiple subdomain scenario. According to GA help:
...if you add example.com to the list of referral exclusions, traffic from the domain example.com and the subdomain another.example.com is excluded...
So, if you're tracking one domain and subdomains of that domain, then it seems you ONLY need to add the root domain to the referrel exclusion list. In addition it seems they might do this by default now, as I see in newly created GA accounts the root domain is added in the list.
Hello Tom, would appreciate your inputs in the following use case:
If we have two sub-domains for a domain (which itself is tracked under GA as UA-property-1):
doc.xyz.com: UA-property-1blog.xyz.com: UA-property-2
How can we exclude only 'doc.xyz.com' from being tracked as the referrer but keep the 'blog.xyz.com' to be tracked as the referred with respect to the main domain xyz.com ?
Kindly let me know your thoughts on this.
Thank you!
Hello, can I use this method also for m.example.com as sub-domain-mobile site?
Thanks
Hello,
I have a website example.com & have mobile site m.example.com as a sub-domain, when users access the site example.com from mobile-devices they are redirected to m.example.com, what is the right & best way to set-up GTM in this case?
Thanks
Hi Tom,
Thanks for this article, it really clears things up. I was wondering if you could just help me clarify a couple of things though.
Im using universal analytics in google tag manager. I have one property set up in analytics to read data across https://www.mydomain.com and https://deck.mydomain.com
-I have added the self referral exclusion for www.mydomain.com,
-I did have cross domain tracking setup for this but have taken this off in accordance with the article.
-I have added in the host append inside analytics
Will this now be adequate for me to be able to track a user from https://www.mydomain.com (where they land and sign up/join) to https://deck.mydomain.com (where they make bookings).
And is it better practice to have 3 properties one for https://www.mydomain.com one for https://deck.mydomain.com with cross domain tracking set up and one (as described above) set up for viewing all.
Ideally I want to be able to view everything as one session and know how many people from https://www.mydomain.com convert or complete actions further down the funnel on https://deck.mydomain.com and know the referral they came into https://www.mydomain.com on.
Thanks again.
Adam
This is such a difficult concept to wrap one's brain around. So I have one subdomain - store.mysite.com and mysite.com. I'm getting many referral visits from my own site in analytics. Here's what I'm confused about. If I add mysite.com to my referral exclusion list, it seems like that should fix my problem. However, does that mean that, if someone goes from mysite.com to store.mysite.com and my referral exclusion is set up, their session and pageviews will be excluded from my data after they've moved to store.mysite.com?
No - the idea with referral exclusion is to prevent a new session being triggered. As long as the code is set up properly, the pageviews from the original subdomain and the pageviews from the second subdomain will be combined into one session.
Hi Tom,
I came across this article while doing a little research. I work in the arts industry in Ireland, and I'm part of a network of several organisations that would like some examples of best practice for sharing selected web data. Ultimately we'd like to be able to use a shared dashboard or other suitable tool to benchmark how our sites, campaigns, social networks, etc are performing. We'd also like to learn a little more about our web visitors, to see if we have similar visitor demographics, for instance. That might inform joint marketing campaigns or opportunities in future.
I wondered if this is the kind of thing that we could use a shared Analytics dashboard for? Or if you have any practical examples of cases where this type of data sharing has taken place, or where it has worked well?
It's worth noting that we don't currently have someone central managing all our Analytics accounts. Each organisation manages their's separately.
I'd be so grateful for any help or advice!
Thanks,
Aoife
Shared analytics dashboards, if you're talking about what I think you're talking about, are shared across users, not accounts - they're not a way of viewing data from multiple properties in one dashboard.
Thanks Tom - I thought so... I'm not sure the solution we're looking for exists. It's probably rare to want to share that level of information with other organisations! Appreciate you getting back to me
Hi Tom,
Myself and my director are getting a lot out of this article! There's one thing we're a little confused about though. We've got the "ignore self-referrals" set up in our account, but we're still seeing the other sites show up in our referrals, and our direct traffic is showing landing pages that imply traffic from within our sites.
Any thoughts on why this is?
Here's a screenshot of what we're looking at, anonymized: https://i.imgur.com/ysV8jTe.png
There are a few possible reasons:
Great post Tom! I gonna use it for subdomains and measure more specifically for each one. Thanks a lot.
How can my own site showing as a referral site in referral site section?
https://support.google.com/analytics/answer/3198398
Hi Tom,
Thanks for sharing such a wonderful post over cross domain tracking in Google Analytics. This post clearly gives the best solution to some long due queries that were frequent among beginners in Analytics. I'm going to share this blog among my peers.
"Out of the box, Google Analytics handles being deployed across multiple domains or subdomains extremely poorly." Yep this is very true, I wish it was easier to view under 1 ID! I thought the upgraded analytics was supposed to make this easier.
This is a new website. I have www.domain.com and store.domain.com Its hard to tell the difference between / and / of website and store. I have a 301 redirected domain going to the store.domain too.
I guess the easiest way would be give each its unique but I would rather look at everything under 1 view.
Getting the analytics and goal conversion set up in this site I will be working on. Well if I can't get it right at least I smarter people than me here to count on.
Happy Monday
[link removed by editor]
Thanks for a great post Tom,
I guess the main reason why so many sites with multiple subdomains don't use two tracking codes is simply because they don't know it's possible.
We actually have very good experience using two, one for each subdomain separately and one for the entire network (the entire domain). Analytics handles the "All sites" property very well.
You can then easily decide for each property which referrals you'd like to exclude, but the main thing is that all of the data is available according to what you want to see, as separate sites or as one network.
Agreed, except for "Analytics handles the "All sites" property very well." - it does if you follow the steps I've outlined above (prepend hostnames to request URIs, add all domains to referral exclusion), but lots of people/businesses don't realise they need to.
You’re totally right, and in cases like in your URL structure example people should definitely be aware of that.
At the same time, we are one example for a site that doesn't need that because our subdomains are the localized editions of the same content.
In our case "a.site.com/category1" and "b.site.com/category1" are two identical categories but in different languages. When we use the "All sites" property, we actually do want to see the data for the page or category across all subdomains.
Thanks again!
Nicely written post, timed perfectly as we're just addressing the issue of multiple domain tracking and cross-channel attribution this week!
Thanks for sharing.
Love the post . I just discovered a way of monitoring applied to several domains who had the opportunity to meet . I put it up soon.
Thanks for this post, Tom. I am trying to resolve a self-referral problem that I'm seeing in Universal Analytics, but was told (perhaps erroneously), that adding my own domain to the Referral Exclusion List just results in that traffic being called Direct rather a Referral. In other words, it just moves the visit from one bucket to another.
The specific situation is that we have a few subdomains (page.example.com, member.example.com) but most of the traffic is on www.example.com. We'd like to have a visitor that starts on the page subdomain, moves to www and then to member all be considered a single visit. Is there something else to set up to ensure this?
In some cases it could result in traffic just being re-labelled as direct (e.g. if you have a landing page with no tracking code), but in the cross-subdomain case the purpose is to prevent movement between subdomains from triggering a new session at all, so you're taking a session that would have been a self-referral and re-classifying it as part of another session. Hope that helps.
I've been looking for a guide on this from a solid source. Thanks Moz.
GREAT !!!
Thanks you very much Tom
I was successful
I have recently become responsible for a number of client site analytics. A few of the client sites span multiple domains. In one case there is the "article" site and the other is a about the author page. Both domains link to each other and I'm looking for a way to determine whether the traffic flowing between the two is back and forth traffic or real referral traffic from one site to the other. So I want to know if visitor A enters site A and then goes to B, and visitor B enters site B and then goes to site A or if visitor A is entering site A going to site B and then back to site A. I was thinking of using multi-domain tracking but I've never done that before and I don't know if I can still pull data for the individual domains involved.
Could I achieve this with filters?
No, I don't think filters would be a good solution for this.
In my opinion, your best option is to treat them as one site employing cross-domain tracking. Then use the User Flow report to analyse movements between areas of the site (you can use regex to customise User Flow reports, I explain how in section 1 here).
Thanks, for the great article! I have a question. My company has separated their subdomains with different tracking IDs for each. We have recently launched an online store, but in order to track conversions I need to see every time a customer lands on the login screen, which is on a different subdomain with a different tracking code than the store. How do I go about doing this?
Thanks you very much Tom! It was just what I was looking for, I´m going to try with two tracking number to see the results!
I´m still not sure if it would be good for me due the low traffic I have.
Hi there, this very nice article which is a great use.It might be helpful,Thank you for your research buddy
Hi Tom,
Thank you for sharing such an informative article.
I have a question, if my website is www.mydoamin.com, and i have 2 subdomains such as:
blog.mydomain.com and training.mydomain.com, what situation is this based on your table?
Appreciate your advice.
[link removed by editor]
Very useful article because we use analytics for domain and subdomain pages and your posts give us the hability of measure individually.
Very Good Article Clear my so many doubt !!
This may be a bit off track but if you have a client with multiple locations in different cities do you see a local SEO benefit by having different domains / sites for each location?