What is a user-event tracker ? (Analytics Script) 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.
// Queues a named tracker object for creation.
ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');
where:
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'));
});
The default trackers are given the name “t0”.
ga(function(tracker) {
console.log(tracker.get('name'));
});
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:
ga('set', {
page: '/about',
title: 'About Us'
});
// or
ga(function(tracker) {
tracker.set('page', '/about');
});
ga('myTracker.set', 'page', '/about');
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());
});
When there is no default tracker, the first argument of the ready callback is undefined
ga(function(tracker) {
console.log(tracker); // Logs `undefined`.
});
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: