Custom Metrics: patch

需要授权

更新现有自定义指标。此方法支持修补语义。立即试用查看示例

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
accountId string 要更新的自定义指标的帐号 ID。
customMetricId string 要更新的自定义指标的自定义指标 ID。
webPropertyId string 要更新的自定义指标的网络媒体资源 ID。
可选的查询参数

授权

此请求需要获得下列范围的授权(详细了解身份验证和授权)。

范围
https://www.googleapis.com/auth/analytics.edit

请求正文

根据修补语义的规则,在请求正文提供 management.customMetric 资源的相关部分。

响应

如果成功,此方法会在响应正文中返回 management.customMetric 资源

示例

注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

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

/*
 * This request patches 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()
      .patch("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

使用 Python 客户端库

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

# This request patches an existing custom metric.
try:
  analytics.management().customMetrics().patch(
      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))

试试看!

请使用下面的 API Explorer 对实际数据调用此方法,并查看响应。或者,您也可以尝试使用独立的 Explorer