Google Analytics - Tracker

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

3 - Management

3.1 - Create

doc


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

where:

3.2 - Initialization

  • If a cookie does not exist for the specified domain, a client ID is generated and stored in the cookie.
  • the tracker will gather the browsing context (page, url, screen,…)

3.3 - Get

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

  • When using only one tracker (default)

ga(function(tracker) {
  console.log(tracker); 
});

  • when using more than one

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

3.4 - Get Name

The default trackers are given the name “t0”.


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

3.5 - 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:

3.6 - Set properties

  • On the default tracker

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

  • on a named tracker

ga('myTracker.set', 'page', '/about');

3.7 - 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());
});

3.8 - Exist

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


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

3.9 - 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:

  • The table that describes each of these tasks, in the order they are executed.
  • how to add, abort, set a task

4 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap