gaAddonsgaAddons - Google Analytics Addons by Stéphane Hamel

Documentation: Calls Reference

_setXDomain

Automated cross-domain tracking.

You might want to review the Test Cases for additional examples.

Refer to Google Analytics article about cross-domain tracking for additional information..

Caveat

This call must come before your regular _trackPageView. In fact, the best practice would be to put _setXDomain just after your _setAccount call

When tracking multiple domains in a single profile, pages with identical URLs will be rolled up into one. In the example below, www.example-petstore.com/index.htm and dogs.example-petstore.com/index.htm will be considered one and the same in your Google Analytics reports. You should set up an advanced filter in your Google Analytics profile so the resulting, tracked URLs also includes the full domain name. Refer to the article on the ROI Revolution blog for step by step instructions about Tracking Multiple Domains.


Cross domain scenario

  • One domain & sub-domains (Google Analytics help)
    _gaq.push(['_setXDomain', {
          domainName: 'example-petstore.com'
          }]);
    Here, we tell _setXDomain that any subdomain of .example-petstore.com should be tracked, thus, www and dogs.

    The method used by gaAddons is documented in "Google Analytics Subdomain Tracking" by ROI Revolution.

  • Multiple domains & sub-domains (Google Analytics help)
    We use a regular expression for "include" so we can specify multiple domain names.
    _gaq.push(['_setXDomain', {
          domainName: 'example-petstore.com',
          include: /(my-example-blogsite.com|otherdomain.com)/
          }]);
    We tell gaAddons the main domain is exampler-petstore.com but we also want to track my-example-blogsite and otherdomain in the same account.

    Links between example-petstore, my-example-blogsite and otherdomain will be modified to pass the proper information (i.e. the GA _link or _linkByPost calls)

  • One domain & sub-directories of other domains (Google Analytics help)
    _gaq.push(['_setXDomain', {
          domainName: 'example-petstore.com',
          include: /(blog-hosting-service.com\/myBlog|otherdomain.com\/otherdir)/
          }]);
    This is the same concept as above, but only for a specific directory of the other domain.

    Links between example-petstore, blog-hosting-service and otherdomain will be modified to pass the proper information (i.e. the GA _link or _linkByPost calls) only if they match the specified directories.

  • A single sub-directory (Google Analytics help)
    _gaq.push(['_setXDomain', {
          include: '/myBlog/
          }]);
    If what you have access to is only a sub-directory of the current domain. Note, again that domainName is a regular expression, giving you more control over what needs to be tracked.
  • Not supported by gaAddons: Tracking across two sub-directories on the same domain (Google Analytics help) and iFrame Content Hosted on Another Domain (Google Analytics help)

Parameters

domainName string
The your primary domain name. Do not put a leading "." when specifying the domainName.
include string|regex
Depending on the cross-domain scenario, you might have to specify the include rules. Carefully review the scenarios above to know if you should specify a string or a regular expression.
exclude regex
The exclude filter can be used to exclude some links from cross-domain tracking. By default, nothing is excluded. Caution should be exercised when using this option since it can significantly affect the accuracy of your tracking.
selector 'a'|jQuery selector
Advanced use only: allow you to specify an alternative jQuery selector for cross-domain links.