This reference describes the methods that you use for customizing how Google Analytics reporting works across domains, across different hosts, or within sub-directories of a website.
_cookiePathCopy(newPath)_getLinkerUrl(targetUrl,
useHash)_link(targetUrl, useHash)_linkByPost(formObject,
useHash)_setAllowHash(bool) deprecated_setAllowLinker(bool)_setCookiePath(newCookiePath)_setDomainName(newDomainName)_cookiePathCopy(newPath)
Changes the paths of all GATC cookies to the newly-specified path. Use this feature to track user behavior from one directory structure to another on the same domain.
When this function is called, it immediately copies any cookies
to the new cookie path. Therefore, if the _trackPageview() method has not been
called, the values for any existing Analytics cookies will be supplied. For
that reason, we recommend that this method is called after _trackPageview()
as well as other configuration methods that might impact cookie values or
campaign values that you want to pass along, such as
_setCampaignCookieTimeout()
or _setReferrerOverride().
_gaq.push(['_cookiePathCopy', '/newSubDirectory/']);
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._trackPageview();
pageTracker._cookiePathCopy("/newSubDirectory/");
String newPath New path to store GATC cookies
under.
_getLinkerUrl(targetUrl, useHash)
This method works in conjunction with the _setDomainName() and _setAllowLinker() methods
to enable cross-domain user tracking specifically for iFrames and links
that open in a new window. This method returns a string of all the GATC cookie
data from the initiating link by appending it to the URL parameter. This can
then be passed on to a another site or iFrame.
_gaq.push(function() {
var pageTracker = _gat._getTrackerByName(); // Gets the default tracker.
var linkerUrl = pageTracker._getLinkerUrl('http://www.my-example-iframecontent.com/');
});
pageTracker._getLinkerUrl("http://www.my-example-iframecontent.com/");
pageTracker._setAllowLinker(true);)
in order for link to work properly.String targetUrl URL of target site to send
cookie values to.
String useHash Set to true for passing tracking
code variables by using the # anchortag separator rather than the default
? query string separator.
String The linker URL.
_link(targetUrl, useHash)
This method works in conjunction with
the _setDomainName()
and _setAllowLinker() methods to enable cross-domain
user tracking. The _link() method passes
the GATC
cookies from this site to another via URL parameters (HTTP
GET). It also changes the document.location and redirects the user
to the new URL.
<a href="http://example.com/test.html"
onclick="_gaq.push(['_link', 'http://example.com/test.html']); return false;">click me</a>
<a href="http://www.newsite.com" onclick="pageTracker._link('http://www.newsite.com');return false;">Go to our sister site</a>
pageTracker._setAllowLinker(true);)
in order for link to work properly.
String targetUrl URL of target site to send
cookie values to.
String useHash Set to true for passing tracking
code variables by using the # anchortag separator rather than the default
? query string separator.
_linkByPost(formObject, useHash)
This method works in conjunction with the _setDomainName() and _setAllowLinker() methods
to enable cross-domain user tracking. The _linkByPost() method
passes the GATC cookies from the referring form to another site in a string
appended to the action value of the form (HTTP POST). This method is typically
used when tracking user behavior from one site to a 3rd-party shopping
cart site, but can also be used to send cookie data to other domains in
pop-ups or in iFrames.
<form action="http://www.shoppingcartsite.com/myService/formProcessor.php"
name="f" method="post" onsubmit="_gaq.push(['_linkByPost', this]);">
...
</form>
<form action="http://www.shoppingcartsite.com/myService/formProcessor.php"
name="f" method="post" onsubmit="pageTracker._linkByPost(this)">
. . .
</form>In addition, _setAllowLinker() must be set to true on the
destination web page in order for linking to work.
HTMLFormElement formObject Form object encapsulating
the POST request.
String useHash Set to true for passing tracking
code variables by using the # anchortag separator rather than the default
? query string separator.
_setAllowHash(bool)
This method is deprecated and no longer required for cross-domain tracking.
Sets the allow domain hash flag. By default, this value is set to true.
The domain hashing functionality in Google Analytics creates a hash value
from your domain, and uses this number to check cookie integrity for visitors.
If you have multiple sub-domains, such as example1.example.com and example2.example.com,
and you want to track user behavior across both of these sub-domains, you
would turn off domain hashing so that the cookie integrity check will not
reject a user cookie coming from one domain to another. Additionally, you
can turn this feature off to optimize per-page tracking performance.
Boolean true or false Default
value is true. If this parameter is set to true,
then domain hashing is enabled. Otherwise, domain hashing is disabled.
_setAllowLinker(bool)
Sets the linker functionality flag as part of enabling cross-domain user
tracking. By default, this method is set to false and linking
is disabled. See also _link(), _linkByPost(),
and _setDomainName() methods to enable cross-domain tracking.
Use the _setAllowLinker method on the target site, so that
the target site uses the cookie data in the URL parameter, instead of
the standard session logic.
_gaq.push(['_setAllowLinker', true]);
pageTracker._setAllowLinker(true);
Boolean true or false Default
value is false. If this parameter is set to true,
then linker is enabled. Otherwise, domain linking is disabled.
_setCookiePath(newCookiePath)
Sets the new cookie path for your site. By default, Google Analytics sets the cookie path to the root level (/). In most situations, this is the appropriate option and works correctly with the tracking code you install on your website, blog, or corporate web directory. However, in a few cases where user access is restricted to only a sub-directory of a domain, this method can resolve tracking issues by setting a sub-directory as the default path for all tracking.
Typically, you would use this if your data is not being tracked and you subscribed to a blog service and only have access to your defined sub-directory, or if you are on a Corporate or University network and only have access to your home directory. In these cases, using a terminal slash is the recommended practice for defining the sub-directory.
_gaq.push(['_setCookiePath', '/myBlogDirectory/']);
pageTracker._setCookiePath("/myBlogDirectory/");
String newCookiePath New cookie path to
set.
_setDomainName(newDomainName)
Sets the domain name for
the GATC
cookies. There are three modes to this
method: ("auto" | "none" | [domain]). By
default, the method is set to auto, which
attempts to resolve the domain name based on
the document.domain property in the
DOM.
See
the Cross
Domain Tracking Guide for a variety of examples that illustrate
when and how to specify a domain with this method. The following example
illustrates how you would set the domain name to example.com:
_gaq.push(['_setDomainName', 'example.com']);
pageTracker._setDomainName("example.com");
Use the leading dot in front of the domain name if you want tracking across lower-level sub-domains such as the following:
dogs.petstore.example.com and cats.petstore.example.com, _gaq.push(['_setDomainName', '.example.com']);
pageTracker._setDomainName(".example.com");
If you do not use the leading period in this type of
scenario, the cookies will not be available to the lower-level
domains of example.com
(e.g. dogs.petstore.example.com).
If you are using the leading dot, it's important that this leading dot be specified in the tracking code for all domains that participate in the domain linking. This ensures that the cookies are available to all participating sites, thus avoiding errors and inconsistencies in report data.
Setting this method to none ensures that the cookies in a given domain
are not accessible by any sub-domains.
_gaq.push(['_setDomainName', 'none']);
pageTracker._setDomainName("none");
String newDomainName New default domain
name to set.