Skip to main content
Glama
ambit1977

Google Tag Manager MCP Server

by ambit1977

update_trigger

Modify existing triggers in Google Tag Manager by updating settings like filters, event conditions, and timing parameters to refine when tags fire.

Instructions

既存のトリガーを更新します。filter、autoEventFilter、waitForTagsなどのすべての設定を更新できます。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesアカウントID
containerIdYesコンテナID
workspaceIdYesワークスペースID
triggerIdYesトリガーID
nameNoトリガー名
typeNoトリガータイプ
customEventFilterNoカスタムイベントフィルタ(CUSTOM_EVENTタイプ用)
filterNoフィルタ(linkClick、clickなどのタイプ用)
autoEventFilterNo自動イベントフィルタ(linkClickタイプ用)
waitForTagsNoタグの待機を有効化(linkClickタイプ用)
checkValidationNoバリデーションチェック(linkClickタイプ用)
waitForTagsTimeoutNoタグ待機タイムアウト(ミリ秒、linkClickタイプ用)
formIdNoフォームID(formSubmissionタイプ用)
formClassesNoフォームクラス(formSubmissionタイプ用)
verticalThresholdNo垂直スクロール閾値(パーセント、scrollDepthタイプ用)
horizontalThresholdNo水平スクロール閾値(パーセント、scrollDepthタイプ用)
selectorNoCSSセレクタ(elementVisibilityタイプ用)
visiblePercentageThresholdNo表示割合閾値(パーセント、elementVisibilityタイプ用)
continuousTimeMinMillisecondsNo連続表示時間(ミリ秒、elementVisibilityタイプ用)
videoIdNoYouTube動画ID(youtubeVideoタイプ用)
enableTriggerOnVideoStartNo動画開始時に発火(youtubeVideoタイプ用)
enableTriggerOnVideoProgressNo動画再生中に発火(youtubeVideoタイプ用)
enableTriggerOnVideoCompleteNo動画完了時に発火(youtubeVideoタイプ用)
enableTriggerOnVideoPauseNo動画一時停止時に発火(youtubeVideoタイプ用)
enableTriggerOnVideoSeekNo動画シーク時に発火(youtubeVideoタイプ用)
intervalNoインターバル(ミリ秒、timerタイプ用)
limitNo発火回数の上限(timerタイプ用)
startTimerOnNoタイマー開始タイミング(timerタイプ用、例: "windowLoad", "domReady")

