Tag Manager: Update Variable
gtm_update_variableChange one existing user-defined variable of a Google Tag Manager container in a draft workspace: a constant's value, a data layer variable's key or default, a URL variable's component or query key, a cookie's name, a JavaScript variable's name, a lookup table's input and rows, or any variable's name and notes. The variable's kind cannot change; only the arguments passed change. Saved in the existing workspace the user names (ask which) and NOT published: the user reviews and publishes in Tag Manager. Requires editing to be enabled on the Tag Manager connection.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"workspace": "<workspace>",
"variable": "<variable>"
},
"name": "gtm_update_variable"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notes | No | Replaces the notes on the variable. Optional. | |
| value | No | CONSTANT: the constant's value. | |
| new_name | No | A new name for the variable. Tags referencing the old {{name}} are not rewritten. Optional. | |
| variable | Yes | The variable to change: its name or id, as gtm_list_triggers_variables shows them. | |
| container | No | The container: its public id (GTM-XXXXXXX), its name, or its API path from gtm_list_containers. May be left out when the connected login reaches exactly one container. | |
| query_key | No | URL with url_component QUERY: the query parameter read, e.g. gclid. | |
| workspace | Yes | The existing Tag Manager workspace to save the draft in, by name or id, as the user named it (gtm_list_workspaces). Ask the user which workspace to use; never pick one yourself. Nothing is published. | |
| cookie_name | No | COOKIE: the first-party cookie read. | |
| lookup_rows | No | LOOKUP_TABLE: rows as input value → output value, e.g. {"shop.example.com": "G-AAAA", "blog.example.com": "G-BBBB"}. Replaces the whole table on update. | |
| lookup_input | No | LOOKUP_TABLE: the variable whose value is looked up, e.g. Page Hostname (with or without {{ }}). | |
| decode_cookie | No | COOKIE: URI-decode the value. Default false. | |
| default_value | No | DATA_LAYER or LOOKUP_TABLE: the value when the key is absent or no row matches. Optional. | |
| url_component | No | URL: the part of the page URL: URL, PROTOCOL, HOST, PORT, PATH, QUERY, FRAGMENT. | |
| data_layer_key | No | DATA_LAYER: the data layer key read, e.g. ecommerce.value or transactionId. | |
| js_variable_name | No | JAVASCRIPT_VARIABLE: the global JavaScript variable read, e.g. window.dataLayerConfig.value (dot paths allowed). | |
| data_layer_version | No | DATA_LAYER: 1 or 2 (default 2, the one with dot-path keys). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The variable's name after the change. | |
| type | No | Google's type code, e.g. c or v. | |
| changed | Yes | The arguments that were applied. | |
| publicId | No | Public GTM-XXXXXXX id of the container. | |
| published | Yes | Always false: the change is a draft until a version is created and published. | |
| parameters | Yes | The variable's parameters by key after the change, values as text. | |
| variableId | Yes | Id of the variable inside the container. | |
| workspaceId | Yes | Id of the workspace the change was saved in. | |
| workspaceUrl | Yes | Where the user reviews, previews and publishes the workspace in Tag Manager. | |
| containerName | Yes | The container's name. | |
| containerPath | Yes | API path of the container, accounts/{a}/containers/{c}. | |
| workspaceName | Yes | Name of that workspace. |