# Google Analytics MCP Server (Experimental)
[](https://pypi.org/project/analytics-mcp/)
[](https://www.python.org/downloads/)
[](https://github.com/googleanalytics/google-analytics-mcp/actions?query=branch%3Amain++)
[](https://pypi.org/project/analytics-mcp/)
[](https://github.com/googleanalytics/google-analytics-mcp/stargazers)
[](https://github.com/googleanalytics/google-analytics-mcp/network/members)
[](https://www.youtube.com/watch?v=PT4wGPxWiRQ)
This repo contains the source code for running a local
[MCP](https://modelcontextprotocol.io) server that interacts with APIs for
[Google Analytics](https://support.google.com/analytics).
Join the discussion and ask questions in the
[🤖-analytics-mcp channel](https://discord.com/channels/971845904002871346/1398002598665257060)
on Discord.
## Tools 🛠️
The server uses the
[Google Analytics Admin API](https://developers.google.com/analytics/devguides/config/admin/v1)
and
[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1)
to provide several
[Tools](https://modelcontextprotocol.io/docs/concepts/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.
1. Configure credentials for Google Analytics.
1. Configure Gemini.
### Configure Python 🐍
[Install pipx](https://pipx.pypa.io/stable/#install-pipx).
### Enable APIs in your project ✅
[Follow the instructions](https://support.google.com/googleapi/answer/6158841)
to enable the following APIs in your Google Cloud project:
* [Google Analytics Admin API](https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com)
* [Google Analytics Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com)
### Configure credentials 🔑
Configure your [Application Default Credentials
(ADC)](https://cloud.google.com/docs/authentication/provide-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](https://support.google.com/cloud/answer/15549257)
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`.
```shell
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.
```shell
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](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/index.md)
or [Gemini Code
Assist](https://marketplace.visualstudio.com/items?itemName=Google.geminicodeassist).
1. 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](https://support.google.com/googleapi/answer/7014113) of your
Google Cloud project.
```json
{
"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](CONTRIBUTING.md).
Raw data
{
"_id": null,
"home_page": null,
"name": "claudiu-analytics-mcp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "google analytics, analytics, mcp, ga4",
"author": null,
"author_email": "Claudiu Mihaila <iclaudiumihaila@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/79/ed/0a1d8da6eca50e8b4bd587760fac3f8191b5a6a5c43d7aeb35d27935433b/claudiu_analytics_mcp-0.1.1.tar.gz",
"platform": null,
"description": "# Google Analytics MCP Server (Experimental)\n\n[](https://pypi.org/project/analytics-mcp/)\n[](https://www.python.org/downloads/)\n[](https://github.com/googleanalytics/google-analytics-mcp/actions?query=branch%3Amain++)\n[](https://pypi.org/project/analytics-mcp/)\n[](https://github.com/googleanalytics/google-analytics-mcp/stargazers)\n[](https://github.com/googleanalytics/google-analytics-mcp/network/members)\n[](https://www.youtube.com/watch?v=PT4wGPxWiRQ)\n\nThis repo contains the source code for running a local\n[MCP](https://modelcontextprotocol.io) server that interacts with APIs for\n[Google Analytics](https://support.google.com/analytics).\n\nJoin the discussion and ask questions in the\n[\ud83e\udd16-analytics-mcp channel](https://discord.com/channels/971845904002871346/1398002598665257060)\non Discord.\n\n## Tools \ud83d\udee0\ufe0f\n\nThe server uses the\n[Google Analytics Admin API](https://developers.google.com/analytics/devguides/config/admin/v1)\nand\n[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1)\nto provide several\n[Tools](https://modelcontextprotocol.io/docs/concepts/tools) for use with LLMs.\n\n### Retrieve account and property information \ud83d\udfe0\n\n- `get_account_summaries`: Retrieves information about the user's Google\n Analytics accounts and properties.\n- `get_property_details`: Returns details about a property.\n- `list_google_ads_links`: Returns a list of links to Google Ads accounts for\n a property.\n\n### Run core reports \ud83d\udcd9\n\n- `run_report`: Runs a Google Analytics report using the Data API.\n- `get_custom_dimensions_and_metrics`: Retrieves the custom dimensions and\n metrics for a specific property.\n\n### Run realtime reports \u23f3\n\n- `run_realtime_report`: Runs a Google Analytics realtime report using the\n Data API.\n\n## Setup instructions \ud83d\udd27\n\nSetup involves the following steps:\n\n1. Configure Python.\n1. Configure credentials for Google Analytics.\n1. Configure Gemini.\n\n### Configure Python \ud83d\udc0d\n\n[Install pipx](https://pipx.pypa.io/stable/#install-pipx).\n\n### Enable APIs in your project \u2705\n\n[Follow the instructions](https://support.google.com/googleapi/answer/6158841)\nto enable the following APIs in your Google Cloud project:\n\n* [Google Analytics Admin API](https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com)\n* [Google Analytics Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com)\n\n### Configure credentials \ud83d\udd11\n\nConfigure your [Application Default Credentials\n(ADC)](https://cloud.google.com/docs/authentication/provide-credentials-adc).\nMake sure the credentials are for a user with access to your Google Analytics\naccounts or properties.\n\nCredentials must include the Google Analytics read-only scope:\n\n```\nhttps://www.googleapis.com/auth/analytics.readonly\n```\n\nCheck out\n[Manage OAuth Clients](https://support.google.com/cloud/answer/15549257)\nfor how to create an OAuth client.\n\nHere are some sample `gcloud` commands you might find useful:\n\n- Set up ADC using user credentials and an OAuth desktop or web client after\n downloading the client JSON to `YOUR_CLIENT_JSON_FILE`.\n\n ```shell\n gcloud auth application-default login \\\n --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \\\n --client-id-file=YOUR_CLIENT_JSON_FILE\n ```\n\n- Set up ADC using service account impersonation.\n\n ```shell\n gcloud auth application-default login \\\n --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \\\n --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform\n ```\n\nWhen the `gcloud auth application-default` command completes, copy the\n`PATH_TO_CREDENTIALS_JSON` file location printed to the console in the\nfollowing message. You'll need this for the next step!\n\n```\nCredentials saved to file: [PATH_TO_CREDENTIALS_JSON]\n```\n\n### Configure Gemini\n\n1. Install [Gemini\n CLI](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/index.md)\n or [Gemini Code\n Assist](https://marketplace.visualstudio.com/items?itemName=Google.geminicodeassist).\n\n1. Create or edit the file at `~/.gemini/settings.json`, adding your server\n to the `mcpServers` list.\n\n Replace `PATH_TO_CREDENTIALS_JSON` with the path you copied in the previous\n step.\n\n We also recommend that you add a `GOOGLE_CLOUD_PROJECT` attribute to the\n `env` object. Replace `YOUR_PROJECT_ID` in the following example with the\n [project ID](https://support.google.com/googleapi/answer/7014113) of your\n Google Cloud project.\n\n ```json\n {\n \"mcpServers\": {\n \"analytics-mcp\": {\n \"command\": \"pipx\",\n \"args\": [\n \"run\",\n \"analytics-mcp\"\n ],\n \"env\": {\n \"GOOGLE_APPLICATION_CREDENTIALS\": \"PATH_TO_CREDENTIALS_JSON\",\n \"GOOGLE_PROJECT_ID\": \"YOUR_PROJECT_ID\"\n }\n }\n }\n }\n ```\n\n## Try it out \ud83e\udd7c\n\nLaunch Gemini Code Assist or Gemini CLI and type `/mcp`. You should see\n`analytics-mcp` listed in the results.\n\nHere are some sample prompts to get you started:\n\n- Ask what the server can do:\n\n ```\n what can the analytics-mcp server do?\n ```\n\n- Ask about a Google Analytics property\n\n ```\n Give me details about my Google Analytics property with 'xyz' in the name\n ```\n\n- Prompt for analysis:\n\n ```\n what are the most popular events in my Google Analytics property in the last 180 days?\n ```\n\n- Ask about signed-in users:\n\n ```\n were most of my users in the last 6 months logged in?\n ```\n\n- Ask about property configuration:\n\n ```\n what are the custom dimensions and custom metrics in my property?\n ```\n\n## Contributing \u2728\n\nContributions welcome! See the [Contributing Guide](CONTRIBUTING.md).\n",
"bugtrack_url": null,
"license": null,
"summary": "MCP server for Google Analytics",
"version": "0.1.1",
"project_urls": {
"homepage": "https://github.com/iclaudiumihaila/google-analytics-mcp",
"issues": "https://github.com/iclaudiumihaila/google-analytics-mcp/issues",
"repository": "https://github.com/iclaudiumihaila/google-analytics-mcp.git"
},
"split_keywords": [
"google analytics",
" analytics",
" mcp",
" ga4"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "673a14b6ac2696df228b2207683016cca7d4ba6e7385a3f375900989d80c3f5d",
"md5": "c079d43088656dcbe84d23db6e83a6c2",
"sha256": "96d1a17c1bb896bb92f5523f26526818db4bd20de2e8bc9e4f31be30b5972771"
},
"downloads": -1,
"filename": "claudiu_analytics_mcp-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c079d43088656dcbe84d23db6e83a6c2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 22148,
"upload_time": "2025-09-03T09:29:32",
"upload_time_iso_8601": "2025-09-03T09:29:32.613604Z",
"url": "https://files.pythonhosted.org/packages/67/3a/14b6ac2696df228b2207683016cca7d4ba6e7385a3f375900989d80c3f5d/claudiu_analytics_mcp-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "79ed0a1d8da6eca50e8b4bd587760fac3f8191b5a6a5c43d7aeb35d27935433b",
"md5": "7120a4f118bcebd1d4d14c2646c9159e",
"sha256": "aac62df3db2e0ab8f9a86bee61fb68671a2aa0c27423222a71409aadf6371eb6"
},
"downloads": -1,
"filename": "claudiu_analytics_mcp-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "7120a4f118bcebd1d4d14c2646c9159e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 17526,
"upload_time": "2025-09-03T09:29:34",
"upload_time_iso_8601": "2025-09-03T09:29:34.061895Z",
"url": "https://files.pythonhosted.org/packages/79/ed/0a1d8da6eca50e8b4bd587760fac3f8191b5a6a5c43d7aeb35d27935433b/claudiu_analytics_mcp-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-03 09:29:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "iclaudiumihaila",
"github_project": "google-analytics-mcp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "claudiu-analytics-mcp"
}