Google Analytics MCP
Google Analytics MCP Server runs a local server to retrieve and report Google Analytics data, enabling easy access to account details, core and realtime reports. It supports seamless integration with LLMs for enhanced analytics insights.
How to Install and Use Google Analytics MCP
Google Analytics MCP is a tool that helps you run a local server interacting with Google Analytics APIs. This lets you get data from your Google Analytics accounts easily using code or chat tools. Below, you will find simple steps to install and set it up, along with examples of how to use it.
Setting Up Python Environment
First, you need to prepare Python on your computer because Google Analytics MCP runs with Python. The best way is to install pipx, which helps you run Python tools in isolated environments. You can install pipx by following the instructions here: Install pipx.
Once pipx is ready, you will use it to run MCP without installing it globally. This keeps everything clean on your machine.
Enabling Google Analytics APIs
The Google Analytics MCP server works by communicating with Google Analytics APIs. You must turn on two important APIs on your Google Cloud project:
- Google Analytics Admin API
- Google Analytics Data API
You can enable these in your project by following this guide: Enable APIs.
Make sure both APIs are active before moving forward.
Configuring Credentials
To let MCP access your Google Analytics data, you need to set up credentials. These are like keys to your Google data.
You should create Application Default Credentials (ADC) for a user who has at least read-only access to your analytics accounts.
Make sure the credentials include this access scope:
https://www.googleapis.com/auth/analytics.readonly
You can create OAuth clients and get your credentials JSON using Google Cloud’s tools. One common method is to run this command in your terminal, replacing YOUR_CLIENT_JSON_FILE with the file you downloaded from Google Cloud:
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
After running this, you will see a message like this telling you where the credentials were saved:
Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]
Keep that file path handy for the next step.
Setting Up Gemini Tool
Gemini is a helper tool that connects with the Google Analytics MCP server.
To set it up:
- Install the Gemini CLI or the Gemini Code Assist extension for VS Code.
- Open or create the settings file at
~/.gemini/settings.json. - Add your MCP server information and point it to your credentials file. Replace placeholders with your actual info.
Here is an example of how your settings should look:
{
"mcpServers": {
"analytics-mcp": {
"command": "pipx",
"args": [
"run",
"analytics-mcp"
],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
"GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"
}
}
}
}
Replace PATH_TO_CREDENTIALS_JSON with the file you got earlier, and YOUR_PROJECT_ID with your Google Cloud project ID.
Trying Out Google Analytics MCP
Now that everything is set, you can try running commands with Gemini.
Start Gemini Code Assist or Gemini CLI and type:
/mcp
You should see analytics-mcp as an option. Choose it and try these example prompts:
- To see what the server can do:
what can the analytics-mcp server do?
- To get details about a Google Analytics property:
Give me details about my Google Analytics property with 'xyz' in the name
- To ask for analytics data, like popular events in the last 180 days:
what are the most popular events in my Google Analytics property in the last 180 days?
These commands let you explore your Google Analytics data easily.
That’s it! Following these steps, you’ll have Google Analytics MCP installed and running, ready to help you interact with your analytics data through simple commands or code.