Custom Metrics: list

ต้องมีการให้สิทธิ์

แสดงรายการเมตริกที่กำหนดเองที่ผู้ใช้มีสิทธิ์เข้าถึง ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customMetrics

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
accountId string รหัสบัญชีสำหรับเมตริกที่กำหนดเองเพื่อดึงข้อมูล
webPropertyId string รหัสเว็บพร็อพเพอร์ตี้สำหรับเมตริกที่กำหนดเองเพื่อเรียกดู
พารามิเตอร์การค้นหาที่ไม่บังคับ
max-results integer จำนวนเมตริกที่กำหนดเองสูงสุดที่จะรวมไว้ในคำตอบนี้
start-index integer ดัชนีของเอนทิตีแรกที่จะดึงข้อมูล ใช้พารามิเตอร์นี้เป็นกลไกการใส่เลขหน้าร่วมกับพารามิเตอร์ max-results

การให้สิทธิ์

คำขอนี้ต้องได้รับการให้สิทธิ์อย่างน้อย 1 ขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/analytics

เนื้อหาของคำขอ

อย่าแสดงเนื้อหาของคำขอด้วยวิธีนี้

คำตอบ

หากทำสำเร็จ เมธอดนี้จะแสดงเนื้อหาการตอบสนองที่มีโครงสร้างต่อไปนี้

{
  "kind": "analytics#customMetrics",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.customMetrics Resource
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
kind string ประเภทคอลเล็กชัน
username string รหัสอีเมลของผู้ใช้ที่ตรวจสอบสิทธิ์แล้ว
totalResults integer จำนวนผลลัพธ์ทั้งหมดสำหรับข้อความค้นหา โดยไม่คำนึงถึงจำนวนผลลัพธ์ในการตอบกลับ
startIndex integer ดัชนีเริ่มต้นของทรัพยากร ซึ่งเท่ากับ 1 โดยค่าเริ่มต้น หรือระบุโดยพารามิเตอร์การค้นหา Start-index
itemsPerPage integer จำนวนทรัพยากรสูงสุดที่การตอบกลับมีได้ โดยไม่คำนึงถึงจำนวนทรัพยากรที่แสดงผลจริง ค่าอยู่ในช่วง 1 ถึง 1000 โดยมีค่า 1000 โดยค่าเริ่มต้น หรือมีการระบุโดยพารามิเตอร์การค้นหาผลลัพธ์สูงสุด
items[] list คอลเล็กชันของเมตริกที่กําหนดเอง

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

Java

ใช้ไลบรารีของไคลเอ็นต์ Java

/**
 * Note: This code assumes you have an authorized Analytics service object.
 */

/**
 * This request lists all custom metrics for the authorized user.
 */
try {
  CustomMetrics metrics = analytics.management.customMetrics
      .list("12345", "UA-12345-1").execute();

} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/**
 * The results of the list method are stored in the metrics object.
 * The following code shows how to iterate through them.
 */
for (CustomMetric metric : metrics.getItems()) {
  System.out.println("Metric Kind: " + metric.getKind());
  System.out.println("Metric Id: " + metric.getId());
  System.out.println("Account ID: " + metric.getAccountId());
  System.out.println("Property ID: " + metric.getWebPropertyId());
  System.out.println("Metric Name: " + metric.getName());
  System.out.println("Metric Index: " + metric.getIndex());
  System.out.println("Metric Scope: " + metric.getScope());
  System.out.println("Metric Active: " + metric.getActive());
  System.out.println("Metric Type: " + metric.getType());
  System.out.println("Metric Created: " + metric.getCreated());
  System.out.println("Metric Updated: " + metric.getUpdated());
}

Python

ใช้ไลบรารีของไคลเอ็นต์ Python

# Note: This code assumes you have an authorized Analytics service object.

# This request lists all custom metrics for the authorized user.
try:
  metrics = analytics.management().customMetrics().list(
      accountId='123456',
      webPropertyId='UA-123456-1',
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))


# The results of the list method are stored in the metrics object.
# The following code shows how to iterate through them.
for metric in metrics.get('items', []):
  print 'Metric Kind = %s' % metric.get('kind')
  print 'Metric Id = %s' % metric.get('id')
  print 'Account ID = %s' % metric.get('accountId')
  print 'Property ID = %s' % metric.get('webPropertyId')
  print 'Metric Name = %s' % metric.get('name')
  print 'Metric Index = %s' % metric.get('index')
  print 'Metric Scope = %s' % metric.get('scope')
  print 'Metric Active = %s' % metric.get('active')
  print 'Metric Type = %s' % metric.get('type')
  print 'Metric Created = %s' % metric.get('created')
  print 'Metric Updated = %s' % metric.get('updated')

ลองใช้เลย

ใช้ API Explorer ด้านล่างเพื่อเรียกใช้เมธอดนี้ในข้อมูลสดและดูการตอบสนอง หรือลองใช้เครื่องมือสำรวจแบบสแตนด์อโลน