English | Site Directory

Google Analytics Custom Tracking

Google Analytics Tracking API

This reference contains all of the available methods that you can use to customize data configuration for Google Analytics reporting.

All Methods, Alphabetical Order

Method Details

_addIgnoredOrganic()

    _addIgnoredOrganic(newIgnoredOrganicKeyword)
    Sets the string as ignored term(s) for Keywords reports. Use this to configure Google Analytics to treat certain search terms as direct traffic, such as when users enter your domain name as a search term. When you set keywords using this method, the search terms are still included in your overall page view counts, but not included as elements in the Keywords reports.
    pageTracker._addIgnoredOrganic("www.mydomainname.com");

    parameters

      String   newIgnoredOrganicKeyword Keyword search terms to treat as direct traffic.

_addIgnoredRef()

    _addIgnoredRef(newIgnoredReferrer)
    Excludes a source as a referring site. Use this option when you want to set certain referring links as direct traffic, rather than as referring sites. For example, your company might own another domain that you want to track as direct traffic so that it does not show up on the "Referring Sites" reports. Requests from excluded referrals are still counted in your overall page view count.
    pageTracker._addIgnoredRef("www.sister-site.com");

    parameters

      String   newIgnoredReferrer Referring site to exclude.

_addItem()

    _addItem(Item, sku, name, category, price, quantity)
    Adds a transaction item to the parent transaction object. Use this method to track items purchased by visitors to your ecommerce site. This method tracks items by SKU and performs no additional ecommerce calculations (such as quantity calculations). Therefore, if the item being added is a duplicate (by SKU) of an existing item for that session, then the old information is replaced with the new. Additionally, it does not enforce the creation of a parent transation object, but it is advised that you set this up explicitly in your transaction tracking code. If no parent transaction object exists for the item, the item is attached to an empty transaction object instead.
    pageTracker._addItem(
       "343212", //order ID
       "DD4444", //sku
       "Lava Lamp", // product name
       "Decor", // category or product variation
       "34.99", // price
       "1"  //quantity
     );

    parameters

      String   Item
      String   sku Item's SKU code (required).
      String   name Product name.
      String   category Product category.
      String   price Product price (required).
      String   quantity Purchase quantity (required).

_addOrganic()

    _addOrganic(newOrganicEngine, newOrganicKeyword)
    Adds a search engine to be included as a potential search engine traffic source. By default, Google Analytics recognizes a number of common search engines, but you can add additional search engine sources to the list.

    parameters

      String   newOrganicEngine Engine for new organic source.
      String   newOrganicKeyword Keyword name for new organic source.

_addTrans()

    _addTrans(orderId, affiliation, total, tax, shipping, city, state, country)
    Creates a transaction object with the given values. As with _addItem(), this method handles only transaction tracking and provides no additional ecommerce functionality. Therefore, if the transaction is a duplicate of an existing transaction for that session, the old transaction values are over-written with the new transaction values.
    pageTracker._addTrans(
         "1234", //order ID - required
         "My Partner Store", //affiliation or store name
         "84.99", //total - required
         "7.66", //tax
         "15.99", //shipping
         "Boston", //city
         "MA", //state or province
         "USA" //country
         );

    parameters

      String   orderId Internal unique order id number for this transaction.
      String   affiliation Optional partner or store affiliation. (undefined if absent)
      String   total Total dollar amount of the transaction.
      String   tax Tax amount of the transaction.
      String   shipping Shipping charge for the transaction.
      String   city City to associate with transaction.
      String   state State to associate with transaction.
      String   country Country to associate with transaction.

    returns

      _gat.GA_EComm_.Transactions_ The tranaction object that was modified.

_clearIgnoredOrganic()

    _clearIgnoredOrganic()
    Clears all strings previously set for exclusion from the Keyword reports.

_clearIgnoredRef()

    _clearIgnoredRef()
    Clears all items previously set for exclusion from the Referring Sites report.

_clearOrganic()

    _clearOrganic()
    Clears all search engines as organic sources. Use this method when you want to define a customized search engine ordering precedence.

_cookiePathCopy()

    _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. In order for this to work, the GATC tracking data must be initialized (_initData() must be called).
    var pageTracker = _gat._getTracker("UA-12345-1");
    pageTracker._initData();
    pageTracker._trackPageview();  
    pageTracker._cookiePathCopy("/newSubDirectory/");

    parameters

      String   newPath New path to store GATC cookies under.

