Setting Up Google Tag Manager MCP for Claude

Stuart Clark avatar
Setting Up Google Tag Manager MCP for Claude

AI-Powered SEO & CRO  ·  stuseo.uk

PART 6 OF 13

Setting Up Google Tag Manager MCP for Claude

Audit, deploy and check your tags in plain English

AI-POWERED SEO & CRO WITH CLAUDE — 13-PART SERIES

You are reading Part 6 of 13. Start from the beginning if you haven’t read the introduction yet.

Why connect Google Tag Manager to Claude?

Earlier in this series we connected Claude to GA4, Search Console, FreeCrawl and Microsoft Clarity. Those connections tell Claude what is happening on your site. Google Tag Manager is different. It’s where you deploy the tags that run on your site: analytics and conversion tracking, advertising pixels, consent tools, testing scripts and other third-party code. On most sites, the majority of those tags are tracking, so GTM effectively decides what gets measured. If a tag isn’t firing, a trigger is too broad or an event is named inconsistently, every report built on top of it is wrong.

A GTM MCP server lets Claude read and edit your containers, tags, triggers and variables through the Tag Manager API. You can ask Claude to audit a container, explain why an event isn’t reaching GA4, or set up the tracking for a new A/B test, without clicking through the GTM interface yourself.

As with every server in this series, MCP is an open standard. This guide uses the Claude desktop app, but the same server also works with other MCP-compatible tools, including Claude Code, Cursor, VS Code and ChatGPT.

The server we’ll use: Stape’s GTM MCP server

Google doesn’t publish an official Tag Manager MCP server, so this guide uses the open-source Google Tag Manager MCP server from Stape. It is free, actively maintained, and comes in two versions that share the same 18 GTM tools:

  • Hosted server (Option A): the quickest setup. You sign in with Google in your browser and Stape handles authentication. Your GTM data passes through Stape’s server at gtm-mcp.stape.ai.
  • Local server (Option B): it runs on your own computer using a Google Cloud service account you create. Your data only travels between your machine and Google, and you control exactly what the account can do in GTM.

If you’re just trying it out on your own containers, Option A takes about five minutes. For client containers, or anywhere you’d rather data didn’t pass through a third party, use Option B.

Before you start

  1. Install the Claude desktop app and sign in.
  2. Install Node.js (the LTS version). Both options use the npx command that comes with it. To check it worked, open a terminal (Command Prompt or PowerShell on Windows, Terminal on Mac) and run node -v and npx -v. Each should print a version number.
  3. Make sure your Google account has access to the GTM container you want to work with.

WINDOWS & MAC

You edit the Claude config through Settings → Developer → Edit Config in the app. If you need to find the file directly:
Windows: %APPDATA%\Claude\claude_desktop_config.json
Mac: ~/Library/Application Support/Claude/claude_desktop_config.json

Option A: connect Claude to the hosted GTM server

Step A1: Open your Claude config

In the Claude desktop app, go to Settings → Developer → Edit Config. This opens claude_desktop_config.json in your text editor.

Step A2: Add the GTM server

If the file is empty, or only contains {}, replace everything with:

{
  "mcpServers": {
    "gtm-mcp-server": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://gtm-mcp.stape.ai/mcp"]
    }
  }
}

If you already have other servers from earlier in this series, don’t create a second mcpServers block. Add the "gtm-mcp-server": { ... } entry inside the existing one, with a comma after the server before it:

{
  "mcpServers": {
    "google-analytics": {
      ...your existing GA4 settings...
    },
    "gtm-mcp-server": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://gtm-mcp.stape.ai/mcp"]
    }
  }
}

Keep the server name short. Some MCP clients drop tools if the server name and tool name together run past 60 characters.

Step A3: Restart Claude and sign in with Google

Save the file and fully quit Claude. On Windows, right-click the Claude icon in the system tray and choose Quit. On Mac, press Cmd+Q. Then reopen it. A browser window will open for Google sign-in. Choose the Google account that has access to your GTM containers and approve the requested permissions.

Step A4: Test the connection

Start a new chat and ask: “List my Google Tag Manager accounts and containers.” Claude will ask permission to use the GTM tool the first time. Allow it, and you should see your real account and container names. You’re connected, so skip ahead to using Claude with GTM.

Option B: run the GTM server locally with a service account

Step B1: Enable the Tag Manager API

Go to the Google Cloud Console and select a project, or create one from the project picker at the top. If you followed the GA4 setup in Part 2, you can reuse that project. Go to APIs & Services → Library, search for Tag Manager API, open it and click Enable.

Step B2: Create a service account

  1. Go to IAM & Admin → Service Accounts and click Create service account.
  2. Give it a name such as claude-gtm and click Create and continue. It doesn’t need any Google Cloud roles, so skip the optional steps and click Done.
  3. Copy the service account’s email address. It ends in .iam.gserviceaccount.com.

Step B3: Download a JSON key

Click the service account, open the Keys tab, then choose Add key → Create new key → JSON → Create. A JSON file will download. Keep it private: anyone with this file can act as the service account.

