Tags: update

需要授權

更新 GTM 代碼。 立即試用查看範例

要求

HTTP 要求

PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/tags/tagId

參數

參數名稱 說明
路徑參數
accountId string GTM 帳戶 ID。
containerId string GTM 容器 ID。
tagId string GTM 代碼 ID。
自選查詢參數
fingerprint string 如果提供這個指紋,這個指紋必須與儲存空間中標記的指紋相符。

授權

這項要求需要下列範圍的授權 (進一步瞭解驗證和授權)。

範圍
https://www.googleapis.com/auth/tagmanager.edit.containers

要求主體

在要求主體中,提供具有以下屬性的標記資源

資源名稱 說明 附註
必要屬性
name string 代碼顯示名稱。 可寫入
parameter[].type string 參數類型。有效值如下:
  • boolean:這個值代表布林值,以「true」或「false」表示
  • integer:這個值代表 64 位元的帶正負號整數值,以 10 為底數
  • list:應指定參數清單
  • map:應指定參數對應
  • template:此值代表任何文字,可能包含變數參照 (甚至是可能會傳回非字串類型的變數參照)
  • trigger_reference:這個值代表觸發條件,以觸發條件 ID 表示


可接受的值為:
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
  • "triggerReference"
可寫入
priority.type string 參數類型。有效值如下:
  • boolean:這個值代表布林值,以「true」或「false」表示
  • integer:這個值代表 64 位元的帶正負號整數值,以 10 為底數
  • list:應指定參數清單
  • map:應指定參數對應
  • template:此值代表任何文字,可能包含變數參照 (甚至是可能會傳回非字串類型的變數參照)
  • trigger_reference:這個值代表觸發條件,以觸發條件 ID 表示


可接受的值為:
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
  • "triggerReference"
可寫入
選用屬性
blockingRuleId[] list 封鎖規則 ID。如果清單中的任何規則評估結果為 true,代碼就不會觸發。 可寫入
blockingTriggerId[] list 封鎖觸發條件 ID。如果清單中的任何觸發條件評估結果為 true,代碼就不會觸發。 可寫入
firingRuleId[] list 觸發規則 ID。只要列出的規則為 true,且其所有 blockingRuleIds (如有指定) 皆為 false,標記就會觸發。 可寫入
firingTriggerId[] list 觸發條件 ID。如果列出的觸發條件其中一項為 true,blockingTriggerIds (如果有的話) 全都為 false,代碼就會觸發。 可寫入
liveOnly boolean 如果設為 true,這個代碼只會在實際環境中觸發 (例如在預覽或偵錯模式下)。 可寫入
notes string 使用者在容器中套用這個代碼的附註。 可寫入
parameter[] list 代碼的參數。 可寫入
parameter[].key string 唯一識別參數的已命名鍵。必須用於頂層參數和對應值。清單值會忽略。 可寫入
parameter[].list[] list 此清單參數的參數 (系統會忽略鍵)。 可寫入
parameter[].map[] list 此對應參數的參數 (必須有鍵,鍵不得重複)。 可寫入
parameter[].value string 適合指定類型的參數值 (可能包含「」等變數參照。 可寫入
paused boolean 如果代碼暫停,則為 True。 可寫入
priority nested object 使用者定義的代碼數字優先順序。代碼會按照優先順序以非同步方式觸發。數值較高的代碼會先觸發。標記的優先順序可以是正值或負值。預設值為 0。 可寫入
priority.key string 唯一識別參數的已命名鍵。必須用於頂層參數和對應值。清單值會忽略。 可寫入
priority.list[] list 此清單參數的參數 (系統會忽略鍵)。 可寫入
priority.map[] list 此對應參數的參數 (必須有鍵,鍵不得重複)。 可寫入
priority.value string 適合指定類型的參數值 (可能包含「」等變數參照。 可寫入
scheduleEndMs long 排定代碼的結束時間戳記 (以毫秒為單位)。 可寫入
scheduleStartMs long 排定代碼的開始時間戳記 (以毫秒為單位)。 可寫入
type string GTM 代碼類型。 可寫入

回應

如果成功,這個方法會在回應主體中傳回標記資源

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

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

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

// Construct the parameters.
Parameter arg0 = new Parameter();
arg0.setType("template");
arg0.setKey("trackingId");
arg0.setValue("UA-123456-1");

Parameter arg1 = new Parameter();
arg1.setType("template");
arg1.setKey("type");
arg1.setValue("TRACK_TRANSACTION");

// Construct the tag object.
Tag tag = new Tag();
tag.setName("Sample Universal Analytics");
tag.setType("ua");
tag.setLiveOnly(false);
tag.setParameter(Arrays.asList(arg0, arg1));

try {
  Tag response = tagmanager.accounts().
      containers().tags().update("123456", "54321", "1", tag).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 new container tag.
try:
  response = tagmanager.accounts().containers().tags().update(
      accountId='123456',
      containerId='54321',
      tagId='1',
      body={
          'name': 'Universal Analytics Tag',
          'type': 'ua',
          'liveOnly': False,
          'parameter': [
              {
                  'type': 'template',
                  'key': 'trackingId',
                  'value': 'UA-123456-1'
              },
              {
                  'type': 'template',
                  'key': 'type',
                  'value': 'TRACK_TRANSACTION'
              }
          ]
      }
  ).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')

試試看!

您可以使用下方的 APIs Explorer,針對即時資料呼叫這個方法,然後查看回應。