Overseas access: www.kdjingpai.com
Ctrl + D Favorites

Google Analytics MCP (Model Context Protocol) is an open source tool that allows users to connect Google Analytics 4 (GA4) data with big models (e.g. Claude, Cursor, etc.) via a local server. It provides data query and management capabilities through the Google Analytics Admin API and Data API. Users can run the server locally to analyze website traffic, user behavior and other data with the help of natural language processing. The project is hosted on GitHub , maintained by the Google Analytics team , supports Python environment , suitable for developers and data analysts . The code is updated frequently, the last update in July 2025, and the community is highly active.

Function List

  • Get Google Analytics account and property information.
  • Queries detailed information about specific properties, such as configuration and settings.
  • List links to Google Ads accounts.
  • Run GA4 data reports with support for custom dimensions and metrics.
  • Get the core reporting dimensions for a specific attribute, including custom dimensions.
  • Get core reporting metrics for specific attributes, including custom metrics.
  • Provides a list of standard dimensions and indicators for easy data analysis.
  • Supports natural language queries and incorporates large models to handle complex data requirements.

Using Help

Installation process

To use Google Analytics MCP, users need to install and configure the server in their local environment. Below are the detailed installation and usage steps:

  1. Preparing the environment
    • Make sure that Python 3.10 or later is installed on your system. Run the following command to check the version:
      python --version
      python3 --version
      
    • mountingpipand check the version:
      pip --version
      pip3 --version
      
  2. clone warehouse
    Clone the Google Analytics MCP repository locally using Git:

    git clone https://github.com/googleanalytics/google-analytics-mcp.git
    cd google-analytics-mcp
    
  3. Creating a Virtual Environment
    To avoid dependency conflicts, it is recommended to create a Python virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # Linux/Mac
    venv\Scripts\activate     # Windows
    
  4. Installation of dependencies
    Install the required dependencies for the project in the virtual environment:

    pip install -r requirements.txt
    
  5. Configuring Google Analytics Credentials
    • Create a service account in Google Cloud Console to enable the Google Analytics Data API.
    • Download the JSON key file for the service account, noting the path as/path/to/your/service-account-key.jsonThe
    • Setting environment variablesGOOGLE_APPLICATION_CREDENTIALS::
      export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"  # Linux/Mac
      set GOOGLE_APPLICATION_CREDENTIALS="path\to\your\service-account-key.json"     # Windows
      
    • Optional: Edit~/.gemini/settings.json, add the credential path:
      {
      "mcpServers": {
      "analytics-mcp": {
      "command": "pipx",
      "args": ["run", "--spec", "git+https://github.com/googleanalytics/google-analytics-mcp.git", "google-analytics-mcp"],
      "env": {
      "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json"
      }
      }
      }
      }
      
  6. Operations Server
    Use the following command to start the MCP server:

    pipx run --spec git+https://github.com/googleanalytics/google-analytics-mcp.git google-analytics-mcp
    

    or run in a virtual environment:

    python -m ga4_mcp_server
    
  7. test connection
    Run the following code to verify GA4 credentials:

    import os
    from google.analytics.data_v1beta import BetaAnalyticsDataClient
    os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/your/service-account-key.json"
    client = BetaAnalyticsDataClient()
    print("✅ GA4 credentials working!")
    

    If you see "✅ GA4 credentials working!", the configuration is successful.

Main Functions

  1. Get account and property information
    utilizationget_account_summariesTool queries the user's Google Analytics account and attribute list. After running it, the server returns the account ID, attribute ID and other information, which is suitable for a quick overview of the account structure.
  2. Operational Data Reporting
    utilizationrun_reportThe tool generates GA4 reports. The user needs to specify the attribute ID, date range, dimension and metrics. For example, query for country/region and active user data for the last 7 days:

    {
    "propertyId": "properties/123456789",
    "dateRanges": [{"startDate": "7daysAgo", "endDate": "yesterday"}],
    "dimensions": [{"name": "country"}],
    "metrics": [{"name": "activeUsers"}]
    }
    

    The report results are returned in JSON format and contain data for the specified dimensions and metrics.

  3. Access to dimensions and indicators
    • utilizationget_dimensionscap (a poem)get_metricsGet the core dimensions and metrics of an attribute, including custom dimensions and metrics.
    • utilizationget_standard_dimensionscap (a poem)get_standard_metricsGet a list of standard dimensions and metrics for GA4, suitable for initial configuration reports.
  4. natural language query
    MCP supports querying data in natural language through large models such as Claude. For example, enter "Compare average session length by device category over the last 30 days":

    • The server converts the request into an API call, generating a report.
    • Return results are presented in table or JSON format for easy understanding.

Featured Function Operation

  1. Integration with large models
    The MCP server runs locally and allows users to combine GA4 data with large models. For example, using Claude or Cursor, enter a natural language command such as "show pageviews by browser for the last 90 days". The server parses the command, calls the GA4 API, and returns structured data.
  2. Google Ads Link Management
    utilizationlist_google_ads_linksQueries links to Google Ads accounts with GA4 attributes. The returned results include the account ID and status of the link, which is suitable for marketers to optimize their ad placements.
  3. Customizing dimensions and indicators
    Users can access theget_dimensionscap (a poem)get_metricsGet custom dimensions and metrics to create personalized reports. For example, analyze the number of triggers for a specific event (e.g., a "purchase" event).

caveat

  • Ensure that the service account has permissions for the Google Analytics Data API and Admin API.
  • Check the internet connection, the server needs to have access to the Google API.
  • Regularly update the repository code for the latest features:
    git pull origin main
    

application scenario

  1. Website Traffic Analysis
    Webmasters use MCP to query GA4 data to analyze traffic sources, user behavior, and conversions over the past 30 days to help optimize website content and marketing strategies.
  2. Advertising Effectiveness Evaluation
    The marketing team works throughlist_google_ads_linkscap (a poem)run_reportFunctions to compare the click-through and conversion rates of different ad campaigns and adjust the placement budget.
  3. Data-driven product optimization
    Product managers use natural language queries to analyze user dwell time and bounce rates on specific pages to optimize the user experience.
  4. Developer Integration Testing
    The developer integrates the MCP server into the data analysis tool, testing API calls and data returns to ensure stable system operation.

QA

  1. How do I secure my GA4 credentials?
    Store service account key files in a secure location to avoid public sharing. Use environment variables or~/.gemini/settings.jsonConfigure credentials to prevent leakage.
  2. What big models does MCP support?
    Support for MCP clients such as Claude, Cursor, Gemini CLI, etc., with the possibility of expanding for more compatible models in the future.
  3. What should I do if my report query fails?
    Check service account permissions, API enablement status, and network connectivity. Ensure thatpropertyIdCorrect, the date range format is "YYYY-MM-DD" or "7daysAgo".
  4. How do I view supported dimensions and metrics?
    utilizationget_standard_dimensionscap (a poem)get_standard_metricsGet a list of criteria, orget_dimensionscap (a poem)get_metricsGet attribute-specific custom dimensions and metrics.
0Bookmarked
0kudos

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

inbox

Contact Us

Top

en_USEnglish