Macros: update

認証が必要です

GTM マクロを更新します。 今すぐ試すまたは例を見る

リクエスト

HTTP リクエスト

PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/macros/macroId

パラメータ

パラメータ名 説明
パスパラメータ
accountId string GTM アカウント ID。
containerId string GTM コンテナ ID。
macroId string GTM マクロ ID。
省略可能なクエリ パラメータ
fingerprint string 指定する場合は、ストレージ内のマクロと同じフィンガープリントを使用する必要があります。

承認

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

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

リクエスト本文

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

プロパティ名 説明 メモ
必須プロパティ
parameter[].type string パラメータの型。有効な値は次のとおりです。
  • boolean: ブール値(「true」または「false」)
  • integer: 64 ビット符号付き整数値(10 進数)
  • list: パラメータのリスト
  • map: パラメータのマップ
  • template: 任意のテキストを表します。マクロ参照も含めることができます(文字列以外の型を返すマクロ参照も含みます)。


有効な値は次のとおりです。
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
書き込み可能
type string GTM マクロのタイプ。 書き込み可能
省略可能なプロパティ
disablingRuleId[] list モバイル コンテナのみ: 条件付きマクロを無効にするためのルール ID のリスト。すべての無効化ルールが false である一方で、有効化ルールの 1 つが true の場合、マクロは有効になります。順不同のセットとして扱われます。 書き込み可能
enablingRuleId[] list モバイル コンテナのみ: 条件変数を有効にするためのルール ID のリスト。すべての無効化ルールーが false である一方で、有効化ルールの 1 つが true の場合、マクロは有効になります。順不同のセットとして扱われます。 書き込み可能
name string マクロの表示名。 書き込み可能
notes string コンテナでこのマクロを利用する方法についてのユーザーのメモ。 書き込み可能
parameter[] list マクロのパラメータ。 書き込み可能
parameter[].key string パラメータを一意に識別する名前付きキー。トップレベルのパラメータとマップ値では必須となります。リスト値では無視されます。 書き込み可能
parameter[].list[] list このリスト パラメータのパラメータ(キーは無視されます)。 書き込み可能
parameter[].map[] list このマップ パラメータのパラメータ(一意のキーが必要)。 書き込み可能
parameter[].value string 指定された型のパラメータ値(「」などマクロの参照も使用できます)。 書き込み可能
scheduleEndMs long マクロをスケジュール設定する終了タイムスタンプ(ミリ秒単位)。 書き込み可能
scheduleStartMs long マクロをスケジュール設定する開始タイムスタンプ(ミリ秒単位)。 書き込み可能

レスポンス

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

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

Java

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

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

/*
 * This request updates an existing macro for the authorized user.
 */

// Construct the macro object.
Macro macro = new Macro();
macro.setName("Updated URL Macro");
macro.setType("u");

// Construct the parameters.
Parameter arg0 = new Parameter();
arg0.setType("template");
arg0.setKey("component");
arg0.setValue("URL");

Parameter arg1 = new Parameter();
arg1.setType("template");
arg1.setKey("customUrlSource");
arg1.setValue("{{element}}");

// set the parameters on the macro.
macro.setParameter(Arrays.asList(arg0, arg1));

try {
  Macro response = tagmanager.accounts().containers().
      macros().update("123456", "54321", "18", macro).execute();

} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the update method are stored in the response object.
 * The following code shows how to access the updated name and fingerprint.
 */
System.out.println("Updated Name = " + response.getName());
System.out.println("Updated Fingerprint = " + response.getFingerprint());

Python

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

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

# This request updates an existing macro for the authorized user.
try:
  response = tagmanager.accounts().containers().macros().update(
      accountId='123456',
      containerId='54321',
      macroId='19',
      body={
          'name': 'Sample URL Macro',
          'type': 'u',
          'parameter': [
              {
                  'type': 'template',
                  'key': 'component',
                  'value': 'URL'
              },
              {
                  'type': 'template',
                  'key': 'customUrlSource',
                  'value': '{{element}}'
              }
          ]
      }
  ).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 update method are stored in the response object.
# The following code shows how to access the updated name and fingerprint.
print 'Updated Name = %s' % response.get('name')
print 'Updated Fingerprint = %s' % response.get('fingerprint')

試してみよう:

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