This section covers the following configurations related to your account or website administration:
You can configure tracking so that data from multiple website installations is aggregated in one reporting profile in your Analytics account. This is referred to as site linking and involves enabling first-party cookies to be read across these different installations, so that a user session established in one domain is maintained as the same session in the other. Enabling site linking involves two main elements:
In addition, a session from one site can only be transferred to another site via a click or a form submission which links two page views under a single session. If a user independently visits two sites that are linked (such as through a bookmark), these visits are counted under separate sessions. In this scenario, the linking methods are not invoked, and thus there is no way to determine the initiating session for a given user.
Site linking is set up differently depending upon whether you are tracking across sub-domains, top-level domains, or across directories. Ideally, you will enable multi-site tracking by first establishing a profile for your primary website and using that tracking code for all other installations, along with configuring the necessary linking functions. In this case, your configuration will be set up correctly before data is recorded, and you will have all data historically located in one profile.
If you have already established separate profiles for each website installation, you can still enable linking of the separate web properties, but you will need to choose one existing profile to act as the primary one for aggregating the data from both sites. The data collected in each profile prior to linking cannot be merged into a primary profile, so the historical data for the secondary profile will remain separate.
Finally, once you have domain linking established, you will see only the request URI in the content reports, and not the top-level or sub-domain for a given page. So for example, if you have a page on http://www.example.com/index.php and another page on http://www.example2.com/index.php, you will see listings in the reports for two distinct index.php pages, and will not be able to distinguish which page is from which domain. You can include the referring domain in the page reports by setting a filter that will include all components of the page URL in the content reports, as follows:
(.*), which is an expression that captures all characters.$A1$B1 as the value for that choice.This will capture the www.example.com portion of your URL and include that at the beginning of your page URL in the content reports section.
Tracking across multiple top-level domains involves first establishing domain linking on the separate domains by using the _setDomainName() and _setAllowLinker() functions as illustrated:
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();
By default, domain name determination is set to auto-detect the domain for the cookie based on the document location object for the web page, so setting the domain name to "none" configures your pages for cross-domain session tracking. Now, you can use both the _link() and _linkByPost() methods in both links and forms that communicate to the sister domains. See the ga.js API documentation for details and examples.
As with top-level domain linking, tracking sessions across multiple hosts involves first configuring the the _setDomainName() and _setAllowLinker() functions, but with a different parameter for the _setDomainName() function:
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName(".example.com");
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();
Set the _setDomainName() parameter explicitly to your domain name if your website spans multiple hostnames and you want to track visitor behavior across all hosts. For example, if you have two hosts: server1.example.com and server2.example.com, you would set the domain name as indicated above.
Be sure to use a leading "." in front of your domain name, as illustrated here. The leading period ensures that the cookie will be accessible across all hosts. Otherwise, the cookie is accessible only in www.example.com.
Now, you can use both the _link() and _linkByPost() methods in both links and forms that communicate to the sister domains. See the ga.js API documentation for details and examples.
If you administer all parts of a given domain and have access to the root level settings, tracking across sub-directories is automatic because the tracking configuration will set the cookie path by default to the root-level directory. In that case, all sub-directories can access that cookie to maintain session information for a given user. However, you might have a website configuration such that you only want to track users to a sub-directory. For example, suppose you have a store hosted www.example.com/myStore/ where you only want to track visitor behavior to your store. Or, you might have an account where access is restricted only to your sub-directory.
In order to enable this feature in your tracking, you will use the _setCookiePath() function in your tracking code:
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setCookiePath("/myStore/");
pageTracker._initData();
pageTracker._trackPageview();
Once this is set up, your reports will display user activity only to that sub-directory. This is because the cookie path is set to your sub-directory rather than the root directory. In this case, users navigating from your section of the website to another directory on the same domain will not be tracked, since cookie paths are not read across parallel directories. However, you might have multiple sub-directories that you want to have linked, in a fashion similar to domain linking. For example, suppose your store exists on www.example.com/myStore/ but your hosting provider offers a shopping cart on www.example.com/exampleShoppingCart/. If you want to track user sessions from your store to the shopping cart, you can use the _cookieCopyPath() method to copy the cookie information to another directory on the same domain. In this case, the entire tracking code snippet would look like:
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._initData();
pageTracker._trackPageview();
pageTracker._setCookiePath("/myStore/");
pageTracker._cookiePathCopy("/exampleShoppingCart/");
You can set up two tracking code objects on a single website, so that data from one website appears in two separate Analytics accounts. This might be useful in cases where Analytics tracking of a given site is used by independent account holders for divergent purposes. For example, a 3rd-party shopping cart site administrator can track all traffic to the entire site under his Analytics account, and a client of that shopping cart site can track traffic to her specific pages using her account ID.
To track multiple accounts on a single website, you initialize separate page tracking objects for each account. This separation of tracking objects allows an easy-to-read separation of methods that apply only to a given account/page tracker object. In the following example, one account sets the session timeout to one hour, while the other account leaves session timeout to the default value of 30 minutes.
<script type="text/javascript">
var trackerA = _gat._getTracker("UA-12345-1");
trackerA._initData(); trackerA._setSessionTimeout(3600);
trackerA._trackPageview();
var trackerB = _gat._gaTracker("UA-67890-1");
trackerB._initData();
trackerB._trackPageview();
</script>