Tracking Code: The _gat Global Object

The _gat global object is used to create and retrieve tracker objects, from which all other methods are invoked. Therefore the methods in this list should be run only off a tracker object created using the _gat global variable. All other methods should be called using the _gaq global object for asynchronous tracking.

_gat Object Methods

Method Details

_getTracker()

    _getTracker(account)
    Creates a tracker object for the given web property ID. If this method is called more than once for the same Analytic account ID, a new object is created for each invocation.
    _gat._getTracker('UA-65432-1');

    parameters

      String account The full web property ID (e.g. UA-65432-1) for the tracker object.

    returns

      Tracker The created tracking object.

_createTracker()

    _createTracker(opt_account, opt_name)
    Creates a new tracker object and assigns it the given name. If no name is give, one will be generated. Tracker objects are stored under their names so they can be retrieved via _getTrackerByName. If two trackers are created with the same name, the second will overwrite the first and the first will no longer be retrieveable via _getTrackerByName.
    _gat._createTracker('UA-65432-1');
    _gat._createTracker('UA-65432-2', 't2');

    parameters

      String opt_account The full web property ID (e.g. UA-XXXXX-X) for the tracker object.
      String opt_name Optional name to store the tracker under. Use this name to retrieve the tracker via _getTrackerByName

    returns

      Tracker The created tracking object.

_getTrackerByName()

    _getTrackerByName(opt_name)
    Retrieves the tracker object with the given name. If no name is given, the default will be used, which is the empty string (''). If no tracker exists with the given name, a new tracker is created, assigned to that name and returned.
    _gat._getTrackerByName();
    _gat._getTrackerByName('t2');

    parameters

      String opt_name Optional name of the tracker to retrieve. Defaults to the empty string ('').

    returns

      Tracker The retrieved or created tracking object.

_anonymizeIp()

    _anonymizeIp()

    Tells Google Analytics to mask the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting.

    When using this function to mask tracking, you must use the push function and properly associate the function with the tracker object, as illustrated below.

Async Snippet (recommended)
var _gaq = _gaq || [];
_gaq.push (['_setAccount', 'UA-XXXXXXX-YY']);
_gaq.push (['_gat._anonymizeIp']);
_gaq.push (['_trackPageview']);


_forceSSL()

    _forceSSL(bool)

    Configures Google Analytics to send all hits using SSL, even from insecure (HTTP) pages.

Async Snippet (recommended)

_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_gat._forceSSL']);       // Send all hits using SSL, even from insecure (HTTP) pages.
_gaq.push(['_trackPageview']);