Domains and directories
One of the first things you should know about when using and configuring Google Analytics is how the domain of the web property you are tracking is defined as a "site" for the purposes of viewing your reports. The default setup of the tracking code is designed to make it easy for you to track traffic to a single domain or subdomain (e.g. a single website URL) that does not share user data with other domains or sub-domains.
For example, if your pet store URL is
dogs.example.com and you install the tracking code with its web property ID on those pages, tracking is automatically set up to track user data only for this single URL. In a similar way, if you own the primary domain, such as
www.example.com, and you install tracking for all pages on this site, user and referral traffic is recorded separately for
This article provides an overview to domains and directories in Analytics and discusses how:In this article:
Analytics cookies define a site using
Google Analytics sets and reads cookies for each unique domain being tracked by reading the
document.domain property for the page host. For this reason, Analytics views subdomains like
dogtoys.example.com as distinct from primary domains such as
document.domain property for any page you are curious about. For example, if you were to test the
document.domain property on the dogtoys website, you would see
dogtoys.example.com as the domain.
Separate domains mean separate user and traffic data
For each separate domain, the standard Analytics cookies determine two simple things:
- user information (sessions counts)
- traffic sources (referrals, searches, ad campaigns)
If you have separate cookies set for a domain and a sub-domain, unique users to each are counted independently, and any links between the two sites are counted as referral traffic. The two sites will also not share search or campaign information. This is true even if each site uses the same web property ID in the tracking code.
For example, suppose you have an online store on
dogtoys.example.com, with a shopping cart for the store on
www.example.com. Both sites have been set up with the same web property ID in the tracking code for their pages, but with no customizations. In this scenario, sessions via a link from
www.example.com will be counted as referrals. In addition, suppose some of your customers reach
dogtoys.example.com from an AdWords link, and visit the site repeatedly, before finally completing their purchase on
www.example.com. Their first visit to the shopping cart will be counted as an additional (and new) user session because user data for
www.example.com is separated--by cookie--from
If you wish instead to link user and referral traffic between two domains, you can achieve this by customizing the tracking code.
Separate domains do not mean separate content
When the Analytics servers receive a GIF request for a page, the URI and page name are stored in the request and delivered to the view that contains the matching web property ID. This means that content for a given domain is simply defined by the actual web property ID of the tracking code itself. For this reason, you can easily copy the tracking code (with the same web property ID) to your various domains and see the content data for all of them in the same reporting view.
This is also why you might forget to make the additional customization necessary to integrate user and traffic tracking between domains, since the content data for each domain appears so readily.
Sub-directories of a domain share cookies of the domain
In a standard tracking setup for a website, user, traffic, and content data is associated with a single domain, including any traffic to sub-directories. However, it is often the case that you only want to track (or have access to) a sub-directory of a domain. Following are two common examples:
- You use a shopping cart service for your online store, which resides on a sub-directory of the service domain, such as
www.example-shopping-cart.com/yourCart. In this case, you might only have access to those pages located on the sub-directory.
- Your company's website is very large, and your project is restricted to a sub-directory of the larger website, which you want to track independently from the larger domain.
Without any modification to the tracking code, the Analytics cookies will be set to the host domain, with the cookie path set to the root level (
/) of the domain. In this way, user, traffic, and campaign data to the subdirectory will be shared with user, traffic, and campaign data across the entire website.
In order to restrict tracking to a sub-directory of a website, you must define it as a separate entity by means of cookies. Since a cookie is uniquely defined by a combination of the domain and the path, you can set the path of the cookie to your sub-directory in order to separate tracking to your section of the website. For information on how to do this, see Domains & Cookies (analytics.js).