Google Tag Manager MCP Server

Google Tag Manager MCP Server

Integrates Google Tag Manager with Claude to automate the creation and management of tags, triggers, and variables using natural language prompts. It provides specialized tools for GA4 and Facebook Pixel setup, along with automated tracking workflows for ecommerce and lead generation sites.

Category
Visit Server

README

Google Tag Manager MCP Server

A Model Context Protocol (MCP) server that integrates Google Tag Manager with Claude, enabling automated GTM configuration and component creation through natural language prompts.

Features

  • GTM API Integration: Full Google Tag Manager API integration for creating and managing tags, triggers, and variables
  • Component Templates: Pre-built templates for common tracking scenarios (GA4, Facebook Pixel, conversion tracking)
  • Workflow Automation: Complete workflow creation for different site types (ecommerce, lead generation, content sites)
  • Claude Integration: Natural language interface for GTM configuration through Claude

Setup

1. Install Dependencies

Option A: Using uv (Recommended)

# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env

# Install dependencies
uv sync

Option B: Using pip

pip install -r requirements.txt

2. Google Cloud Console Setup

  1. Go to the Google Cloud Console
  2. Create a new project or select existing one
  3. Enable the Tag Manager API:
    • Go to "APIs & Services" > "Library"
    • Search for "Tag Manager API"
    • Click "Enable"

3. Create Service Account Credentials

  1. Go to "APIs & Services" > "Credentials"
  2. Click "Create Credentials" > "OAuth 2.0 Client IDs"
  3. Choose "Desktop application"
  4. Download the JSON file and save it as credentials.json in this directory

4. Configure Claude

Add the MCP server configuration to your Claude config:

{
  "mcpServers": {
    "gtm": {
      "command": "python",
      "args": ["/path/to/mcp-for-gtm/server.py"],
      "env": {
        "GTM_CREDENTIALS_FILE": "/path/to/mcp-for-gtm/credentials.json",
        "GTM_TOKEN_FILE": "/path/to/mcp-for-gtm/token.json"
      }
    }
  }
}

Available Tools

Basic GTM Operations

  • create_gtm_tag: Create individual GTM tags
  • create_gtm_trigger: Create GTM triggers
  • create_gtm_variable: Create GTM variables
  • list_gtm_containers: List all containers for an account
  • get_gtm_container: Get container details
  • publish_gtm_version: Publish a container version

Workflow Tools

  • create_ga4_setup: Complete Google Analytics 4 setup with config tag and common events
  • create_facebook_pixel_setup: Facebook Pixel tracking setup
  • create_form_tracking: Form submission tracking setup
  • generate_gtm_workflow: Generate complete workflows for different site types

Usage Examples

1. Set up Google Analytics 4 tracking

Create a complete GA4 setup for my website with measurement ID G-XXXXXXXXXX in GTM account 123456 and container 7890123

2. Generate ecommerce tracking workflow

Generate a complete ecommerce tracking workflow with GA4 measurement ID G-XXXXXXXXXX and Facebook Pixel ID 123456789

3. Create form tracking

Set up form tracking for the contact form with selector #contact-form in my GTM container

4. Create custom components

Create a custom GTM tag for tracking video plays with the following parameters: event_name = "video_play", video_title = "{{Video Title}}", video_duration = "{{Video Duration}}"

Workflow Types

The generate_gtm_workflow tool supports three main workflow types:

  • ecommerce: Enhanced ecommerce tracking with purchase, cart, and product interaction events
  • lead_generation: Form submissions, CTA clicks, and conversion tracking
  • content_site: Content engagement, newsletter signups, and social sharing

Authentication

On first run, the server will open a browser window for OAuth authentication. Grant the necessary permissions to access your GTM account. The authentication token will be saved for future use.

File Structure

mcp-for-gtm/
├── server.py              # Main MCP server
├── gtm_client.py          # GTM API client
├── gtm_components.py      # Component templates and workflow builder
├── requirements.txt       # Python dependencies
├── config.json           # MCP server configuration
├── credentials.json      # Google OAuth credentials (you provide)
├── token.json           # Generated auth token (auto-created)
└── README.md           # This file

Troubleshooting

Authentication Issues

  • Ensure credentials.json is properly configured from Google Cloud Console
  • Check that Tag Manager API is enabled in your Google Cloud project
  • Verify you have the necessary permissions in your GTM account

Permission Errors

  • Make sure your Google account has edit permissions for the GTM container
  • Ensure the GTM account and container IDs are correct

API Errors

  • Check your GTM account and container IDs
  • Verify that the workspace exists (default workspace ID is used)
  • Check rate limits if you're making many requests

Development

Running Tests

# Using uv
uv run python test_server.py

# Or directly with python
python test_server.py

Running the Server

# Using the convenience script
./run_server.sh

# Or manually with uv
uv run python server.py

# Or with system python
python server.py

Development Dependencies

The project includes development dependencies for code quality:

# Format code with black
uv run black .

# Check with flake8
uv run flake8 .

# Type checking with mypy
uv run mypy .

# Run tests with pytest
uv run pytest

Contributing

Feel free to submit issues and enhancement requests!

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured