Skip to main content
Glama

Google Ads & Meta Ads

Tag Manager: Create Variable

gtm_create_variable

Create one user-defined variable in a draft workspace of a Google Tag Manager container: a constant (e.g. a GA4 measurement id), a data layer variable (e.g. ecommerce.value), a URL part (e.g. the gclid query parameter), a first-party cookie, a global JavaScript variable, or a lookup table mapping one variable's values to outputs. Tags and triggers then reference it as {{Name}}. 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. Custom JavaScript variables are not created.

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>",
      "name": "<name>",
      "type": "<type>"
    },
    "name": "gtm_create_variable"
  }
}

Input Schema

NameRequiredDescriptionDefault
nameYesThe variable's name, unique in the container, e.g. "DL - Order Value". Tags reference it as {{name}}.
typeYesKind of variable: CONSTANT, DATA_LAYER, URL, COOKIE, JAVASCRIPT_VARIABLE or LOOKUP_TABLE.
notesNoNotes shown on the variable in Tag Manager. Optional.
valueNoCONSTANT: the constant's value.
containerNoThe 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_keyNoURL with url_component QUERY: the query parameter read, e.g. gclid.
workspaceYesThe 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_nameNoCOOKIE: the first-party cookie read.
lookup_rowsNoLOOKUP_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_inputNoLOOKUP_TABLE: the variable whose value is looked up, e.g. Page Hostname (with or without {{ }}).
decode_cookieNoCOOKIE: URI-decode the value. Default false.
default_valueNoDATA_LAYER or LOOKUP_TABLE: the value when the key is absent or no row matches. Optional.
url_componentNoURL: the part of the page URL: URL, PROTOCOL, HOST, PORT, PATH, QUERY, FRAGMENT.
data_layer_keyNoDATA_LAYER: the data layer key read, e.g. ecommerce.value or transactionId.
js_variable_nameNoJAVASCRIPT_VARIABLE: the global JavaScript variable read, e.g. window.dataLayerConfig.value (dot paths allowed).
data_layer_versionNoDATA_LAYER: 1 or 2 (default 2, the one with dot-path keys).

Output Schema

NameRequiredDescriptionDefault
kindYesCONSTANT, DATA_LAYER, URL, COOKIE, JAVASCRIPT_VARIABLE or LOOKUP_TABLE.
nameYesThe variable's name.
typeYesGoogle's type code: c, v, u, k, j or smm.
publicIdNoPublic GTM-XXXXXXX id of the container.
publishedYesAlways false: the change is a draft until a version is created and published.
parametersYesThe variable's parameters by key, values as text.
variableIdYesId of the new variable inside the container.
workspaceIdYesId of the workspace the change was saved in.
workspaceUrlYesWhere the user reviews, previews and publishes the workspace in Tag Manager.
containerNameYesThe container's name.
containerPathYesAPI path of the container, accounts/{a}/containers/{c}.
workspaceNameYesName of that workspace.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already say readOnly=false, destructive=false, idempotent=false, so the description's value is in the extra context it adds: the write lands only in a draft workspace, nothing is published, the user reviews and publishes in Tag Manager, and the connection needs editing enabled. What is missing is the failure behavior on duplicate names (the schema says names are unique) and any confirmation of what the response returns.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the action and packs the supported kinds plus the draft/not-published constraint into a compact block with no filler sentences. It is dense but readable; the workspace/publish sentence carves out slightly more space than needed for what it says.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 16-parameter write tool with an output schema, the description supplies everything an agent needs before calling it: where the object is saved, that it is a draft, that publishing is a separate human step, that editing permission is required, and which variable type is unsupported. Return values need not be explained because an output schema exists.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all 16 parameters are already documented, including per-type fields and the lookup_rows replace-on-update note. The description reinforces the type-to-field relationship only through loose examples (a GA4 measurement id for constants, ecommerce.value for data layer, gclid), which mostly duplicate schema examples, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Create one user-defined variable in a draft workspace of a Google Tag Manager container') and then enumerates the concrete variable kinds it supports (constant, data layer, URL part, cookie, JS variable, lookup table). The resource is clearly distinct from the tag/trigger creation siblings, and the 'no custom JavaScript' boundary is stated up front.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit operational guidance: 'Saved in the existing workspace the user names (ask which)' with the hard instruction never to publish, and a precondition that editing must be enabled on the connection. It also states an exclusion (Custom JavaScript variables are not created), so the agent knows when this tool is not the right fit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources