Variables: update

需要授權

更新 GTM 變數。 立即試用查看範例

要求

HTTP 要求

PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/variables/variableId

參數

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

授權

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

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

要求主體

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

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


可接受的值為:
  • "boolean"
  • "integer"
  • "list"
  • "map"
  • "template"
  • "triggerReference"
可寫入
type string GTM 變數類型。 可寫入
選用屬性
disablingTriggerId[] list 僅適用於行動容器:用於停用條件變數的觸發條件 ID 清單;如果其中一個啟用觸發條件為 True,但所有停用觸發條件都是 False,變數就會啟用。視為未排序的集合。 可寫入
enablingTriggerId[] list 僅適用於行動容器:用於啟用條件變數的觸發條件 ID 清單;如果其中一個啟用觸發條件為 True,但所有停用觸發條件皆為 false,變數就會啟用。視為未排序的集合。 可寫入
notes string 使用者說明如何在容器中套用這個變數。 可寫入
parameter[] list 變數的參數。 可寫入
parameter[].key string 唯一識別參數的已命名鍵。必須用於頂層參數和對應值。清單值會忽略。 可寫入
parameter[].list[] list 此清單參數的參數 (系統會忽略鍵)。 可寫入
parameter[].map[] list 此對應參數的參數 (必須有鍵,鍵不得重複)。 可寫入
parameter[].value string 適合指定類型的參數值 (可能包含「」等變數參照。 可寫入
scheduleEndMs long 安排變數的結束時間戳記 (以毫秒為單位)。 可寫入
scheduleStartMs long 安排變數的開始時間戳記 (以毫秒為單位)。 可寫入

回應

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

範例

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

Java

使用 Java 用戶端程式庫

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

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

// Create the variable object.
Variable variable = new Variable();
variable.setName("RandomNumber");
variable.setType("r"); // The random number type.

try {
  Variable response = tagmanager.accounts().containers().
      variables().update("12345", "54321", "2", variable).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 variable.
try:
  response = tagmanager.accounts().containers().variables().update(
      accountId='123456',
      containerId='54321',
      variableId='4',
      body={
          'name': 'updated_random_number',
          'type': 'r'
      }
  ).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,針對即時資料呼叫這個方法,然後查看回應。