Custom Metrics: list

Memerlukan otorisasi

Mencantumkan metrik kustom yang dapat diakses oleh pengguna. Coba sekarang atau lihat contohnya.

Permintaan

Permintaan HTTP

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

Parameter

Nama parameter Nilai Deskripsi
Parameter jalur
accountId string ID akun untuk metrik kustom yang akan diambil.
webPropertyId string ID properti web untuk metrik kustom yang akan diambil.
Parameter kueri opsional
max-results integer Jumlah maksimum metrik kustom yang akan disertakan dalam respons ini.
start-index integer Indeks entity pertama yang akan diambil. Gunakan parameter ini sebagai mekanisme penomoran halaman beserta parameter hasil maksimal.

Otorisasi

Permintaan ini memerlukan otorisasi dengan setidaknya salah satu cakupan berikut (baca selengkapnya tentang autentikasi dan otorisasi).

Cakupan
https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/analytics

Isi permintaan

Jangan memberikan isi permintaan dengan metode ini.

Respons

Jika berhasil, metode ini akan menampilkan isi respons dengan struktur berikut:

{
  "kind": "analytics#customMetrics",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.customMetrics Resource
  ]
}
Nama properti Nilai Deskripsi Catatan
kind string Jenis koleksi.
username string ID email pengguna terautentikasi
totalResults integer Jumlah total hasil untuk kueri, berapa pun jumlah hasil dalam respons.
startIndex integer Indeks awal resource, yang merupakan 1 secara default atau ditentukan oleh parameter kueri indeks awal.
itemsPerPage integer Jumlah maksimum resource yang dapat ditampung respons, berapa pun jumlah resource sebenarnya yang ditampilkan. Nilainya berkisar dari 1 hingga 1.000 dengan nilai 1.000 secara default, atau ditentukan oleh parameter kueri hasil maks.
items[] list Kumpulan metrik kustom.

Contoh

Catatan: Contoh kode yang tersedia untuk metode ini tidak merepresentasikan semua bahasa pemrograman yang didukung (lihat halaman library klien untuk mengetahui daftar bahasa yang didukung).

Java

Menggunakan library klien 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

Menggunakan library klien 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')

Cobalah!

Gunakan APIs Explorer di bawah untuk memanggil metode ini pada data live dan melihat respons. Atau, coba Explorer mandiri.