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. The server uses the Google Analytics Admin API Google Analytics Data API to provide several Tools for use with LLMs. - getaccountsummaries: Retrieves information about the user's Google Analytics accounts
Add this skill
npx mdskills install googleanalytics/google-analytics-mcpWell-documented MCP server with comprehensive Google Analytics API integration and excellent setup guide
1# Google Analytics MCP Server (Experimental)23[](https://pypi.org/project/analytics-mcp/)4[](https://www.python.org/downloads/)5[](https://github.com/googleanalytics/google-analytics-mcp/actions?query=branch%3Amain++)6[](https://pypi.org/project/analytics-mcp/)7[](https://github.com/googleanalytics/google-analytics-mcp/stargazers)8[](https://github.com/googleanalytics/google-analytics-mcp/network/members)9[](https://www.youtube.com/watch?v=PT4wGPxWiRQ)1011This repo contains the source code for running a local12[MCP](https://modelcontextprotocol.io) server that interacts with APIs for13[Google Analytics](https://support.google.com/analytics).1415Join the discussion and ask questions in the16[๐ค-analytics-mcp channel](https://discord.com/channels/971845904002871346/1398002598665257060)17on Discord.1819## Tools ๐ ๏ธ2021The server uses the22[Google Analytics Admin API](https://developers.google.com/analytics/devguides/config/admin/v1)23and24[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1)25to provide several26[Tools](https://modelcontextprotocol.io/docs/concepts/tools) for use with LLMs.2728### Retrieve account and property information ๐2930- `get_account_summaries`: Retrieves information about the user's Google31 Analytics accounts and properties.32- `get_property_details`: Returns details about a property.33- `list_google_ads_links`: Returns a list of links to Google Ads accounts for34 a property.3536### Run core reports ๐3738- `run_report`: Runs a Google Analytics report using the Data API.39- `get_custom_dimensions_and_metrics`: Retrieves the custom dimensions and40 metrics for a specific property.4142### Run realtime reports โณ4344- `run_realtime_report`: Runs a Google Analytics realtime report using the45 Data API.4647## Setup instructions ๐ง4849โจ Watch the [Google Analytics MCP Setup50Tutorial](https://youtu.be/nS8HLdwmVlY) on YouTube for a step-by-step51walkthrough of these instructions.5253[](https://www.youtube.com/watch?v=nS8HLdwmVlY)5455Setup involves the following steps:56571. Configure Python.581. Configure credentials for Google Analytics.591. Configure Gemini.6061### Configure Python ๐6263[Install pipx](https://pipx.pypa.io/stable/#install-pipx).6465### Enable APIs in your project โ6667[Follow the instructions](https://support.google.com/googleapi/answer/6158841)68to enable the following APIs in your Google Cloud project:6970* [Google Analytics Admin API](https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com)71* [Google Analytics Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com)7273### Configure credentials ๐7475Configure your [Application Default Credentials76(ADC)](https://cloud.google.com/docs/authentication/provide-credentials-adc).77Make sure the credentials are for a user with access to your Google Analytics78accounts or properties.7980Credentials must include the Google Analytics read-only scope:8182```83https://www.googleapis.com/auth/analytics.readonly84```8586Check out87[Manage OAuth Clients](https://support.google.com/cloud/answer/15549257)88for how to create an OAuth client.8990Here are some sample `gcloud` commands you might find useful:9192- Set up ADC using user credentials and an OAuth desktop or web client after93 downloading the client JSON to `YOUR_CLIENT_JSON_FILE`.9495 ```shell96 gcloud auth application-default login \97 --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \98 --client-id-file=YOUR_CLIENT_JSON_FILE99 ```100101- Set up ADC using service account impersonation.102103 ```shell104 gcloud auth application-default login \105 --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \106 --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform107 ```108109When the `gcloud auth application-default` command completes, copy the110`PATH_TO_CREDENTIALS_JSON` file location printed to the console in the111following message. You'll need this for the next step!112113```114Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]115```116117### Configure Gemini1181191. Install [Gemini120 CLI](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/index.md)121 or [Gemini Code122 Assist](https://marketplace.visualstudio.com/items?itemName=Google.geminicodeassist).1231241. Create or edit the file at `~/.gemini/settings.json`, adding your server125 to the `mcpServers` list.126127 Replace `PATH_TO_CREDENTIALS_JSON` with the path you copied in the previous128 step.129130 We also recommend that you add a `GOOGLE_CLOUD_PROJECT` attribute to the131 `env` object. Replace `YOUR_PROJECT_ID` in the following example with the132 [project ID](https://support.google.com/googleapi/answer/7014113) of your133 Google Cloud project.134135 ```json136 {137 "mcpServers": {138 "analytics-mcp": {139 "command": "pipx",140 "args": [141 "run",142 "analytics-mcp"143 ],144 "env": {145 "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",146 "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"147 }148 }149 }150 }151 ```152153## Try it out ๐ฅผ154155Launch Gemini Code Assist or Gemini CLI and type `/mcp`. You should see156`analytics-mcp` listed in the results.157158Here are some sample prompts to get you started:159160- Ask what the server can do:161162 ```163 what can the analytics-mcp server do?164 ```165166- Ask about a Google Analytics property167168 ```169 Give me details about my Google Analytics property with 'xyz' in the name170 ```171172- Prompt for analysis:173174 ```175 what are the most popular events in my Google Analytics property in the last 180 days?176 ```177178- Ask about signed-in users:179180 ```181 were most of my users in the last 6 months logged in?182 ```183184- Ask about property configuration:185186 ```187 what are the custom dimensions and custom metrics in my property?188 ```189190## Contributing โจ191192Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md).193
Full transparency โ inspect the skill content before installing.