Custom Metrics: update

Memerlukan otorisasi

Memperbarui metrik kustom yang ada. Coba sekarang atau lihat contohnya.

Permintaan

Permintaan HTTP

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

Parameter

Nama parameter Nilai Deskripsi
Parameter jalur
accountId string ID akun untuk metrik kustom yang akan diperbarui.
customMetricId string ID metrik kustom untuk metrik kustom yang akan diperbarui.
webPropertyId string ID properti web untuk metrik kustom yang akan diperbarui.
Parameter kueri opsional

Otorisasi

Permintaan ini memerlukan otorisasi dengan cakupan berikut (baca lebih lanjut tentang autentikasi dan otorisasi).

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

Isi permintaan

Dalam isi permintaan, berikan resource management.customMetric.

Respons

Jika berhasil, metode ini menampilkan resource management.customMetric dalam isi respons.

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 updates an existing custom metric.
 */

// Construct the body of the request and set its properties.
CustomMetric body = new CustomMetric();
body.setName("Level Completions");
body.setScope("HIT");
body.setType("INTEGER");
body.setActive(true);

try {
  analytics.management().customMetrics()
      .update("123456", "UA-123456-1", "ga:metric2", body).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

Python

Menggunakan library klien Python.

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

# This request updates an existing custom metric.
try:
  analytics.management().customMetrics().update(
      accountId='123456',
      webPropertyId='UA-123456-1',
      customMetricId='ga:metric2',
      body={
          'name': 'Level Completions',
          'scope': 'HIT',
          'type': 'INTEGER',
          'active': True
      }
  ).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))

Cobalah!

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