Table of Contents

Google Analytics - Tracker

About

Tracker in Google analytics

Tracker objects (also known as “trackers”) are objects that can collect and store data and then send that data to Google Analytics.

Management

Create

doc

// Queues a named tracker object for creation.
ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');

where:

Initialization

Get

Getting a reference to a tracker object requires waiting until after the create command has been executed with the ready callback

ga(function(tracker) {
  console.log(tracker); 
});
ga(function() {
  console.log(ga.getByName('myTracker'));
});

Get Name

The default trackers are given the name “t0”.

ga(function(tracker) {
  console.log(tracker.get('name'));
});

Get properties

by name

ga(function(tracker) {
  console.log(tracker.get('name'));
  console.log(tracker.get('clientId'));
  console.log(tracker.get('referrer'));
});

where:

by id defined in the measurement protocol

ga(function(tracker) {
  console.log(tracker.get('&dt'));
});

// same as
ga(function(tracker) {
  console.log(tracker.get('title'));
});

where:

Set properties

ga('set', {
  page: '/about',
  title: 'About Us'
});
// or
ga(function(tracker) {
  tracker.set('page', '/about');
});
ga('myTracker.set', 'page', '/about');

List

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

ga(function() {
  // Logs an array of all tracker objects.
  console.log(ga.getAll());
});

Exist

When there is no default tracker, the first argument of the ready callback is undefined

ga(function(tracker) {
  console.log(tracker); // Logs `undefined`.
});

Send

Each time the send command is called, analytics.js executes a sequence of tasks to validate, construct, and send a measurement protocol request from the user's browser to Google Analytics.

See:

Documentation / Reference