_createEventTracker()

    _createEventTracker(objName)
    This method is deprecated. Creates an event tracking object with the specified name. Call this method when you want to create a new web page object to track in the Event Tracking section of the reporting. See the Event Tracking Guide for more information.
    var videoTracker = pageTracker._createEventTracker("Videos");

    parameters

      String   objName The name of the tracked object.

    returns

      _gat.GA_EventTracker_ A new event tracker instance.

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

_getClientInfo()

    _getClientInfo(1)
    Gets the flag that indicates whether the browser tracking module is enabled. See _setClientInfo() for more information.

    parameters

      Number   1 if enabled, 0 if disabled.

_getDetectFlash()

    _getDetectFlash(1)
    Gets the Flash detection flag. See _setDetectFlash() for more information.

    parameters

      Number   1 if enabled, 0 if disabled.

_getDetectTitle()

    _getDetectTitle(1)
    Gets the title detection flag.

    parameters

      Number   1 if enabled, 0 if disabled.

_getLocalGifPath()

    _getLocalGifPath()
    Gets the local path for the Urchin GIF file. See _setLocalGifPath() for more information.

    returns

      String Path to GIF file on the local server.

_getServiceMode()

    _getServiceMode()
    Returns the server operation mode. Possible return values are 0 for local mode (sending data to local server set by _setLocalGifPath()), 1 for remote mode (send data to Google Analytics backend server), or 2 for both local and remote mode.

    returns

      Number Server operation mode.

_getVersion()

    _getVersion()
    Returns the GATC version number.

    returns

      String GATC version number.

_initData()

    _initData()
    Initializes or re-initializes the GATC (Google Analytics Tracker Code) object.
    var pageTracker = _gat._getTracker("UA-12345-1");
    pageTracker._initData();
    pageTracker._trackPageview();

_link()

    _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 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://www.newsite.com" onclick="pageTracker._link('http://www.newsite.com');return false;">Go to our sister site</a>

    You must also enable linking on the target site (pageTracker._setAllowLinker(true);) in order for link to work properly.

    parameters

      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. (Currently this behavior is for internal Google properties only.)

_linkByPost()

    _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 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="pageTracker._linkByPost(this)">
    . . .
    </form>

    In addition, _setAllowLinker() must be set to true on the destination web page in order for linking to work.

    parameters

      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.

_setAllowAnchor()

    _setAllowAnchor(enable)
    Allows the # sign to be used as a query string delimiter in campaign tracking. This option is disabled by default. Typically, campaign tracking URLs are comprised of the question mark (?) separator and the ampersand (&) as delimiters for the key/value pairs that make up the query. By enabling this option, your campaign tracking URLs can use a pound (#) sign instead of the question mark (?).
    http://mysite.net/index.html?source=In+House#method=email#offer_type=Fall+email+offers
    pageTracker._setAllowAnchor(true);

    parameters

      Boolean   enable If this parameter is set to true, then campaign will use anchors. Else, campaign will use search strings.

_setAllowHash()

    _setAllowHash(enable)
    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.

    parameters

      Boolean   enable If this parameter is set to true, then domain hashing is enabled. Else, domain hashing is disabled. True by default.

_setAllowLinker()

    _setAllowLinker(enable)
    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.
    pageTracker._setAllowLinker(true);

    parameters

      Boolean   enable If this parameter is set to true, then linker is enabled. Else, linker is disabled.

_setCampContentKey()

    _setCampContentKey(newCampContentKey)
    Sets the campaign ad content key. The campaign content key is used to retrieve the ad content (description) of your advertising campaign from your campaign URLs. Use this function on the landing page defined in your campaign.

    For example, suppose you have an ad on another website with this URL to your site:

    http://mysite.net/index.html?source=giganoshopper.com&method=referral&offer_type=Christmas+specials&description=Garden+gloves


    In this url, the key "description" delineates the content supplied in the URL for that campaign. (These terms and phrases appear under the Ad Content column in the Campaign detail page in the Traffic Sources report.) To use that key as your customized campaign content key, you would set:

    pageTracker._setCampContentKey("description");

    parameters

      String   newCampContentKey New campaign content key to set.

_setCampMediumKey()

    _setCampMediumKey(newCampMedKey)
    Sets the campaign medium key, which is used to retrieve the medium from your campaign URLs. The medium appears as a segment option in the Campaigns report.

    For example, suppose you have an ad on another website with this URL to your site:

    http://mysite.net/index.html?source=giganoshopper.com&method=ad&offer_type=Christmas+specials&description=Garden+gloves


    In this url, the key "method" delineates the medium in the URL for that campaign. To use that key as your customized campaign content key, you would set:

    pageTracker._setCampMediumKey("method");

    parameters

      String   newCampMedKey Campaign medium key to set.

