11# Google Analytics MCP Server (Experimental)
22
3+ [ ![ PyPI version] ( https://img.shields.io/pypi/v/analytics-mcp.svg )] ( https://pypi.org/project/analytics-mcp/ )
4+ [ ![ Python 3.10+] ( https://img.shields.io/badge/python-3.10+-blue.svg )] ( https://www.python.org/downloads/ )
5+ [ ![ GitHub branch check runs] ( https://img.shields.io/github/check-runs/googleanalytics/google-analytics-mcp/main )] ( https://github.com/googleanalytics/google-analytics-mcp/actions?query=branch%3Amain++ )
6+ [ ![ PyPI - Downloads] ( https://img.shields.io/pypi/dm/analytics-mcp )] ( https://pypi.org/project/analytics-mcp/ )
7+ [ ![ GitHub stars] ( https://img.shields.io/github/stars/googleanalytics/google-analytics-mcp?style=social )] ( https://github.com/googleanalytics/google-analytics-mcp/stargazers )
8+ [ ![ GitHub forks] ( https://img.shields.io/github/forks/googleanalytics/google-analytics-mcp?style=social )] ( https://github.com/googleanalytics/google-analytics-mcp/network/members )
9+ [ ![ YouTube Video Views] ( https://img.shields.io/youtube/views/PT4wGPxWiRQ )] ( https://www.youtube.com/watch?v=PT4wGPxWiRQ )
10+
311This repo contains the source code for running a local
412[ MCP] ( https://modelcontextprotocol.io ) server that interacts with APIs for
513[ Google Analytics] ( https://support.google.com/analytics ) .
614
715Join the discussion and ask questions in the
8- [ : robot : -analytics-mcp channel] ( https://discord.com/channels/971845904002871346/1398002598665257060 )
16+ [ 🤖 -analytics-mcp channel] ( https://discord.com/channels/971845904002871346/1398002598665257060 )
917on Discord.
1018
11- ## Tools : hammer_and_wrench :
19+ ## Tools 🛠️
1220
1321The server uses the
1422[ Google Analytics Admin API] ( https://developers.google.com/analytics/devguides/config/admin/v1 )
1725to provide several
1826[ Tools] ( https://modelcontextprotocol.io/docs/concepts/tools ) for use with LLMs.
1927
20- ### Retrieve account and property information : orange_circle :
28+ ### Retrieve account and property information 🟠
2129
2230- ` get_account_summaries ` : Retrieves information about the user's Google
2331 Analytics accounts and properties.
2432- ` get_property_details ` : Returns details about a property.
2533- ` list_google_ads_links ` : Returns a list of links to Google Ads accounts for
2634 a property.
2735
28- ### Run core reports : orange_book :
36+ ### Run core reports 📙
2937
3038- ` run_report ` : Runs a Google Analytics report using the Data API.
3139- ` get_custom_dimensions_and_metrics ` : Retrieves the custom dimensions and
3240 metrics for a specific property.
3341
34- ### Run realtime reports : hourglass_flowing_sand :
42+ ### Run realtime reports ⏳
3543
3644- ` run_realtime_report ` : Runs a Google Analytics realtime report using the
3745 Data API.
3846
39- ## Setup instructions
47+ ## Setup instructions 🔧
4048
4149Setup involves the following steps:
4250
43511 . Configure Python.
44521 . Configure credentials for Google Analytics.
45531 . Configure Gemini.
4654
47- ### Configure Python : snake :
55+ ### Configure Python 🐍
4856
4957[ Install pipx] ( https://pipx.pypa.io/stable/#install-pipx ) .
5058
51- ### Enable APIs in your project : white_check_mark :
59+ ### Enable APIs in your project ✅
5260
5361[ Follow the instructions] ( https://support.google.com/googleapi/answer/6158841 )
5462to enable the following APIs in your Google Cloud project:
5563
5664* [ Google Analytics Admin API] ( https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com )
5765* [ Google Analytics Data API] ( https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com )
5866
59- ### Configure credentials : key :
67+ ### Configure credentials 🔑
6068
6169Configure your [ Application Default Credentials
6270(ADC)] ( https://cloud.google.com/docs/authentication/provide-credentials-adc ) .
@@ -92,41 +100,26 @@ Here are some sample `gcloud` commands you might find useful:
92100 --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform
93101 ```
94102
103+ When the ` gcloud auth application-default ` command completes, copy the
104+ ` PATH_TO_CREDENTIALS_JSON ` file location printed to the console in the
105+ following message. You'll need this for the next step!
106+
107+ ```
108+ Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]
109+ ```
110+
95111### Configure Gemini
96112
971131 . Install [ Gemini
98114 CLI] ( https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/index.md )
99115 or [ Gemini Code
100- Assist] ( https://marketplace.visualstudio.com/items?itemName=Google.geminicodeassist )
116+ Assist] ( https://marketplace.visualstudio.com/items?itemName=Google.geminicodeassist ) .
101117
1021181 . Create or edit the file at ` ~/.gemini/settings.json ` , adding your server
103119 to the ` mcpServers ` list.
104120
105- ``` json
106- {
107- "mcpServers" : {
108- "analytics-mcp" : {
109- "command" : " pipx" ,
110- "args" : [
111- " run" ,
112- " --spec" ,
113- " git+https://github.com/googleanalytics/google-analytics-mcp.git" ,
114- " google-analytics-mcp"
115- ]
116- }
117- }
118- }
119- ```
120-
121- 1 . **Optional:** Configure the `GOOGLE_APPLICATION_CREDENTIALS` environment
122- variable in Gemini settings. You may want to do this if you always want to
123- use a specific set of credentials, regardless of which Application Default
124- Credentials are selected in your current environment.
125-
126- In `~/.gemini/settings.json`, add a `GOOGLE_APPLICATION_CREDENTIALS`
127- attribute to the `env` object. Replace `PATH_TO_ADC_JSON` in the following
128- example with the full path to the ADC JSON file you always want to use for
129- your MCP server.
121+ Replace ` PATH_TO_CREDENTIALS_JSON ` with the path you copied in the previous
122+ step.
130123
131124 We also recommend that you add a ` GOOGLE_CLOUD_PROJECT ` attribute to the
132125 ` env ` object. Replace ` YOUR_PROJECT_ID ` in the following example with the
@@ -140,20 +133,18 @@ Here are some sample `gcloud` commands you might find useful:
140133 "command" : " pipx" ,
141134 "args" : [
142135 " run" ,
143- " --spec" ,
144- " git+https://github.com/googleanalytics/google-analytics-mcp.git" ,
145- " google-analytics-mcp"
136+ " analytics-mcp"
146137 ],
147138 "env" : {
148- "GOOGLE_APPLICATION_CREDENTIALS" : " PATH_TO_ADC_JSON " ,
149- "GOOGLE_CLOUD_PROJECT " : " YOUR_PROJECT_ID"
139+ "GOOGLE_APPLICATION_CREDENTIALS" : " PATH_TO_CREDENTIALS_JSON " ,
140+ "GOOGLE_PROJECT_ID " : " YOUR_PROJECT_ID"
150141 }
151142 }
152143 }
153144 }
154145 ```
155146
156- ## Try it out :lab_coat:
147+ ## Try it out 🥼
157148
158149Launch Gemini Code Assist or Gemini CLI and type `/mcp`. You should see
159150`analytics-mcp` listed in the results.
@@ -190,6 +181,6 @@ Here are some sample prompts to get you started:
190181 what are the custom dimensions and custom metrics in my property?
191182 ```
192183
193- ## Contributing
184+ ## Contributing ✨
194185
195186Contributions welcome! See the [Contributing Guide](CONTRIBUTING.md).
0 commit comments