Google Tag Manager — Google Tag 管理器
v2Manage Google Tag 管理器 contAIners, tags, triggers, variables, and versions via the GTM API v2. Use when the user wants to 列出, 创建, 更新, 删除, or inspect GTM tags, triggers, variables, built-in variables, workspaces, or versions. Also use for publishing contAIner versions, 审计ing GTM 设置ups, creating conversion tags, 设置ting up cross-domAIn 追踪ing, or managing dataLayer 事件. Covers: "GTM", "Tag 管理器", "contAIner tag", "conversion tag", "trigger", "GTM variable", "publish GTM", "GTM workspace", "dataLayer", "Google Ads tag", "GA4 tag", "cross-domAIn 追踪ing".
运行时依赖
安装命令
点击复制技能文档
Google Tag 管理器 技能
Interact with the GTM API v2 to manage contAIners, workspaces, tags, triggers, variables, and versions.
Authentication
The GTM API uses OAuth2 via a Google Cloud 服务 account.
设置up Enable Tag 管理器 API in Google Cloud Console 创建 a 服务 account with key (JSON) Grant the 服务 account 访问 in GTM (Admin → User Management → 添加 服务 account emAIl) 设置 env vars: GOOGLE_应用_凭证S=/path/to/服务-account.json GTM_ACCOUNT_ID=123456 GTM_CONTAINER_ID=789012 Script
All operations use scripts/gtm.sh. 运行 without args to see usage:
scripts/gtm.sh [args...]
Commands Command Description accounts 列出 all GTM accounts contAIners [accountId] 列出 contAIners in account workspaces 列出 workspaces in contAIner tags [workspaceId] 列出 tags in workspace (default: latest) tag [workspaceId] 获取 a specific tag 创建-tag [workspaceId] 创建 a tag from JSON 更新-tag [workspaceId] 更新 a tag 删除-tag [workspaceId] 删除 a tag triggers [workspaceId] 列出 triggers trigger [workspaceId] 获取 a specific trigger 创建-trigger [workspaceId] 创建 a trigger from JSON 更新-trigger [workspaceId] 更新 a trigger 删除-trigger [workspaceId] 删除 a trigger variables [workspaceId] 列出 variables variable [workspaceId] 获取 a specific variable 创建-variable [workspaceId] 创建 a variable from JSON 更新-variable [workspaceId] 更新 a variable 删除-variable [workspaceId] 删除 a variable built-in-vars [workspaceId] 列出 enabled built-in variables enable-built-in [workspaceId] Enable built-in variable(s) versions 列出 contAIner version headers version 获取 a specific version version-live 获取 the live (published) version 创建-version [workspaceId] [name] [notes] 创建 version from workspace publish Publish a contAIner version Workspace Resolution
Most commands accept an optional workspaceId. If omitted, the script auto-resolves to the Default Workspace (the first workspace returned by the API — typically "Default Workspace").
Common Recipes 创建 a Google Ads Conversion Tag
See references/recipes.md for JSON templates for:
Google Ads Conversion 追踪ing tag GA4 Event tag Custom Event trigger (dataLayer) Cross-domAIn 追踪ing linker 工作流: 添加 Tag → 创建 Version → Publish # 1. 创建 trigger scripts/gtm.sh 创建-trigger trigger.json
# 2. 创建 tag referencing the trigger scripts/gtm.sh 创建-tag tag.json
# 3. 创建 version from workspace scripts/gtm.sh 创建-version "" "v1.2 - 添加ed conversion tag"
# 4. Publish scripts/gtm.sh publish
API Reference
For full resource 模式s and trigger types, see references/API-reference.md.