การอ้างอิงนี้อธิบายถึงเมธอดที่พร้อมใช้งานในออบเจ็กต์ ga
สรุปเมธอด
เมธอดต่อไปนี้ใช้ได้กับออบเจ็กต์ ga
หลังจากโหลดไลบรารี analytics.js
แล้ว เนื่องจากวิธีเหล่านี้ไม่พร้อมใช้งานทันที คุณควรเรียกใช้โดยใช้ga
คิวคําสั่ง'sการเรียกกลับเสมอ
Don't — ใช้วิธีการของออบเจ็กต์ 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
สร้างอินสแตนซ์เครื่องมือติดตามใหม่ด้วยช่องที่ระบุ
การใช้งาน
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
รับอินสแตนซ์เครื่องมือติดตามที่มีชื่อที่ระบุ
การใช้งาน
ga.getByName(name);
พารามิเตอร์
ชื่อ | ประเภท | จำเป็น | คำอธิบาย |
---|---|---|---|
name |
string |
yes | ชื่อของเครื่องมือติดตามที่จะรับ |
การคืนสินค้า
ตัวอย่าง
// 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
นําอินสแตนซ์เครื่องมือติดตามที่มีชื่อที่ระบุออก
การใช้งาน
ga.remove(name);
พารามิเตอร์
ชื่อ | ประเภท | จำเป็น | คำอธิบาย |
---|---|---|---|
name |
string |
yes | ชื่อของเครื่องมือติดตามที่จะนําออก |
การคืนสินค้า
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'); });