Containers: create

認証が必要です

コンテナを作成します。今すぐ試すまたは例を見る

リクエスト

HTTP リクエスト

POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers

パラメータ

パラメータ名 説明
パスパラメータ
accountId string GTM アカウント ID。

承認

このリクエストは、次のスコープでの承認が必要です(認証と承認の詳細をご確認ください)。

スコープ
https://www.googleapis.com/auth/tagmanager.edit.containers

リクエスト本文

リクエストの本文には、以下のプロパティを使用して Containers リソースを指定します。

プロパティ名 説明 メモ
必須プロパティ
name string コンテナの表示名。 書き込み可能
timeZoneCountryId string コンテナの国 ID。 書き込み可能
timeZoneId string コンテナのタイムゾーン ID。 書き込み可能
usageContext[] list コンテナの使用状況の一覧。有効な値は次のとおりです。web, android, ios 書き込み可能
省略可能なプロパティ
domainName[] list コンテナに関連付けられたドメイン名のオプションのリスト。 書き込み可能
enabledBuiltInVariable[] list 有効化された組み込み変数のリスト。有効な値は次のとおりです。pageUrl, pageHostname, pagePath, referrer, event, clickElement, clickClasses, clickId, clickTarget, clickUrl, clickText, formElement, formClasses, formId, formTarget, formUrl, formText, errorMessage, errorUrl, errorLine, newHistoryFragment, oldHistoryFragment, newHistoryState, oldHistoryState, historySource, containerVersion, debugMode, randomNumber, containerId 書き込み可能
notes string コンテナのメモ。 書き込み可能

レスポンス

成功すると、このメソッドによりレスポンスの本文で Containers リソースが返されます。

注: このメソッドで使用可能なコード例では、サポートされているプログラミング言語すべての例を示しているわけではありません(サポートされている言語の一覧については、クライアント ライブラリ ページをご覧ください)。

Java

Java クライアント ライブラリを使用します。

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

/*
 * This request creates a new container for the authorized user.
 */

// Construct the container object.
Container container = new Container();
container.setName("Example Container");
container.setTimeZoneCountryId("US");
container.setTimeZoneId("America/Los_Angeles");
container.setUsageContext(Arrays.asList("web", "android", "ios"));

try {
  Container response = tagmanager.accounts().
      containers().create("12345", container).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created Id and Fingerprint.
 */
System.out.println("Container Id = " + response.getContainerId());
System.out.println("Container Fingerprint" + response.getFingerprint());

Python

Python クライアント ライブラリを使用します。

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

# This request creates a new container.
try:
  response = tagmanager.accounts().containers().create(
      accountId='123456',
      body={
          'name': 'Example Container',
          'timeZoneCountryId': 'US',
          'timeZoneId': 'America/Los_Angeles',
          'usageContext': ['web', 'android']
      }
  ).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 create method are stored in the response object.
# The following code shows how to access the created id and fingerprint.
print response.get('containerId')
print response.get('fingerprint')

試してみよう:

以下の API Explorer を使用して、ライブデータに対してこのメソッドを呼び出し、レスポンスを確認してください。