_setCampNameKey()

    _setCampNameKey(newCampNameKey)
    Sets the campaign name key. The campaign name key is used to retrieve the name of your advertising campaign from your campaign URLs. You would use this function on any page that you want to track click-campaigns on.

    For example, suppose you send an email to registered users about a special offer, and the link to that offer looks like:

    http://mysite.net/index.html?source=In+House&method=email&offer_type=Fall+email+offers


    In this url, the key "offer_type" delineates the name supplied in the URL for that campaign. (This is the name that appears in the list of Campaigns in the Traffic Sources report.) To use that key as your customized campaign name key, you would set:

    pageTracker._setCampNameKey("offer_type");

    parameters

      String   newCampNameKey Campaign name key.

_setCampNOKey()

    _setCampNOKey(newCampNOKey)
    Sets the campaign no-override key variable, which is used to retrieve the campaign no-override value from the URL. By default, this variable and its value are not set. For campaign tracking and conversion measurement, this means that, by default, the most recent impression is the campaign that is credited in your conversion tracking. If you prefer to associate the first-most impressions to a conversion, you would set this method to a specific key, and in the situation where you use custom campaign variables, you would use this method to set the variable name for campaign overrides. The no-override value prevents the campaign data from being over-written by similarly-defined campaign URLs that the visitor might also click on.

    If you have an ad on another website with this URL to your site:

    http://mysite.net/index.html?source=giganoshopper.com&method=referral&offer_type=Christmas+specials&description=Garden+gloves&noo=1234


    In this url, the key "noo" delineates the no-override value in the URL for that campaign. To use that key as your customized campaign no-override key, you would set:

    pageTracker._setCampNOKey("noo");

    parameters

      String   newCampNOKey Campaign no-override key to set.

_setCampSourceKey()

    _setCampSourceKey(newCampSrcKey)
    Sets the campaign source key, which is used to retrieve the campaign source from the URL. "Source" appears as a segment option in the Campaigns report.

    For example, suppose you have an ad on another website with this URL to your site:

    http://mysite.net/index.html?source=giganoshopper.com&method=referral&offer_type=Christmas+specials&description=Garden+gloves


    In this url, the key "source" delineates the source in the URL for that campaign. To use that key as your customized campaign source key, you would set:

    pageTracker._setCampSourceKey("source");

    parameters

      String   newCampSrcKey Campaign source key to set.

_setCampTermKey()

    _setCampTermKey(newCampTermKey)
    Sets the campaign term key, which is used to retrieve the campaign keywords from the URL.

    For example, suppose you have a paid ad on a search engine tagged as follow:

    http://mysite.net/index.html?source=weSearch4You.com&method=paidSearchAd&offer_type=Christmas+specials&description=Garden+gloves&term=garden+tools


    In this url, the key "term" delineates the keyword terms in the URL for that campaign. To use that key as your customized campaign term key, you would set:

    pageTracker._setCampTermKey("term");

    parameters

      String   newCampTermKey Term key to set.

_setCampaignTrack()

    _setCampaignTrack(enable)
    Sets the campaign tracking flag. By default, campaign tracking is enabled for standard Google Analytics set up. If you wish to disable campaign tracking and the associated cookies that are set for campaign tracking, you can use this method.

    parameters

      Boolean   enable True by default, which enables campaign tracking. If set to false, campaign tracking is disabled.

_setClientInfo()

    _setClientInfo(enable)
    Sets the browser tracking module. By default, Google Analytics tracks browser information from your visitors and provides more data about your visitor's browser settings that you get with a simple HTTP request. If you desire, you can turn this tracking off by setting the parameter to false. If you do this, any browser data will not be tracked and cannot be recovered at a later date, so use this feature carefully.

    parameters

      Boolean   enable Defaults to true, and browser tracking is enabled. If set to false, browser tracking is disabled.

_setCookiePath()

    _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.
    pageTracker._setCookiePath("/~username/");
    pageTracker._setCookiePath("/myBlogDirectory/");

    parameters

      String   newCookiePath New cookie path to set.

_setCookieTimeout()

    _setCookieTimeout(newDefaultTimeout)
    Sets the campaign tracking cookie expiration time in seconds. By default, campaign tracking is set for 6 months. In this way, you can determine over a 6-month period whether visitors to your site convert based on a specific campaign. However, your business might have a longer or shorter campaign time-frame, so you can use this method to adjust the campaign tracking for that purpose.
    pageTracker._setCookieTimeout("3152600"); //number of seconds in 1 year

    parameters

      String   newDefaultTimeout New default cookie expiration time to set. Pass in as a string and it is converted to an integer.

