This reference describes the methods available on the Tracker object.

Method Summary

Methods

get(fieldName)

returns: * Gets the value of a field stored on the tracker.

set(fieldName|fieldsObject, [fieldValue])

returns: undefined

Sets a field/value pair or a group of field/value pairs on the tracker.

send([hitType], [...fields], [fieldsObject])

returns: undefined

Sends a hit to Google Analytics.

Method Details

get

Gets the value of a field stored on the tracker.

Usage

tracker.get(fieldName);

Parameters

Name

Type

Required

Description

fieldName

string

yes

The name of the field the get the value of.

Returns

*

Examples

// Creates a default tracker.

ga('create', 'UA-XXXXX-Y', auto);

// Gets the client ID of the default tracker and logs it.

ga(function(tracker) {

  var clientId = tracker.get('clientId');

  console.log(clientId);

});

set

Sets a field/value pair or a group of field/value pairs on the tracker.

Usage

// Sets a single field/value pair.

tracker.set(fieldName, fieldValue);

// Sets a group of field/value pairs.

tracker.set(fieldsObject);

Note: it's recommended to call the set method using the ga command queue. See the set method reference for more details.

Parameters

See the field reference for individual field documentation.

Returns

undefined

Examples

// Creates a default tracker.

ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {

  // Sets the page field to "/about.html".

  tracker.set('page', '/about.html');

});

// Creates a default tracker.

ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {

  // Sets both the page and title fields.

  tracker.set({

    page: '/about.html',

    title: 'About'

  });

});

send

Sends a hit to Google Analytics.

Usage

tracker.send([hitType], [...fields], [fieldsObject]);

The fields that are sent are the values specified in the ...fields parameters and fieldsObject, merged with the fields currently stored on the tracker.

Note: the values specified in ...fields and fieldsObject are sent with the current hit, but they are not stored on the tracker object. Use the set method to update a tracker.

Parameters

The fields that can be specified by the ...fields parameters vary depending on the hit type. The following table lists the fields that correspond to each hit type. Hit types not listed do not accept ...fields parameters, only the fieldsObject.

Hit type

...fields

pageview

page

event

eventCategory, eventAction, eventLabel, eventValue

social

socialNetwork, socialAction, socialTarget

timing

timingCategory, timingVar, timingValue, timingLabel

See the field reference for individual field documentation.

Note: it's recommended to call the send method using the ga command queue. See the send method reference for more details.

Returns

undefined

Examples

// Creates a default tracker.

ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {

  // Sends a pageview hit.

  tracker.send('pageview');

});

// Creates a default tracker.

ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {

  // Sends an event hit for the tracker named "myTracker" with the

  // following category, action, and label, and sets the nonInteraction

  // field value to true.

  tracker.send('event', 'link', 'click', 'http://example.com', {

    nonInteraction: true

  });

});

Did this answer your question?