create_trigger
Create triggers in Google Tag Manager to track user interactions like page views, clicks, custom events, form submissions, scroll depth, element visibility, YouTube video engagement, and timed actions.
Instructions
新しいトリガーを作成します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | アカウントID | |
| containerId | Yes | コンテナID | |
| workspaceId | Yes | ワークスペースID | |
| name | Yes | トリガー名 | |
| type | Yes | トリガータイプ(例: "PAGEVIEW", "CLICK", "CUSTOM_EVENT", "linkClick"など) | |
| customEventFilter | No | カスタムイベントフィルタ(CUSTOM_EVENTタイプ用) | |
| filter | No | フィルタ(linkClick、clickなどのタイプ用) | |
| autoEventFilter | No | 自動イベントフィルタ(linkClickタイプ用) | |
| waitForTags | No | タグの待機を有効化(linkClickタイプ用) | |
| checkValidation | No | バリデーションチェック(linkClickタイプ用) | |
| waitForTagsTimeout | No | タグ待機タイムアウト(ミリ秒、linkClickタイプ用) | |
| formId | No | フォームID(formSubmissionタイプ用) | |
| formClasses | No | フォームクラス(formSubmissionタイプ用) | |
| verticalThreshold | No | 垂直スクロール閾値(パーセント、scrollDepthタイプ用) | |
| horizontalThreshold | No | 水平スクロール閾値(パーセント、scrollDepthタイプ用) | |
| selector | No | CSSセレクタ(elementVisibilityタイプ用) | |
| visiblePercentageThreshold | No | 表示割合閾値(パーセント、elementVisibilityタイプ用) | |
| continuousTimeMinMilliseconds | No | 連続表示時間(ミリ秒、elementVisibilityタイプ用) | |
| videoId | No | YouTube動画ID(youtubeVideoタイプ用) | |
| enableTriggerOnVideoStart | No | 動画開始時に発火(youtubeVideoタイプ用) | |
| enableTriggerOnVideoProgress | No | 動画再生中に発火(youtubeVideoタイプ用) | |
| enableTriggerOnVideoComplete | No | 動画完了時に発火(youtubeVideoタイプ用) | |
| enableTriggerOnVideoPause | No | 動画一時停止時に発火(youtubeVideoタイプ用) | |
| enableTriggerOnVideoSeek | No | 動画シーク時に発火(youtubeVideoタイプ用) | |
| interval | No | インターバル(ミリ秒、timerタイプ用) | |
| limit | No | 発火回数の上限(timerタイプ用) | |
| startTimerOn | No | タイマー開始タイミング(timerタイプ用、例: "windowLoad", "domReady") |
Implementation Reference
- src/index.js:558-680 (schema)Input schema definition for the create_trigger tool, including all parameters for different trigger types like filter, autoEventFilter, formId, etc.{ name: 'create_trigger', 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: 'トリガータイプ(例: "PAGEVIEW", "CLICK", "CUSTOM_EVENT", "linkClick"など)', }, 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', 'name', 'type'], }, },
- src/index.js:1162-1428 (handler)MCP tool handler for 'create_trigger'. Processes input arguments, applies type-specific configurations (e.g., filters for linkClick/formSubmission/youtubeVideo/etc.), constructs the triggerData object, and calls GTMClient.createTrigger to perform the API call.case 'create_trigger': { const triggerData = { name: args.name, type: args.type, }; // カスタムイベントフィルタ(CUSTOM_EVENTタイプ用) if (args.customEventFilter) { triggerData.customEventFilter = args.customEventFilter; } // フィルタ(linkClick、clickなどのタイプ用) if (args.filter) { // JSON文字列の場合は配列に変換 if (typeof args.filter === 'string') { try { triggerData.filter = JSON.parse(args.filter); } catch (e) { triggerData.filter = args.filter; } } else { triggerData.filter = args.filter; } } // 自動イベントフィルタ(linkClickタイプ用) if (args.autoEventFilter) { // JSON文字列の場合は配列に変換 if (typeof args.autoEventFilter === 'string') { try { triggerData.autoEventFilter = JSON.parse(args.autoEventFilter); } catch (e) { triggerData.autoEventFilter = args.autoEventFilter; } } else { triggerData.autoEventFilter = args.autoEventFilter; } } // タグ待機設定(linkClickタイプ用) if (args.waitForTags !== undefined) { triggerData.waitForTags = { type: 'boolean', value: String(args.waitForTags) }; } // バリデーションチェック(linkClickタイプ用) if (args.checkValidation !== undefined) { triggerData.checkValidation = { type: 'boolean', value: String(args.checkValidation) }; } // タグ待機タイムアウト(linkClickタイプ用) if (args.waitForTagsTimeout !== undefined) { triggerData.waitForTagsTimeout = { type: 'template', value: String(args.waitForTagsTimeout) }; } // formSubmission用 if (args.type === 'formSubmission') { triggerData.filter = []; if (args.formId) { triggerData.filter.push({ type: 'contains', parameter: [ { type: 'template', key: 'arg0', value: '{{Form ID}}' }, { type: 'template', key: 'arg1', value: args.formId } ] }); } if (args.formClasses) { triggerData.filter.push({ type: 'contains', parameter: [ { type: 'template', key: 'arg0', value: '{{Form Classes}}' }, { type: 'template', key: 'arg1', value: args.formClasses } ] }); } } // scrollDepth用 if (args.type === 'scrollDepth') { triggerData.parameter = [ { type: 'template', key: 'verticalThresholdUnits', value: 'PERCENT' }, { type: 'template', key: 'verticalThreshold', value: String(args.verticalThreshold || 25) } ]; if (args.horizontalThreshold !== undefined) { triggerData.parameter.push( { type: 'template', key: 'horizontalThresholdUnits', value: 'PERCENT' }, { type: 'template', key: 'horizontalThreshold', value: String(args.horizontalThreshold) } ); } } // elementVisibility用 if (args.type === 'visible' || args.type === 'elementVisibility') { triggerData.type = 'visible'; triggerData.parameter = [ { type: 'template', key: 'selector', value: args.selector || '' }, { type: 'template', key: 'visiblePercentageThreshold', value: String(args.visiblePercentageThreshold || 50) }, { type: 'template', key: 'continuousTimeMinMilliseconds', value: String(args.continuousTimeMinMilliseconds || 0) } ]; } // youtubeVideo用 if (args.type === 'youtubeVideo') { triggerData.parameter = [ { type: 'template', key: 'enableTriggerOnVideoStart', value: String(args.enableTriggerOnVideoStart || false) }, { type: 'template', key: 'enableTriggerOnVideoProgress', value: String(args.enableTriggerOnVideoProgress || false) }, { type: 'template', key: 'enableTriggerOnVideoComplete', value: String(args.enableTriggerOnVideoComplete || false) }, { type: 'template', key: 'enableTriggerOnVideoPause', value: String(args.enableTriggerOnVideoPause || false) }, { type: 'template', key: 'enableTriggerOnVideoSeek', value: String(args.enableTriggerOnVideoSeek || false) } ]; if (args.videoId) { triggerData.filter = [ { type: 'equals', parameter: [ { type: 'template', key: 'arg0', value: '{{Video ID}}' }, { type: 'template', key: 'arg1', value: args.videoId } ] } ]; } } // timer用 if (args.type === 'timer') { triggerData.parameter = [ { type: 'template', key: 'interval', value: String(args.interval || 1000) }, { type: 'template', key: 'limit', value: String(args.limit || 1) }, { type: 'template', key: 'startTimerOn', value: args.startTimerOn || 'windowLoad' } ]; } // linkClickタイプの場合、waitForTags、checkValidation、waitForTagsTimeoutが未設定の場合はデフォルト値を設定 if (triggerData.type === 'linkClick') { if (triggerData.waitForTags === undefined) { triggerData.waitForTags = { type: 'template' }; } if (triggerData.checkValidation === undefined) { triggerData.checkValidation = { type: 'template' }; } if (triggerData.waitForTagsTimeout === undefined) { triggerData.waitForTagsTimeout = { type: 'template' }; } if (!triggerData.uniqueTriggerId) { triggerData.uniqueTriggerId = { type: 'template' }; } } return { content: [ { type: 'text', text: JSON.stringify( await this.gtmClient.createTrigger( args.accountId, args.containerId, args.workspaceId, triggerData ), null, 2 ), }, ], }; }
- src/gtm-client.js:212-220 (helper)Core implementation in GTMClient that makes the actual Google Tag Manager API call to create the trigger using the googleapis library.*/ async createTrigger(accountId, containerId, workspaceId, triggerData) { await this.ensureAuth(); const response = await this.tagmanager.accounts.containers.workspaces.triggers.create({ parent: `accounts/${accountId}/containers/${containerId}/workspaces/${workspaceId}`, requestBody: triggerData }); return response.data; }