Back to Experiments

GA4 MCP

LLM SetupNov 26, 2025
Priority:
(Highest)
Data AnalyticsMCPGA4

Result Summary

Able to query Google Analytics data directly from LLM


Google Official MCP Setup Link

 

Set Up Guide Using Claude Code

This guide will walk you through setting up the Google Analytics 4 MCP server in Claude Desktop using the Smithery approach.

Time Required: 15-20 minutes Prerequisites: All verified ✅

  • Node.js v22.19.0 ✅
  • npm 10.9.3 ✅
  • Claude Desktop ✅

  • Step 1: Set Up Google Cloud Service Account

    1.1 Access Google Cloud Console

  • Open your browser and go to: https://console.cloud.google.com
  • Sign in with your Google account
  • 1.2 Create or Select a Project

  • At the top of the page, click the project dropdown
  • Click "NEW PROJECT"
  • Name it: Claude GA4 MCP
  • Click "CREATE"
  • Wait for the project to be created, then select it from the dropdown
  • 1.3 Enable Google Analytics Data API

  • In the left sidebar, click "APIs & Services" > "Library"
  • In the search bar, type: Google Analytics Data API
  • Click on "Google Analytics Data API"
  • Click the blue "ENABLE" button
  • Wait for it to enable (takes a few seconds)
  • 1.4 Create Service Account

  • In the left sidebar, click "IAM & Admin" > "Service Accounts"
  • Click "CREATE SERVICE ACCOUNT" at the top
  • Fill in the details:
    1. Service account name: Claude-GA4-MCP
    2. Service account ID: (auto-filled, leave as is)
    3. Description: Service account for Claude to access GA4 data
  • Click "CREATE AND CONTINUE"
  • Skip the optional steps by clicking "CONTINUE" then "DONE"
  • 1.5 Download Credentials JSON

  • You should now see your service account listed
  • Click on the service account email (looks like: claude-ga4-mcp@your-project.iam.gserviceaccount.com)
  • Go to the "KEYS" tab
  • Click "ADD KEY" > "Create new key"
  • Select "JSON" format
  • Click "CREATE"
  • A JSON file will download automatically - save this file securely!
  • Rename it to: ga4-credentials.json
  • Move it to this directory: /Users/ellen/Desktop/agent/GA4_MCP/
  • IMPORTANT: Copy the service account email - you'll need it in the next step! The email looks like: claude-ga4-mcp@your-project-id.iam.gserviceaccount.com


    Step 2: Grant GA4 Access to Service Account

    2.1 Access Google Analytics

  • Open a new tab and go to: https://analytics.google.com
  • Sign in if needed
  • 2.2 Find Your Property ID

  • In the bottom left, click "Admin" (gear icon)
  • In the "Property" column, you'll see your property name
  • Below it, you'll see a number like "123456789" - copy this number!
  • Save it somewhere - this is your GA4 Property ID
  • 2.3 Add Service Account Access

  • Still in Admin, under the "Property" column, click "Property Access Management"
  • Click the blue "+" button in the top right
  • Click "Add users"
  • Paste your service account email (from Step 1.5)
  • Under "Permissions", select "Viewer"
  • Uncheck "Notify new users by email" (it's a service account, not a person)
  • Click "Add"
  • Note: It may take a few minutes for access to propagate.


    Step 3: Install MCP Server via Smithery

    Now we'll install the MCP server using a single command:

  • Open Terminal (if not already open)
  • Navigate to this directory:
      cd /Users/ellen/Desktop/agent/GA4_MCP
      
  • Run the Smithery installation command:
      npx -y @smithery/cli install mcp-server-google-analytics --client claude
      
  • Wait for installation to complete (may take 1-2 minutes)

  • Step 4: Configure Claude Desktop

    4.1 Extract Credentials from JSON File

  • Open the ga4-credentials.json file you downloaded
  • Find these values:
    1. client_email: This is your GOOGLE_CLIENT_EMAIL
    2. private_key: This is your GOOGLE_PRIVATE_KEY (includes the -----BEGIN PRIVATE KEY----- part)
  • 4.2 Edit Claude Desktop Config

  • Open Claude Desktop
  • Go to: Settings (or Claude > Settings on Mac)
  • Click Developer
  • Click Edit Config
  • This will open a JSON file in your default text editor.

    4.3 Add MCP Server Configuration

    Add this configuration to the mcpServers section:

    {
      "mcpServers": {
        "google-analytics": {
          "command": "npx",
          "args": ["-y", "mcp-server-google-analytics"],
          "env": {
            "GOOGLE_CLIENT_EMAIL": "paste-your-service-account-email-here",
            "GOOGLE_PRIVATE_KEY": "paste-your-private-key-here-including-begin-and-end-lines",
            "GA_PROPERTY_ID": "paste-your-property-id-here"
          }
        }
      }
    }
    

    IMPORTANT NOTES:

  • Replace the placeholder values with your actual credentials
  • The GOOGLE_PRIVATE_KEY should include ----BEGIN PRIVATE KEY----- and ----END PRIVATE KEY-----
  • Keep the \\n characters in the private key as they are
  • Your GA_PROPERTY_ID should be just the number (no quotes if it's a number)
  • 4.4 Save and Restart

  • Save the config file
  • Completely quit Claude Desktop (File > Quit or Cmd+Q on Mac)
  • Reopen Claude Desktop

  • Step 5: Test Your Setup

    Once Claude Desktop reopens, try these test queries:

    Basic Test:

    Show me page views for the last 7 days
    

    Traffic Analysis:

    What are my top 10 pages by traffic this month?
    

    Device Comparison:

    Compare mobile vs desktop traffic for the last 30 days
    

    If you see Claude accessing the Google Analytics tools and returning data, congratulations! Your setup is complete!


    Troubleshooting

    Claude doesn't show the MCP server

  • Run node --version to verify Node.js is installed
  • Check the config file for typos in the paths or credentials
  • Make sure you completely quit and restarted Claude Desktop (not just closed the window)
  • Authentication errors

  • Verify the service account email has "Viewer" access in GA4 Admin
  • Check that the Google Analytics Data API is enabled in Google Cloud Console
  • Ensure the private key is properly formatted with \\n for line breaks
  • No data returned

  • Verify your GA4 Property ID is correct (should be a 9-digit number)
  • Check that your GA4 property has data for the date range you're querying
  • Service account access can take up to 24 hours to fully propagate (usually much faster)

  • Example Queries to Try

    Once everything is working, try these queries:

    Basic Metrics:

  • "What's my bounce rate for the last month?"
  • "How many active users did I have yesterday?"
  • "Show me sessions by traffic source"
  • Custom Analysis:

  • "Which pages have the highest engagement time?"
  • "Show me conversion rates by device type"
  • "What are my top referring websites?"
  • Event Analysis:

  • "What are my most triggered events this week?"
  • "Show me event counts for [specific event name]"
  • "Analyze user behavior patterns"

  • Additional Resources

  • Google Analytics Data API Documentation
  • Claude Desktop MCP Guide
  • MCP Server GitHub Repository
  •  

     

    While the guide appears complex, Claude Code performs the implementation. Your only task is providing the credentials.