Questo riferimento descrive i metodi disponibili nell'oggetto Tracker
.
Riepilogo metodo
Metodi | |
---|---|
get(fieldName) |
returns: Visualizza il valore di un campo memorizzato nel tracker. |
set(fieldName|fieldsObject, [fieldValue]) |
returns: Imposta una coppia campo/valore o un gruppo di coppie campo/valore sul tracker. |
send([hitType], [...fields], [fieldsObject]) |
returns: Invia un hit a Google Analytics. |
Dettagli metodo
get
Visualizza il valore di un campo memorizzato nel tracker.
Utilizzo
tracker.get(fieldName);
Parametri
Nome | Tipo | Obbligatorio | Descrizione |
---|---|---|---|
fieldName |
string |
yes | Il nome del campo di cui ottenere il valore. |
Restituisce
*
Esempi
// 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
Imposta una coppia campo/valore o un gruppo di coppie campo/valore sul tracker.
Utilizzo
// Sets a single field/value pair. tracker.set(fieldName, fieldValue);
// Sets a group of field/value pairs. tracker.set(fieldsObject);
Parametri
Consulta la documentazione sui campi per la documentazione dei singoli campi.
Restituisce
undefined
Esempi
// 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
Invia un hit a Google Analytics.
Utilizzo
tracker.send([hitType], [...fields], [fieldsObject]);
I campi inviati sono i valori specificati nei parametri ...fields
e fieldsObject
, uniti ai campi attualmente memorizzati sul tracker.
Parametri
I campi che possono essere specificati dai parametri ...fields
variano a seconda del tipo di hit. La seguente tabella elenca i campi che corrispondono a ciascun tipo di hit. I tipi di hit non elencati non accettano parametri ...fields
, solo fieldsObject
.
Tipo di hit | ...fields |
---|---|
pageview |
page |
event |
eventCategory , eventAction , eventLabel , eventValue |
social |
socialNetwork , socialAction , socialTarget |
timing |
timingCategory , timingVar , timingValue , timingLabel |
Consulta la documentazione sui campi per la documentazione dei singoli campi.
Restituisce
undefined
Esempi
// 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 }); });