Step B4: Give the service account access in GTM

  1. In Google Tag Manager, open Admin → User Management for the account you want Claude to work with.
  2. Click + → Add users and paste the service account email.
  3. Set the account permission to User, then set container permissions for each container Claude should manage.
  4. Click Invite. Service accounts don’t need to accept the invitation.

The container permission you choose is your main safety control. Read allows audits only. Edit lets Claude create and change tags in workspaces but not publish. Publish lets it push changes live. We recommend starting with Read or Edit.

Step B5: Add the local server to Claude

Open the JSON key file in a text editor. You need two values from it: client_email and private_key. In Claude, go to Settings → Developer → Edit Config and add the server, following the same rules about existing servers as Step A2:

{
  "mcpServers": {
    "gtm-mcp-server": {
      "command": "npx",
      "args": ["-y", "google-tag-manager-mcp-server"],
      "env": {
        "GOOGLE_CLIENT_EMAIL": "claude-gtm@your-project.iam.gserviceaccount.com",
        "GOOGLE_PRIVATE_KEY": "-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----\n"
      }
    }
  }
}

Paste the client_email value exactly. For GOOGLE_PRIVATE_KEY, copy everything between the quotation marks after "private_key": in the key file, including the \n characters, and paste it between the quotation marks in your config. Don’t remove the \n characters or reformat the key onto multiple lines.

If you want Claude limited to read-only access whatever its GTM permissions, add "GTM_SCOPES": "https://www.googleapis.com/auth/tagmanager.readonly" to the env section. Without it, the server requests every scope its tools need, including publishing.

Step B6: Restart Claude and test

Save the config, fully quit and reopen Claude, then ask: “List my Google Tag Manager accounts and containers.” You should see the accounts the service account was added to. If the list is empty, the service account hasn’t been added in GTM yet (Step B4).

Using Claude with GTM: four practical uses

The server gives Claude one tool for each GTM resource, including accounts, containers, workspaces, tags, triggers, variables, folders, templates, versions and user permissions. Each tool can list, get, create, update and remove items. Here’s how that works in practice.

1. Audit a container with Claude

Containers collect clutter over time: paused tags nobody remembers, duplicate GA4 tags, triggers set to All Pages that should be narrower, and naming that changes every time someone new works on it. Try:

  • “Audit the Default Workspace in my container. List paused tags, tags with no trigger, unused triggers and variables, and any duplicate GA4 tags.”
  • “Check the naming of every tag, trigger and variable and suggest a consistent convention.”

2. Check your tracking is actually working

With GTM and GA4 both connected, Claude can compare what is configured with what is actually being recorded:

  • “List every GA4 event tag in GTM, then check GA4 for each event name over the last 28 days. Flag any event that is configured but not recorded, or recorded but not configured.”
  • “Our form_submit event dropped by half last week. Check the tag, its trigger and related variables, and compare the last two published versions.”

3. Publish tags without the clicking

Describe the tag you want and let Claude build it: “Create a new workspace called ‘Newsletter tracking’. In it, create a GA4 event tag called newsletter_signup that fires on the custom event newsletter_signup, with the parameter form_location taken from the dataLayer.” Claude creates the trigger, variable and tag, then summarises what it changed. Test it in GTM’s Preview mode, then either publish from GTM yourself or ask Claude to create and publish a version.

4. Configure experiment tracking

Every A/B test needs to tell your analytics who saw which variant. Most testing platforms can push an event to the dataLayer when a visitor enters an experiment. Claude can set up the GTM side: a custom event trigger for that event, dataLayer variables for the experiment ID and variant, and a GA4 event tag that sends both as parameters. Remember to register those parameters as custom dimensions in GA4 so you can segment by them. We’ll build on this in Part 8, where Claude sets up an experiment and its tracking in the same workflow.

Safeguards when Claude can edit GTM

  • Ask Claude to work in a new, clearly named workspace rather than the Default Workspace.
  • Ask for a summary of every change before a version is created, and check it in Preview mode.
  • Keep publishing as a separate, explicit instruction. With Option B, you can prevent it entirely by giving the service account Edit rather than Publish permission.
  • Make sure every version has a clear name and description, so you can roll back in seconds from the Versions tab.

Troubleshooting

  • The GTM tools don’t appear in Claude: check the config is valid JSON, with no missing commas or brackets, and that you fully quit Claude rather than just closing the window. Check npx -v works in a terminal.
  • Hosted server sign-in keeps failing or uses the wrong account: mcp-remote caches credentials in a .mcp-auth folder in your home directory (C:\Users\yourname\.mcp-auth on Windows, ~/.mcp-auth on Mac). Delete that folder, then restart Claude and sign in again.
  • Local server stops immediately: the error usually names the missing environment variable. A malformed GOOGLE_PRIVATE_KEY is the most common cause, so copy it again from the key file.
  • Claude can read but not edit: check the container permission in GTM User Management, and remove any read-only GTM_SCOPES setting.
  • Anything else: open Help → View Logs in the Claude desktop app for the server’s error messages.

Next up: Part 7 — Setting Up Google Business Profile MCP for Claude.

One response to “Setting Up Google Tag Manager MCP for Claude”

Leave a Reply

Your email address will not be published. Required fields are marked *