カスタム指標: insert

承認が必要です

新しいカスタム指標を作成します。 こちらから今すぐお試しいただけます。または、をご覧ください。

リクエスト

HTTP リクエスト

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

パラメータ

パラメータ名 説明
パスパラメータ
accountId 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 creates a new 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()
      .insert("123456", "UA-123456-1", 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 creates a new custom metric.
try:
  analytics.management().customMetrics().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      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))

試してみる

リアルタイムのデータでこのメソッドを呼び出してレスポンスを確認するには、以下の APIs Explorer か、スタンドアロンのテストツールをご利用ください。