בהפניה הזו מתוארות השיטות הזמינות באובייקט ga
.
סיכום שיטה
השיטות הבאות זמינות באובייקט ga
לאחר הטעינה של הספרייה analytics.js
. היות שהשיטות האלה לא זמינות באופן מיידי, צריך תמיד להפעיל אותן באמצעות מוכנים להתקשרות חזרה בתור של תור הפקודות ga
.
מה לא לעשות — משתמשים בשיטות אובייקטים מסוג ga
מחוץ ל-readyCallback
, כי יכול להיות שהשיטות עדיין לא זמינות.
var trackers = ga.getAll();
מה כן לעשות – להשתמש ב-ga
שיטות אובייקטים בתוך readyCallback
כי מובטח שיהיו זמינות.
ga(function() { var trackers = ga.getAll(); });
שיטות | |
---|---|
create([trackingId], [cookieDomain], [name], [fieldsObject]); |
החזרות: יצירת מכונת מעקב חדשה עם השדות שצוינו. |
getByName(name) |
החזרות: מקבלת את מכונת המעקב עם השם שצוין. |
getAll() |
החזרות: מקבלת את כל מופעי המעקב. |
remove(name) |
החזרות: הסרת המכונה של מכשיר המעקב עם השם שצוין. |
פרטי השיטה
create
יצירת מכונת מעקב חדשה עם השדות שצוינו.
Usage
ga.create([trackingId], [cookieDomain], [name], [fieldsObject]);
פרמטרים
למידע נוסף על השדות, ניתן לעיין בחומר העזר בנושא שדות.
החזרות
דוגמאות
// Creates a default tracker for the property UA-XXXXX-Y // and uses automatic cookie domain configuration. ga(function() { var tracker = ga.create('UA-XXXXX-Y', 'auto'); })
// Creates a tracker with the name "myTracker" for the property // UA-XXXXX-Y, sets the cookieDomain to "example.com" and specifies // a site speed sample rate of 10%. ga(function() { var myTracker = ga.create('UA-XXXXX-Y', 'example.com', 'myTracker', { siteSpeedSampleRate: 10 }); });
getByName
מקבלת את מכונת המעקב עם השם שצוין.
Usage
ga.getByName(name);
פרמטרים
שם | סוג | חובה | תיאור |
---|---|---|---|
name |
string |
כן | השם של מכשיר המעקב שצריך לקבל. |
החזרות
דוגמאות
// Gets the default tracker. ga(function() { ga.getByName('t0'); });
// Gets the tracker with the name "myTracker". ga(function() { ga.getByName('myTracker'); });
getAll
מקבלת את כל מופעי המעקב.
ga.getAll();
החזרות
Array<Tracker>
דוגמה
// Logs a list of all tracker names to the console. ga(function() { var trackers = ga.getAll(); trackers.forEach(function(tracker) { console.log(tracker.get('name')); }); });
remove
הסרת המכונה של מכשיר המעקב עם השם שצוין.
Usage
ga.remove(name);
פרמטרים
שם | סוג | חובה | תיאור |
---|---|---|---|
name |
string |
כן | השם של מכשיר המעקב שרוצים להסיר. |
החזרות
undefined
דוגמאות
// Removes the default tracker. ga(function() { // Note that, unlike the ga command queue's remove method, // this method requires passing a tracker name, even when // removing the default tracker. ga.remove('t0'); });
// Removes the tracker with the name "myTracker". ga(function() { ga.remove('myTracker'); });