Tracking API: Basic Configuration
This reference describes the methods that you use for customizing all aspects of Google Analytics reporting.
ga.js Basic Methods
Method Details
_getAccount()
Returns the Google Analytics tracking ID for this tracker object.
If you are tracking pages on your website in multiple accounts, you
can use this method to determine the account that is associated
with a particular tracker object.
returns
String Account ID this tracker object is instantiated with.
_getVersion()
Returns the GATC version number.
returns
String GATC version number.
_initData()
Initializes or re-initializes the GATC (Google Analytics Tracker Code) object.
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._initData();
pageTracker._trackPageview();
_setSampleRate()
Sets the new sample rate. If your website is particularly
large and subject to heavy traffic spikes, then setting the
sample rate ensures un-interrupted report tracking.
Sampling in Google Analytics occurs consistently across unique
visitors, so there is integrity in trending and reporting even
when sampling is enabled, because unique visitors remain included
or excluded from the sample, as set from the initiation of sampling.
pageTracker._setSampleRate("80"); //sets sampling rate to 80 percent
parameters
String newRate New sample rate to set. Provide a numeric string as a whole percentage.
_setSessionTimeout()
_setSessionTimeout(newTimeout)
Sets the new session timeout in seconds. By default, session
timeout is set to 30 minutes (1800 seconds). Session timeout
is used to compute visits, since a visit ends after 30 minutes
of browser inactivity or upon browser exit. If you want to change
the definition of a "session" for your particular needs, you
can pass in the number of seconds to define a new value. This
will impact the Visits reports in every section where the number
of visits are calculated, and where visits are used in computing
other values. For example, the number of visits will increase
if you shorten the session timeout, and will decrease if you
increase the session timeout.
parameters
String newTimeout New session timeout to set in seconds.
_setVar()
Sets a user-defined value. The value you supply appears as an option
in the Segment pull-down for the Traffic Sources reports. You can
use this value to provide additional segmentation on users to your
website. For example, you could have a login page or a form that triggers
a value based on a visitor's input, such as a preference the visitor
chooses, or a privacy option. This variable is then updated in the
cookie for that visitor.
parameters
String newVal New user defined value to set.
_trackPageview()
_trackPageview(opt_pageURL)
Main logic for GATC (Google Analytic Tracker Code). If linker
functionalities are enabled, it attempts to extract cookie values from the URL.
Otherwise, it tries to extract cookie values from document.cookie.
It also updates or creates cookies as necessary, then writes them back to the
document object. Gathers all the appropriate metrics to send to the
UCFE (Urchin Collector Front-end).
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._initData();
pageTracker._trackPageview("/home/landingPage");
parameters
String opt_pageURL Optional parameter to indicate what page
URL to track metrics under. When using this option, use a beginning
slash (/) to indicate the page URL.