My favorites | English | Sign in

More personalization in Google Friend Connect New!

Google Analytics

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

_deleteCustomVar()

    _deleteCustomVar(index)
    This method deletes the variable assigned to the supplied index, if one exists. For example, you might set a visitor-level custom variable and later decide that you no longer want to use this visitor-level variable.
    pageTracker._deleteCustomVar(1); 

    parameters

      Int   index The index of the custom variable to delete.

_getAccount()

    _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()

    _getVersion()
    Returns the GATC version number.

    returns

      String GATC version number.

_getVisitorCustomVar()

    _getVisitorCustomVar(index)
    Returns the visitor level custom variable assigned for the specified index.
    pageTracker._getVisitorCustomVar(1); 

    parameters

      Int   index The index of the visitor level custom variable.

    returns

      String The value of the visitor level custom variable. Returns undefined if unable to retrieve the variable for the specified index.

_initData()

    _initData()Deprecated. initData() now executes automatically in the ga.js tracking code.
    Initializes or re-initializes the GATC (Google Analytics Tracker Code) object.
    var pageTracker = _gat._getTracker("UA-12345-1");
    pageTracker._trackPageview();

_setCookiePersistence()

    _setCookiePersistence(milliseconds)
    Sets the Google Analytics visitor cookie expiration in milliseconds. By default, the visitor cookie is set to expire in 2 years. If you prefer, you can change the expiration date of the visitor cookie using this method. For example, to set the expiration of the visitor cookie to 7 days you would use the following code:
    pageTracker._setCookiePersistence(604800000); //number of milliseconds in 7 days

    parameters

      String   milliseconds New visitor cookie expiration time.

_setCustomVar()

    _setCustomVar(index, name, value, opt_scope)
    Sets a custom variable with the supplied name, value, and scope for the variable. There is a 64-byte character limit for the name and value combined.
    pageTracker._setCustomVar(
          1,                   // This custom var is set to slot #1
          "Section",           // The top-level name for your online content categories
          "Life & Style",      // Sets the value of "Section" to "Life & Style" for this particular aricle
          3                    // Sets the scope to page-level
       ); 

    returns

      Boolean This method returns true if the custom variable has been set successfully, and false if it has not (e.g. if your name/value string length exceeds 64 bytes, or if you use an incorrect slot).

    parameters

      Int      index       The slot used for the custom variable. Possible values are 1-5, inclusive.
      String   name        The name for the custom variable.
      String   value       The value for the custom variable.
      Int      opt_scope   The scope used for the custom variable. Possible values are 1 for visitor-level, 2 for sesson-level, and 3 for page-level.

_setSampleRate()

    _setSampleRate(newRate)
    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()

    _setVar(newVal)
    Sets or defines a custom visitor segment with the supplied string. 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. When implemented on your site and data is collected via this method, the newly defined segment appears in the User Defined reports in the Visitors section of the Analytics Reports. Additionally, you can access the User Defined Value segment in the Content Detail report to see which percentage of visitors to a page belong to a particular segment that you define.

    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._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.