Skip to main content
Glama
ambit1977

Google Tag Manager MCP Server

by ambit1977

create_variable

Create custom variables in Google Tag Manager to track and store data for tags and triggers. Define variables like constants, data layer values, JavaScript, DOM elements, cookies, URLs, or built-in variables to capture and reuse data across your GTM implementation.

Instructions

新しい変数を作成します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesアカウントID
containerIdYesコンテナID
workspaceIdYesワークスペースID
nameYes変数名
typeYes変数タイプ(例: "c"=定数, "v"=データレイヤー, "j"=JavaScript, "d"=DOM要素, "k"=Cookie, "u"=URL, "ae"=自動イベント, "b"=組み込み変数など)
parameterNo変数のパラメータ配列。タイプに応じて必要なパラメータを設定してください。

Implementation Reference

  • The core handler function that executes the tool logic by calling the Google Tag Manager API to create a new variable in the specified workspace.
    async createVariable(accountId, containerId, workspaceId, variableData) {
      await this.ensureAuth();
      const response = await this.tagmanager.accounts.containers.workspaces.variables.create({
        parent: `accounts/${accountId}/containers/${containerId}/workspaces/${workspaceId}`,
        requestBody: variableData
      });
      return response.data;
    }
  • The input schema definition for the create_variable tool, specifying parameters like accountId, containerId, workspaceId, name, type, and parameter.
      name: 'create_variable',
      description: '新しい変数を作成します',
      inputSchema: {
        type: 'object',
        properties: {
          accountId: {
            type: 'string',
            description: 'アカウントID',
          },
          containerId: {
            type: 'string',
            description: 'コンテナID',
          },
          workspaceId: {
            type: 'string',
            description: 'ワークスペースID',
          },
          name: {
            type: 'string',
            description: '変数名',
          },
          type: {
            type: 'string',
            description: '変数タイプ(例: "c"=定数, "v"=データレイヤー, "j"=JavaScript, "d"=DOM要素, "k"=Cookie, "u"=URL, "ae"=自動イベント, "b"=組み込み変数など)',
          },
          parameter: {
            type: 'array',
            description: '変数のパラメータ配列。タイプに応じて必要なパラメータを設定してください。',
          },
        },
        required: ['accountId', 'containerId', 'workspaceId', 'name', 'type'],
      },
    },
  • src/index.js:1832-1853 (registration)
    The registration and dispatch logic in the CallToolRequestSchema handler that maps the tool call to gtmClient.createVariable.
    case 'create_variable':
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(
              await this.gtmClient.createVariable(
                args.accountId,
                args.containerId,
                args.workspaceId,
                {
                  name: args.name,
                  type: args.type,
                  parameter: args.parameter || [],
                }
              ),
              null,
              2
            ),
          },
        ],
      };
  • Helper templates for creating common variable configurations (e.g., dataLayer, JavaScript, DOM Element) used to build the parameter array for create_variable.
    export const VariableTemplates = {
      // データレイヤー変数
      dataLayer: (dataLayerVariable, dataLayerVersion = 2) => ({
        type: 'v',
        parameter: [
          {
            type: 'template',
            key: 'dataLayerVersion',
            value: String(dataLayerVersion)
          },
          {
            type: 'template',
            key: 'dataLayerVariable',
            value: dataLayerVariable
          }
        ]
      }),
    
      // JavaScript変数
      javascript: (javascriptCode) => ({
        type: 'j',
        parameter: [
          {
            type: 'template',
            key: 'javascript',
            value: javascriptCode
          }
        ]
      }),
    
      // DOM要素変数
      domElement: (selector, attributeName = null) => {
        const params = [
          {
            type: 'template',
            key: 'selector',
            value: selector
          },
          {
            type: 'template',
            key: 'attributeName',
            value: attributeName || ''
          }
        ];
        return {
          type: 'd',
          parameter: params
        };
      },
    
      // 1st Party Cookie変数
      cookie: (cookieName) => ({
        type: 'k',
        parameter: [
          {
            type: 'template',
            key: 'cookieName',
            value: cookieName
          }
        ]
      }),
    
      // URL変数
      url: (componentType = 1, queryKey = '') => ({
        type: 'u',
        parameter: [
          {
            type: 'integer',
            key: 'componentType',
            value: componentType
          },
          {
            type: 'template',
            key: 'queryKey',
            value: queryKey
          }
        ]
      }),
    
      // 定数変数
      constant: (value) => ({
        type: 'c',
        parameter: [
          {
            type: 'template',
            key: 'value',
            value: value
          }
        ]
      }),
    
      // 自動イベント変数
      autoEvent: (variableType) => ({
        type: 'ae',
        parameter: [
          {
            type: 'template',
            key: 'variableType',
            value: variableType
          }
        ]
      }),
    
      // 組み込み変数(有効化のみ)
      builtIn: (variableType) => ({
        type: 'b',
        parameter: [
          {
            type: 'template',
            key: 'variableType',
            value: variableType
          }
        ]
      })
    };
Behavior2/5

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

With no annotations, the description carries full burden but only states the action without behavioral details. It doesn't disclose whether this is a write operation (implied by 'create'), what permissions are needed, how errors are handled, or what the response looks like (no output schema). This leaves significant gaps for a mutation tool.

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

Conciseness5/5

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

The description is a single, efficient sentence in Japanese ('新しい変数を作成します'), which is appropriately sized and front-loaded with the core action. There's no wasted text or unnecessary elaboration.

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

Completeness2/5

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

For a mutation tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It lacks context on the domain (e.g., Google Tag Manager variables), behavioral traits, usage scenarios, or expected outcomes, making it inadequate for safe and effective use by an AI agent.

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 the schema already documents all 6 parameters thoroughly (e.g., 'type' includes examples like 'c' for constant). The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage.

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

Purpose3/5

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

The description '新しい変数を作成します' (creates a new variable) clearly states the verb+resource action, but it's vague about what kind of variable is being created (e.g., for Google Tag Manager, as implied by sibling tools). It doesn't distinguish from sibling tools like 'create_tag' or 'create_trigger' beyond the resource name.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., authentication, account/container/workspace setup) or differentiate from similar tools like 'update_variable' or 'delete_variable' in the sibling list.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ambit1977/GTM-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server