_setDetectFlash()

    _setDetectFlash(enable)
    Sets the Flash detection flag. By default, Google Analytics tracks Flash player information from your visitors and provides detailed data about your visitor's Flash player settings. If you desire, you can turn this tracking off by setting the parameter to false. If you do this, any Flash player data will not be tracked and cannot be recovered at a later date, so use this feature carefully.

    parameters

      Boolean   enable Default is true and Flash detection is enabled. False disables Flash detection..

_setDetectTitle()

    _setDetectTitle(enable)
    Sets the title detection flag. By default, page title detection for your visitors is on. This information appears in the Contents section under "Content by Title." If you desire, you can turn this tracking off by setting the parameter to false. You could do this if your website has no defined page titles and the Content by Title report has all content grouped into the "(not set)" list. You could also turn this off if all your pages have particularly long titles. If you do this, any page titles that are defined in your website will not be displayed in the "Content by Title" reports. This information cannot be recovered at a later date once it is disabled.

    parameters

      Boolean   enable Defaults to true, and title detection is enabled. If set to false, title detection is disabled.

_setDomainName()

    _setDomainName(newDomainName)
    Sets the domain name for 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 location object in the DOM.

    Set this method 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 follows:

    pageTracker._setDomainName(".example.com");


    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 example.com.

    Set this method to none in the following two situations:
  • You want to disable tracking across hosts.
  • You want to set up tracking across two separate domains. Cross- domain tracking requires configuration of the _setAllowLinker() and _link
  • methods.
    pageTracker._setDomainName("none");

    parameters

      String   newDomainName New default domain name to set.

_setLocalGifPath()

    _setLocalGifPath(newLocalGifPath)
    Sets the local path for the Urchin GIF file. Use this method if you are running the Urchin tracking software on your local servers. The path you specific here is used by the _setLocalServerMode() and _setLocalRemoteServerMode() methods to determine the path to the local server itself.

    parameters

      String   newLocalGifPath Path to GIF file on the local server.

_setLocalRemoteServerMode()

    _setLocalRemoteServerMode()
    Invoke this method to send your tracking data both to a local server and to the Google Analytics backend servers. You would use this method if you are running the Urchin tracking software on your local servers and want to track data locally as well as via Google Analytics servers. In this scenario, the path to the local server is set by _setLocalGifPath().

_setLocalServerMode()

    _setLocalServerMode()
    Invoke this method to send your tracking data to a local server only. You would use this method if you are running the Urchin tracking software on your local servers and want all tracking data to be sent to your servers. In this scenario, the path to the local server is set by _setLocalGifPath().

_setRemoteServerMode()

    _setRemoteServerMode()
    Default installations of Google Analytics send tracking data to the Google Analytics server. You would use this method if you have installed the Urchin software for your website and want to send particular tracking data only to the Google Analytics server.

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

_trackEvent()

    _trackEvent(action, opt_label, opt_value)
    This method use is deprecated. Constructs and sends the event tracking call to GATC via the event tracking object.

    parameters

      String   eventType The type name for the event.
      String   opt_label An optional descriptor for the event.
      Int   opt_value An optional value to be aggregated with the event.

    returns

      Boolean whether the event was successfully sent.

_trackEvent()

    _trackEvent(category, action, opt_label, opt_value)
    Constructs and sends the event tracking call to the Google Analytics Tracking Code. Use this to track visitor behavior on your website that is not related to a web page visit, such as interaction with a Flash video movie control or any user event that does not trigger a page request.

    parameters

      String   eventType The type name for the event.
      String   opt_label An optional descriptor for the event.
      String   opt_value An optional value to be aggregated with the event.

    returns

      Boolean whether the event was successfully sent.

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

_trackTrans()

    _trackTrans()
    Sends both the transaction and item data to the Google Analytics server. This method should be called after _trackPageview(), and used in conjunction with the _addItem() and addTrans() methods. It should be called after items and transaction elements have been set up.
    var pageTracker = _gat._getTracker("UA-12345-1");
       pageTracker._initData();
       pageTracker._trackPageview();
       pageTracker._addTrans(
          "1234", // order ID - required
          "Womens Apparel", // affiliation or store name
          "11.99", // total - required
          "1.29", // tax
          "15.00", // shipping
          "San Jose", // city
          "California", // state or province
          "USA" // country
        );
       pageTracker._addItem(
          "1234", // order ID - required
          "DD44", // SKU/code
          "T-Shirt", // product name
          "Olive Medium", // category or variation
          "11.99", // unit price - required
          "1" // quantity - required
       );
       pageTracker._trackTrans();