Implementation Reference

  • MCP tool handler for 'update_trigger'. Fetches existing trigger data, merges with provided arguments handling special logic for different trigger types (e.g., formSubmission, scrollDepth), preserves fingerprint, and calls GTMClient.updateTrigger to perform the API update.
    case 'update_trigger': {
      // 既存のトリガーデータを取得
      const existingTrigger = await this.gtmClient.getTrigger(
        args.accountId,
        args.containerId,
        args.workspaceId,
        args.triggerId
      );
    
      // 更新データを構築(指定されたパラメータで上書き)
      const triggerData = {
        name: args.name !== undefined ? args.name : existingTrigger.name,
        type: args.type !== undefined ? args.type : existingTrigger.type,
      };
    
      // カスタムイベントフィルタ
      if (args.customEventFilter !== undefined) {
        triggerData.customEventFilter = args.customEventFilter;
      } else if (existingTrigger.customEventFilter) {
        triggerData.customEventFilter = existingTrigger.customEventFilter;
      }
    
      // フィルタ
      if (args.filter !== undefined) {
        triggerData.filter = args.filter;
      } else if (existingTrigger.filter) {
        triggerData.filter = existingTrigger.filter;
      }
    
      // 自動イベントフィルタ
      if (args.autoEventFilter !== undefined) {
        triggerData.autoEventFilter = args.autoEventFilter;
      } else if (existingTrigger.autoEventFilter) {
        triggerData.autoEventFilter = existingTrigger.autoEventFilter;
      }
    
      // タグ待機設定
      if (args.waitForTags !== undefined) {
        triggerData.waitForTags = {
          type: 'boolean',
          value: args.waitForTags
        };
      } else if (existingTrigger.waitForTags) {
        triggerData.waitForTags = existingTrigger.waitForTags;
      }
    
      // バリデーションチェック
      if (args.checkValidation !== undefined) {
        triggerData.checkValidation = {
          type: 'boolean',
          value: args.checkValidation
        };
      } else if (existingTrigger.checkValidation) {
        triggerData.checkValidation = existingTrigger.checkValidation;
      }
    
      // タグ待機タイムアウト
      if (args.waitForTagsTimeout !== undefined) {
        triggerData.waitForTagsTimeout = {
          type: 'template',
          value: String(args.waitForTagsTimeout)
        };
      } else if (existingTrigger.waitForTagsTimeout) {
        triggerData.waitForTagsTimeout = existingTrigger.waitForTagsTimeout;
      }
    
      // formSubmission用の処理
      if (triggerData.type === 'formSubmission') {
        if (args.formId !== undefined || args.formClasses !== undefined) {
          triggerData.filter = [];
          if (args.formId !== undefined) {
            triggerData.filter.push({
              type: 'contains',
              parameter: [
                {
                  type: 'template',
                  key: 'arg0',
                  value: '{{Form ID}}'
                },
                {
                  type: 'template',
                  key: 'arg1',
                  value: args.formId
                }
              ]
            });
          } else if (existingTrigger.filter) {
            // 既存のForm IDフィルタを保持
            const formIdFilter = existingTrigger.filter.find(f => 
              f.parameter?.some(p => p.value === '{{Form ID}}')
            );
            if (formIdFilter) {
              triggerData.filter.push(formIdFilter);
            }
          }
          if (args.formClasses !== undefined) {
            triggerData.filter.push({
              type: 'contains',
              parameter: [
                {
                  type: 'template',
                  key: 'arg0',
                  value: '{{Form Classes}}'
                },
                {
                  type: 'template',
                  key: 'arg1',
                  value: args.formClasses
                }
              ]
            });
          } else if (existingTrigger.filter) {
            // 既存のForm Classesフィルタを保持
            const formClassesFilter = existingTrigger.filter.find(f => 
              f.parameter?.some(p => p.value === '{{Form Classes}}')
            );
            if (formClassesFilter) {
              triggerData.filter.push(formClassesFilter);
            }
          }
        } else if (existingTrigger.filter) {
          triggerData.filter = existingTrigger.filter;
        }
      }
    
      // scrollDepth用の処理
      if (triggerData.type === 'scrollDepth') {
        if (args.verticalThreshold !== undefined || args.horizontalThreshold !== undefined) {
          triggerData.parameter = [
            {
              type: 'template',
              key: 'verticalThresholdUnits',
              value: 'PERCENT'
            },
            {
              type: 'template',
              key: 'verticalThreshold',
              value: String(args.verticalThreshold !== undefined ? args.verticalThreshold : 
                (existingTrigger.parameter?.find(p => p.key === 'verticalThreshold')?.value || 25))
            }
          ];
          if (args.horizontalThreshold !== undefined) {
            triggerData.parameter.push(
              {
                type: 'template',
                key: 'horizontalThresholdUnits',
                value: 'PERCENT'
              },
              {
                type: 'template',
                key: 'horizontalThreshold',
                value: String(args.horizontalThreshold)
              }
            );
          } else if (existingTrigger.parameter) {
            const horizontalThreshold = existingTrigger.parameter.find(p => p.key === 'horizontalThreshold');
            if (horizontalThreshold) {
              triggerData.parameter.push(
                {
                  type: 'template',
                  key: 'horizontalThresholdUnits',
                  value: 'PERCENT'
                },
                horizontalThreshold
              );
            }
          }
        } else if (existingTrigger.parameter) {
          triggerData.parameter = existingTrigger.parameter;
        }
      }
    
      // elementVisibility用の処理
      if (triggerData.type === 'visible' || triggerData.type === 'elementVisibility') {
        triggerData.type = 'visible';
        if (args.selector !== undefined || args.visiblePercentageThreshold !== undefined || args.continuousTimeMinMilliseconds !== undefined) {
          triggerData.parameter = [
            {
              type: 'template',
              key: 'selector',
              value: args.selector !== undefined ? args.selector : 
                (existingTrigger.parameter?.find(p => p.key === 'selector')?.value || '')
            },
            {
              type: 'template',
              key: 'visiblePercentageThreshold',
              value: String(args.visiblePercentageThreshold !== undefined ? args.visiblePercentageThreshold :
                (existingTrigger.parameter?.find(p => p.key === 'visiblePercentageThreshold')?.value || 50))
            },
            {
              type: 'template',
              key: 'continuousTimeMinMilliseconds',
              value: String(args.continuousTimeMinMilliseconds !== undefined ? args.continuousTimeMinMilliseconds :
                (existingTrigger.parameter?.find(p => p.key === 'continuousTimeMinMilliseconds')?.value || 0))
            }
          ];
        } else if (existingTrigger.parameter) {
          triggerData.parameter = existingTrigger.parameter;
        }
      }
    
      // youtubeVideo用の処理
      if (triggerData.type === 'youtubeVideo') {
        if (args.enableTriggerOnVideoStart !== undefined || args.enableTriggerOnVideoProgress !== undefined ||
            args.enableTriggerOnVideoComplete !== undefined || args.enableTriggerOnVideoPause !== undefined ||
            args.enableTriggerOnVideoSeek !== undefined || args.videoId !== undefined) {
          triggerData.parameter = [
            {
              type: 'template',
              key: 'enableTriggerOnVideoStart',
              value: String(args.enableTriggerOnVideoStart !== undefined ? args.enableTriggerOnVideoStart :
                (existingTrigger.parameter?.find(p => p.key === 'enableTriggerOnVideoStart')?.value || false))
            },
            {
              type: 'template',
              key: 'enableTriggerOnVideoProgress',
              value: String(args.enableTriggerOnVideoProgress !== undefined ? args.enableTriggerOnVideoProgress :
                (existingTrigger.parameter?.find(p => p.key === 'enableTriggerOnVideoProgress')?.value || false))
            },
            {
              type: 'template',
              key: 'enableTriggerOnVideoComplete',
              value: String(args.enableTriggerOnVideoComplete !== undefined ? args.enableTriggerOnVideoComplete :
                (existingTrigger.parameter?.find(p => p.key === 'enableTriggerOnVideoComplete')?.value || false))
            },
            {
              type: 'template',
              key: 'enableTriggerOnVideoPause',
              value: String(args.enableTriggerOnVideoPause !== undefined ? args.enableTriggerOnVideoPause :
                (existingTrigger.parameter?.find(p => p.key === 'enableTriggerOnVideoPause')?.value || false))
            },
            {
              type: 'template',
              key: 'enableTriggerOnVideoSeek',
              value: String(args.enableTriggerOnVideoSeek !== undefined ? args.enableTriggerOnVideoSeek :
                (existingTrigger.parameter?.find(p => p.key === 'enableTriggerOnVideoSeek')?.value || false))
            }
          ];
          if (args.videoId !== undefined) {
            triggerData.filter = [
              {
                type: 'equals',
                parameter: [
                  {
                    type: 'template',
                    key: 'arg0',
                    value: '{{Video ID}}'
                  },
                  {
                    type: 'template',
                    key: 'arg1',
                    value: args.videoId
                  }
                ]
              }
            ];
          } else if (existingTrigger.filter) {
            triggerData.filter = existingTrigger.filter;
          }
        } else {
          if (existingTrigger.parameter) {
            triggerData.parameter = existingTrigger.parameter;
          }
          if (existingTrigger.filter) {
            triggerData.filter = existingTrigger.filter;
          }
        }
      }
    
      // timer用の処理
      if (triggerData.type === 'timer') {
        if (args.interval !== undefined || args.limit !== undefined || args.startTimerOn !== undefined) {
          triggerData.parameter = [
            {
              type: 'template',
              key: 'interval',
              value: String(args.interval !== undefined ? args.interval :
                (existingTrigger.parameter?.find(p => p.key === 'interval')?.value || 1000))
            },
            {
              type: 'template',
              key: 'limit',
              value: String(args.limit !== undefined ? args.limit :
                (existingTrigger.parameter?.find(p => p.key === 'limit')?.value || 1))
            },
            {
              type: 'template',
              key: 'startTimerOn',
              value: args.startTimerOn !== undefined ? args.startTimerOn :
                (existingTrigger.parameter?.find(p => p.key === 'startTimerOn')?.value || 'windowLoad')
            }
          ];
        } else if (existingTrigger.parameter) {
          triggerData.parameter = existingTrigger.parameter;
        }
      }
    
      // その他のタイプのパラメータを保持
      if (!triggerData.parameter && existingTrigger.parameter) {
        triggerData.parameter = existingTrigger.parameter;
      }
    
      // fingerprintを保持(更新に必要)
      if (existingTrigger.fingerprint) {
        triggerData.fingerprint = existingTrigger.fingerprint;
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(
              await this.gtmClient.updateTrigger(
                args.accountId,
                args.containerId,
                args.workspaceId,
                args.triggerId,
                triggerData
              ),
              null,
              2
            ),
          },
        ],
      };
    }
  • Input schema definition for the 'update_trigger' tool, defining parameters for GTM trigger update including IDs and type-specific configurations.
    inputSchema: {
      type: 'object',
      properties: {
        accountId: {
          type: 'string',
          description: 'アカウントID',
        },
        containerId: {
          type: 'string',
          description: 'コンテナID',
        },
        workspaceId: {
          type: 'string',
          description: 'ワークスペースID',
        },
        triggerId: {
          type: 'string',
          description: 'トリガーID',
        },
        name: {
          type: 'string',
          description: 'トリガー名',
        },
        type: {
          type: 'string',
          description: 'トリガータイプ',
        },
        customEventFilter: {
          type: 'array',
          description: 'カスタムイベントフィルタ(CUSTOM_EVENTタイプ用)',
        },
        filter: {
          type: 'array',
          description: 'フィルタ(linkClick、clickなどのタイプ用)',
        },
        autoEventFilter: {
          type: 'array',
          description: '自動イベントフィルタ(linkClickタイプ用)',
        },
        waitForTags: {
          type: 'boolean',
          description: 'タグの待機を有効化(linkClickタイプ用)',
        },
        checkValidation: {
          type: 'boolean',
          description: 'バリデーションチェック(linkClickタイプ用)',
        },
        waitForTagsTimeout: {
          type: 'number',
          description: 'タグ待機タイムアウト(ミリ秒、linkClickタイプ用)',
        },
        // formSubmission用
        formId: {
          type: 'string',
          description: 'フォームID(formSubmissionタイプ用)',
        },
        formClasses: {
          type: 'string',
          description: 'フォームクラス(formSubmissionタイプ用)',
        },
        // scrollDepth用
        verticalThreshold: {
          type: 'number',
          description: '垂直スクロール閾値(パーセント、scrollDepthタイプ用)',
        },
        horizontalThreshold: {
          type: 'number',
          description: '水平スクロール閾値(パーセント、scrollDepthタイプ用)',
        },
        // elementVisibility用
        selector: {
          type: 'string',
          description: 'CSSセレクタ(elementVisibilityタイプ用)',
        },
        visiblePercentageThreshold: {
          type: 'number',
          description: '表示割合閾値(パーセント、elementVisibilityタイプ用)',
        },
        continuousTimeMinMilliseconds: {
          type: 'number',
          description: '連続表示時間(ミリ秒、elementVisibilityタイプ用)',
        },
        // youtubeVideo用
        videoId: {
          type: 'string',
          description: 'YouTube動画ID(youtubeVideoタイプ用)',
        },
        enableTriggerOnVideoStart: {
          type: 'boolean',
          description: '動画開始時に発火(youtubeVideoタイプ用)',
        },
        enableTriggerOnVideoProgress: {
          type: 'boolean',
          description: '動画再生中に発火(youtubeVideoタイプ用)',
        },
        enableTriggerOnVideoComplete: {
          type: 'boolean',
          description: '動画完了時に発火(youtubeVideoタイプ用)',
        },
        enableTriggerOnVideoPause: {
          type: 'boolean',
          description: '動画一時停止時に発火(youtubeVideoタイプ用)',
        },
        enableTriggerOnVideoSeek: {
          type: 'boolean',
          description: '動画シーク時に発火(youtubeVideoタイプ用)',
        },
        // timer用
        interval: {
          type: 'number',
          description: 'インターバル(ミリ秒、timerタイプ用)',
        },
        limit: {
          type: 'number',
          description: '発火回数の上限(timerタイプ用)',
        },
        startTimerOn: {
          type: 'string',
          description: 'タイマー開始タイミング(timerタイプ用、例: "windowLoad", "domReady")',
        },
      },
      required: ['accountId', 'containerId', 'workspaceId', 'triggerId'],
    },
  • src/index.js:405-531 (registration)
    Tool registration in the ListToolsRequest handler, defining name, description, and schema for 'update_trigger'.
    {
      name: 'update_trigger',
      description: '既存のトリガーを更新します。filter、autoEventFilter、waitForTagsなどのすべての設定を更新できます。',
      inputSchema: {
        type: 'object',
        properties: {
          accountId: {
            type: 'string',
            description: 'アカウントID',
          },
          containerId: {
            type: 'string',
            description: 'コンテナID',
          },
          workspaceId: {
            type: 'string',
            description: 'ワークスペースID',
          },
          triggerId: {
            type: 'string',
            description: 'トリガーID',
          },
          name: {
            type: 'string',
            description: 'トリガー名',
          },
          type: {
            type: 'string',
            description: 'トリガータイプ',
          },
          customEventFilter: {
            type: 'array',
            description: 'カスタムイベントフィルタ(CUSTOM_EVENTタイプ用)',
          },
          filter: {
            type: 'array',
            description: 'フィルタ(linkClick、clickなどのタイプ用)',
          },
          autoEventFilter: {
            type: 'array',
            description: '自動イベントフィルタ(linkClickタイプ用)',
          },
          waitForTags: {
            type: 'boolean',
            description: 'タグの待機を有効化(linkClickタイプ用)',
          },
          checkValidation: {
            type: 'boolean',
            description: 'バリデーションチェック(linkClickタイプ用)',
          },
          waitForTagsTimeout: {
            type: 'number',
            description: 'タグ待機タイムアウト(ミリ秒、linkClickタイプ用)',
          },
          // formSubmission用
          formId: {
            type: 'string',
            description: 'フォームID(formSubmissionタイプ用)',
          },
          formClasses: {
            type: 'string',
            description: 'フォームクラス(formSubmissionタイプ用)',
          },
          // scrollDepth用
          verticalThreshold: {
            type: 'number',
            description: '垂直スクロール閾値(パーセント、scrollDepthタイプ用)',
          },
          horizontalThreshold: {
            type: 'number',
            description: '水平スクロール閾値(パーセント、scrollDepthタイプ用)',
          },
          // elementVisibility用
          selector: {
            type: 'string',
            description: 'CSSセレクタ(elementVisibilityタイプ用)',
          },
          visiblePercentageThreshold: {
            type: 'number',
            description: '表示割合閾値(パーセント、elementVisibilityタイプ用)',
          },
          continuousTimeMinMilliseconds: {
            type: 'number',
            description: '連続表示時間(ミリ秒、elementVisibilityタイプ用)',
          },
          // youtubeVideo用
          videoId: {
            type: 'string',
            description: 'YouTube動画ID(youtubeVideoタイプ用)',
          },
          enableTriggerOnVideoStart: {
            type: 'boolean',
            description: '動画開始時に発火(youtubeVideoタイプ用)',
          },
          enableTriggerOnVideoProgress: {
            type: 'boolean',
            description: '動画再生中に発火(youtubeVideoタイプ用)',
          },
          enableTriggerOnVideoComplete: {
            type: 'boolean',
            description: '動画完了時に発火(youtubeVideoタイプ用)',
          },
          enableTriggerOnVideoPause: {
            type: 'boolean',
            description: '動画一時停止時に発火(youtubeVideoタイプ用)',
          },
          enableTriggerOnVideoSeek: {
            type: 'boolean',
            description: '動画シーク時に発火(youtubeVideoタイプ用)',
          },
          // timer用
          interval: {
            type: 'number',
            description: 'インターバル(ミリ秒、timerタイプ用)',
          },
          limit: {
            type: 'number',
            description: '発火回数の上限(timerタイプ用)',
          },
          startTimerOn: {
            type: 'string',
            description: 'タイマー開始タイミング(timerタイプ用、例: "windowLoad", "domReady")',
          },
        },
        required: ['accountId', 'containerId', 'workspaceId', 'triggerId'],
      },
    },
  • GTMClient helper method that performs the actual Google Tag Manager API update for a trigger using the googleapis library.
    async updateTrigger(accountId, containerId, workspaceId, triggerId, triggerData) {
      await this.ensureAuth();
      const response = await this.tagmanager.accounts.containers.workspaces.triggers.update({
        path: `accounts/${accountId}/containers/${containerId}/workspaces/${workspaceId}/triggers/${triggerId}`,
        requestBody: triggerData
      });
      return response.data;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'update' implies a mutation operation, the description doesn't address critical behavioral aspects: whether this requires specific permissions, if changes are reversible, what happens to unspecified fields, error conditions, or rate limits. It mentions what CAN be updated but not HOW the update behaves.

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?

The description is appropriately concise - a single sentence that gets straight to the point. It's front-loaded with the core purpose and provides examples of updatable settings. However, the 'etc.' at the end is slightly vague, and the structure could be improved with clearer separation between purpose and capability examples.

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 complex mutation tool with 28 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what constitutes a successful update, error responses, side effects, or dependencies between parameters. The agent lacks crucial context about how this operation behaves in practice despite the comprehensive parameter documentation.

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 28 parameters thoroughly. The description adds minimal value by mentioning 'filter, autoEventFilter, waitForTags, etc.' as examples of updatable settings, but this doesn't provide semantic context beyond what's in the parameter descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('update') and resource ('existing trigger'), making the purpose understandable. It distinguishes from siblings like 'create_trigger' by specifying it updates existing triggers rather than creating new ones. However, it doesn't explicitly differentiate from other update tools like 'update_tag' or 'update_variable' 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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (like needing an existing trigger ID), when-not-to-use scenarios, or how it differs from other update operations. The agent must infer usage from the tool name alone.

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