Open Source CLI Tool

Manage GTM from your terminal

GTM CLI is a powerful command-line interface that gives you complete control over Google Tag Manager. Perfect for automation, CI/CD pipelines, and power users who live in the terminal.

Built for AI agents.
JSON output that LLMs can parse and act on.
CI/CD ready.
Automate GTM as part of your deployment pipeline.
Full API coverage.
Tags, triggers, variables, versions, environments, and more.

Install & get started in seconds:

curl -fsSL https://raw.githubusercontent.com/owntag/gtm-cli/main/install.sh | bash
~/projects β€” gtm-cli
❯ gtm

  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—     β–ˆβ–ˆβ•—
 β–ˆβ–ˆβ•”β•β•β•β•β• β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘
 β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘
 β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘
 β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘    β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
  β•šβ•β•β•β•β•β•    β•šβ•β•   β•šβ•β•     β•šβ•β•     β•šβ•β•β•β•β•β•β•šβ•β•β•β•β•β•β•β•šβ•β•


πŸ€– AI/LLM agents: Run 'gtm agent guide' for a comprehensive usage guide.

Author:  owntag

Description:

  Command-line interface for Google Tag Manager

Commands:

  auth              Manage authentication
  containers        Manage GTM containers
  workspaces        Manage GTM workspaces
  tags              Manage GTM tags
  triggers          Manage GTM triggers
  variables         Manage GTM variables
  …

Why use GTM CLI?

Everything you need

GTM CLI brings the full power of Google Tag Manager to your terminal, with features designed for developers, analysts, and automation workflows.

Speed & Efficiency
Perform operations that would take minutes in the web UI in seconds. Batch operations and keyboard-driven workflows make you significantly faster.
AI batteries included
Instructions for AI agents and LLMs to use GTM CLI is already included, no need to write custom prompts.
Full API Coverage
Manage everything: accounts, containers, workspaces, tags, triggers, variables, versions, environments, folders, user permissions, and server-side GTM resources.
Flexible Authentication
Choose your preferred authentication method: OAuth for interactive use, or Service Accounts for automation.
Shell Completions
Built-in completion scripts for bash, zsh, and fish. Get intelligent tab completion for commands, flags, and arguments.
Multiple Output Formats
Choose between table, JSON, or compact output. Automatically uses JSON when piping to other tools for seamless integration.

Quick Start

1. Authenticate

# Interactive OAuth login (opens browser)
gtm auth login

# Or use a service account for automation
gtm auth login --service-account path/to/key.json

2. Set defaults (optional)

# Configure your default account/container
gtm config setup

3. Start managing your GTM

# List your accounts
gtm accounts list

# List containers in an account
gtm containers list --account-id 123456

# List all tags in a workspace
gtm tags list

# Get a specific tag
gtm tags get --tag-id 42

Common Use Cases

Managing Tags

# List all tags
gtm tags list

# Create a new tag
gtm tags create --name "GA4 Event" --type gaawe --config '{"parameter": [...]}'

# Update a tag
gtm tags update --tag-id 42 --name "New Name"

# Delete a tag
gtm tags delete --tag-id 42 --force

Version Control

# Create a new version
gtm versions create --name "v1.0" --notes "Initial release"

# Get the current live version
gtm versions live

# Publish a version
gtm versions publish --version-id 42

Workspace Management

# List workspaces
gtm workspaces list

# Create a new workspace
gtm workspaces create --name "Feature Branch"

# Check workspace status (pending changes)
gtm workspaces status --workspace-id 1

# Sync workspace with live version
gtm workspaces sync --workspace-id 1

Server-Side GTM

GTM CLI fully supports server-side GTM resources:

# Manage clients
gtm clients list
gtm clients create --name "GA4 Client" --type gaaw_client

# Manage templates
gtm templates list

# Manage transformations
gtm transformations list

Output Formats

GTM CLI adapts to your workflow:

# Table output (default for terminals)
gtm tags list --output table

# JSON output (default when piping)
gtm tags list --output json

# Compact output (just IDs and names)
gtm tags list --output compact

# Pipe to other tools
gtm tags list | jq '.[].name'

CI/CD Integration

GTM CLI shines in automated workflows. Here’s an example GitHub Actions workflow:

jobs:
  deploy-gtm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        
      - name: Install GTM CLI
        run: |
          curl -fsSL https://raw.githubusercontent.com/owntag/gtm-cli/main/install.sh | bash
                    
      - name: Deploy to GTM
        env:
          GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GTM_SERVICE_ACCOUNT_KEY }}
        run: |
          # Create and publish a new version
          gtm versions create --name "Deploy ${{ github.sha }}"
          gtm versions publish --version-id $(gtm version-headers list --output json | jq -r '.[0].containerVersionId')          

Questions or feedback? Open an issue on GitHub – we'd love to hear from you!

Become a Server Side Tagging Pro with owntag

Take control of your digital data collection with Server Side Tagging and Server Side GTM – easily hosted with owntag.

App screenshot