Skip to main content

MCP server for Google Analytics

Project description

Google Analytics MCP Server (Experimental)

PyPI version Python 3.10+ GitHub branch check runs PyPI - Downloads GitHub stars GitHub forks YouTube Video Views

This repo contains the source code for running a local MCP server that interacts with APIs for Google Analytics.

Join the discussion and ask questions in the 🤖-analytics-mcp channel on Discord.

Tools 🛠️

The server uses the Google Analytics Admin API and Google Analytics Data API to provide several Tools for use with LLMs.

Retrieve account and property information 🟠

  • get_account_summaries: Retrieves information about the user's Google Analytics accounts and properties.
  • get_property_details: Returns details about a property.
  • list_google_ads_links: Returns a list of links to Google Ads accounts for a property.

Run core reports 📙

  • run_report: Runs a Google Analytics report using the Data API.
  • get_custom_dimensions_and_metrics: Retrieves the custom dimensions and metrics for a specific property.

Run realtime reports ⏳

  • run_realtime_report: Runs a Google Analytics realtime report using the Data API.

Setup instructions 🔧

Setup involves the following steps:

  1. Configure Python.
  2. Configure credentials for Google Analytics.
  3. Configure Gemini.

Configure Python 🐍

Install pipx.

Enable APIs in your project ✅

Follow the instructions to enable the following APIs in your Google Cloud project:

Configure credentials 🔑

Configure your Application Default Credentials (ADC). Make sure the credentials are for a user with access to your Google Analytics accounts or properties.

Credentials must include the Google Analytics read-only scope:

https://www.googleapis.com/auth/analytics.readonly

Check out Manage OAuth Clients for how to create an OAuth client.

Here are some sample gcloud commands you might find useful:

  • Set up ADC using user credentials and an OAuth desktop or web client after downloading the client JSON to YOUR_CLIENT_JSON_FILE.

    gcloud auth application-default login \
      --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \
      --client-id-file=YOUR_CLIENT_JSON_FILE
    
  • Set up ADC using service account impersonation.

    gcloud auth application-default login \
      --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \
      --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform
    

When the gcloud auth application-default command completes, copy the PATH_TO_CREDENTIALS_JSON file location printed to the console in the following message. You'll need this for the next step!

Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]

Configure Gemini

  1. Install Gemini CLI or Gemini Code Assist.

  2. Create or edit the file at ~/.gemini/settings.json, adding your server to the mcpServers list.

    Replace PATH_TO_CREDENTIALS_JSON with the path you copied in the previous step.

    We also recommend that you add a GOOGLE_CLOUD_PROJECT attribute to the env object. Replace YOUR_PROJECT_ID in the following example with the project ID of your Google Cloud project.

    {
      "mcpServers": {
        "analytics-mcp": {
          "command": "pipx",
          "args": [
            "run",
            "analytics-mcp"
          ],
          "env": {
            "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
            "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"
          }
        }
      }
    }
    

Try it out 🥼

Launch Gemini Code Assist or Gemini CLI and type /mcp. You should see analytics-mcp listed in the results.

Here are some sample prompts to get you started:

  • Ask what the server can do:

    what can the analytics-mcp server do?
    
  • Ask about a Google Analytics property

    Give me details about my Google Analytics property with 'xyz' in the name
    
  • Prompt for analysis:

    what are the most popular events in my Google Analytics property in the last 180 days?
    
  • Ask about signed-in users:

    were most of my users in the last 6 months logged in?
    
  • Ask about property configuration:

    what are the custom dimensions and custom metrics in my property?
    

Contributing ✨

Contributions welcome! See the Contributing Guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claudiu_analytics_mcp-0.1.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claudiu_analytics_mcp-0.1.1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file claudiu_analytics_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: claudiu_analytics_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for claudiu_analytics_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aac62df3db2e0ab8f9a86bee61fb68671a2aa0c27423222a71409aadf6371eb6
MD5 7120a4f118bcebd1d4d14c2646c9159e
BLAKE2b-256 79ed0a1d8da6eca50e8b4bd587760fac3f8191b5a6a5c43d7aeb35d27935433b

See more details on using hashes here.

File details

Details for the file claudiu_analytics_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claudiu_analytics_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96d1a17c1bb896bb92f5523f26526818db4bd20de2e8bc9e4f31be30b5972771
MD5 c079d43088656dcbe84d23db6e83a6c2
BLAKE2b-256 673a14b6ac2696df228b2207683016cca7d4ba6e7385a3f375900989d80c3f5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page