@getmcpads/google-analytics-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +16 -0
- package/README.md +327 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +4488 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +4471 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
google-analytics-mcp-server
|
|
2
|
+
Copyright 2026 GetMCPAds
|
|
3
|
+
|
|
4
|
+
This product includes software developed at GetMCPAds (https://www.getmcpads.com).
|
|
5
|
+
|
|
6
|
+
An open-source Model Context Protocol server for Google Analytics 4.
|
|
7
|
+
It is self-hosted, read-only, and unaffiliated with Google.
|
|
8
|
+
|
|
9
|
+
GetMCPAds also runs a managed gateway that covers Google Analytics alongside
|
|
10
|
+
Meta Ads, Google Ads, TikTok Ads, Pinterest Ads and Search Console, with
|
|
11
|
+
hosted OAuth and cross-platform reporting: https://www.getmcpads.com
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Google, Google Analytics and GA4 are trademarks of Google LLC. This project
|
|
16
|
+
is not affiliated with, endorsed by, or sponsored by Google LLC.
|
package/README.md
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
# google-analytics-mcp-server
|
|
2
|
+
|
|
3
|
+
[](https://github.com/getmcpads-com/google-analytics-mcp-server/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](package.json)
|
|
6
|
+
|
|
7
|
+
An open-source [Model Context Protocol](https://modelcontextprotocol.io) server for
|
|
8
|
+
**Google Analytics 4**. It lets Claude, ChatGPT, Cursor or any MCP client query your
|
|
9
|
+
analytics data and inspect how your property is configured.
|
|
10
|
+
|
|
11
|
+
**Read-only, with no way to turn that off.** You run it, and your credentials stay on your
|
|
12
|
+
machine.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx -y @getmcpads/google-analytics-mcp-server
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
> **Prefer not to run it yourself?** [getmcpads.com](https://www.getmcpads.com) is the hosted
|
|
19
|
+
> version of this server, with Google Analytics alongside Meta Ads, Google Ads, TikTok Ads,
|
|
20
|
+
> Pinterest Ads and Search Console behind a single endpoint, hosted OAuth, and cross-platform
|
|
21
|
+
> reporting. Same tools, same safety model, no setup.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## What you get
|
|
26
|
+
|
|
27
|
+
| | |
|
|
28
|
+
|---|---|
|
|
29
|
+
| **27 read tools** | Reports, pivots, funnels, realtime, plus the Admin API: properties, data streams, custom definitions, key events, audiences |
|
|
30
|
+
| **Diagnostics** | Ecommerce, BigQuery export, server-side tagging, audience exports, quota snapshots |
|
|
31
|
+
| **51 metrics, 62 dimensions** | With a compatibility matrix that catches invalid combinations before they hit the API |
|
|
32
|
+
| **6 resources** | Live catalogues the model can read: metrics, dimensions, compatibility rules, 12 workflow recipes |
|
|
33
|
+
| **Identifier redaction** | User, email and device identifiers redacted by default on access bindings and audience exports, with explicit opt-in to see them |
|
|
34
|
+
| **No writes at all** | Not a flag, a property of the code. See below |
|
|
35
|
+
|
|
36
|
+
### Compatibility, checked before the call
|
|
37
|
+
|
|
38
|
+
GA4 rejects many metric and dimension combinations, and its errors rarely explain which pair
|
|
39
|
+
is at fault. This server carries the compatibility matrix, so `ga4_check_compatibility` and
|
|
40
|
+
`ga4_validate_query` let the model verify a combination before spending a call and a quota
|
|
41
|
+
token on it.
|
|
42
|
+
|
|
43
|
+
Quotas matter here more than on ad platforms: GA4 charges tokens per property per day, and a
|
|
44
|
+
few careless exploratory queries can exhaust them. `ga4_get_property_quotas_snapshot` shows
|
|
45
|
+
what is left.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## How this compares to Google's own MCP server
|
|
50
|
+
|
|
51
|
+
The Google Analytics team ships an official MCP server, and it is good. It is Apache-2.0,
|
|
52
|
+
runs locally, is read-only, and has a large community. Be clear about what differs.
|
|
53
|
+
|
|
54
|
+
| | Google's official server | This server | [getmcpads.com](https://www.getmcpads.com) |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| Tools | **7** | **27** | 27, plus 5 other platforms |
|
|
57
|
+
| Hosting | Local, via pipx | **Local**, via npx | Hosted for you |
|
|
58
|
+
| Read-only | ✅ | ✅ | ✅ |
|
|
59
|
+
| Reports | `run_report`, `run_funnel_report`, realtime | Same, plus **pivots, batch reports, advanced funnels** | Same |
|
|
60
|
+
| Admin API | Account summaries, property details, custom definitions | **Broader**: data streams, key events, channel groups, audiences, audience exports | Same |
|
|
61
|
+
| Diagnostics | ❌ | **Ecommerce, BigQuery export, server-side tagging, quotas** | Same |
|
|
62
|
+
| Metric compatibility | None | **Catalogue and matrix, checkable before the call** | Same |
|
|
63
|
+
| Identifier redaction | ❌ | **Default on, opt-in to disable** | Same |
|
|
64
|
+
| Language | Python | TypeScript | |
|
|
65
|
+
| Status | Labelled experimental by Google | 1.0 | |
|
|
66
|
+
|
|
67
|
+
**Neither is more private than the other.** Both run locally and read only. If the seven
|
|
68
|
+
official tools cover what you need, and your model writes clean GA4 report requests, use
|
|
69
|
+
Google's: it is maintained by the team that owns the API.
|
|
70
|
+
|
|
71
|
+
**Choose this one** when you want named metrics validated against a compatibility matrix
|
|
72
|
+
rather than raw request bodies, when you need the configuration and diagnostics surface, or
|
|
73
|
+
when you want identifiers redacted by default rather than by discipline.
|
|
74
|
+
**Choose [getmcpads.com](https://www.getmcpads.com)** if you want this server's capabilities
|
|
75
|
+
without running it, or you need analytics and ad platforms in the same conversation.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Read-only, and why it stays that way
|
|
80
|
+
|
|
81
|
+
There are no write tools, and no environment variable that adds any. Every tool calls a read
|
|
82
|
+
method of the Data API or the Admin API.
|
|
83
|
+
|
|
84
|
+
This is not caution for its own sake. A misread report is a wrong answer you can spot. A
|
|
85
|
+
mistaken write to an analytics property, a deleted audience or an edited data stream, corrupts
|
|
86
|
+
the record you use to judge everything else, and often silently. The other servers we publish
|
|
87
|
+
do have write tools, guarded by a mandatory preview. This one has none.
|
|
88
|
+
|
|
89
|
+
Our ad platform servers with guarded writes:
|
|
90
|
+
[Meta Ads](https://github.com/getmcpads-com/meta-ads-mcp-server) ·
|
|
91
|
+
[Google Ads](https://github.com/getmcpads-com/google-ads-mcp-server) ·
|
|
92
|
+
[TikTok Ads](https://github.com/getmcpads-com/tiktok-ads-mcp-server)
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Personal data
|
|
97
|
+
|
|
98
|
+
Analytics data is not anonymous by default. A GA4 property can carry a `userId` you set
|
|
99
|
+
yourself, a device identifier, or a Google Signals pseudonymous ID. An MCP conversation sends
|
|
100
|
+
whatever a tool returns to a model.
|
|
101
|
+
|
|
102
|
+
**Identifiers are redacted by default wherever this server can return them**, and showing them
|
|
103
|
+
is an explicit opt-in, never the default.
|
|
104
|
+
|
|
105
|
+
| Tool | Behaviour |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `ga4_list_admin_resources` | Access bindings have user and email identifiers redacted |
|
|
108
|
+
| `ga4_query_audience_export` | Identifier columns redacted, matched against the export's own dimension metadata |
|
|
109
|
+
| `ga4_get_audience_export_diagnostics` | Same redaction on the row sample |
|
|
110
|
+
|
|
111
|
+
Every one of these accepts `includePersonalIdentifiers: true` to return raw values, and
|
|
112
|
+
defaults to `false`.
|
|
113
|
+
|
|
114
|
+
Audience export rows are positional, so the redaction reads the export's dimension metadata to
|
|
115
|
+
find identifier columns. **If that metadata is missing, every value in the row is redacted**
|
|
116
|
+
rather than guessing which column is safe. Failing closed is the point.
|
|
117
|
+
|
|
118
|
+
**Report rows are not redacted.** `ga4_run_report` and the other reporting tools return what
|
|
119
|
+
you asked for. Altering the numbers a report returns would be worse than returning them.
|
|
120
|
+
|
|
121
|
+
So one decision stays yours: if your property carries a `userId` you consider personal, do not
|
|
122
|
+
request it as a report dimension in a conversation whose transcript leaves your machine.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Getting credentials
|
|
127
|
+
|
|
128
|
+
Three values, obtained once.
|
|
129
|
+
|
|
130
|
+
### 1. OAuth client
|
|
131
|
+
|
|
132
|
+
In a [Google Cloud project](https://console.cloud.google.com/), enable the **Google Analytics
|
|
133
|
+
Data API** and the **Google Analytics Admin API**, then create an OAuth client under
|
|
134
|
+
**APIs & Services → Credentials**. Choose **Desktop app** for local use. Note the **client ID**
|
|
135
|
+
and **client secret**.
|
|
136
|
+
|
|
137
|
+
### 2. Refresh token
|
|
138
|
+
|
|
139
|
+
Run the OAuth consent flow once, signed in as a Google account with access to your GA4
|
|
140
|
+
properties, and keep the **refresh token**. The `analytics.readonly` scope is enough, and it
|
|
141
|
+
is the only one you should grant.
|
|
142
|
+
|
|
143
|
+
📖 [Google OAuth for installed apps](https://developers.google.com/identity/protocols/oauth2/native-app)
|
|
144
|
+
|
|
145
|
+
**The refresh token does not expire.** It is the sensitive value: anyone holding it can mint
|
|
146
|
+
access tokens indefinitely. Use an OAuth client dedicated to this server so you can revoke it
|
|
147
|
+
on its own.
|
|
148
|
+
|
|
149
|
+
### 3. Property ID, optional
|
|
150
|
+
|
|
151
|
+
Set `GA4_PROPERTY_ID` to avoid passing it on every call. Find it in GA4 under
|
|
152
|
+
**Admin → Property Settings**, or list them with `ga4_list_properties`.
|
|
153
|
+
|
|
154
|
+
Run **`ga4_health_check`** as your first call. It verifies the credentials and lists the
|
|
155
|
+
properties you can actually reach, without printing any secret.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Setup
|
|
160
|
+
|
|
161
|
+
### Claude Desktop
|
|
162
|
+
|
|
163
|
+
`~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
164
|
+
or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"google-analytics": {
|
|
170
|
+
"command": "npx",
|
|
171
|
+
"args": ["-y", "@getmcpads/google-analytics-mcp-server"],
|
|
172
|
+
"env": {
|
|
173
|
+
"GA4_CLIENT_ID": "your-client-id",
|
|
174
|
+
"GA4_CLIENT_SECRET": "your-client-secret",
|
|
175
|
+
"GA4_REFRESH_TOKEN": "your-refresh-token"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Restart Claude Desktop. Ask it: *"list my Google Analytics properties"*.
|
|
183
|
+
|
|
184
|
+
### Claude Code
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
claude mcp add google-analytics --env GA4_CLIENT_ID=... --env GA4_CLIENT_SECRET=... --env GA4_REFRESH_TOKEN=... -- npx -y @getmcpads/google-analytics-mcp-server
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Cursor
|
|
191
|
+
|
|
192
|
+
`.cursor/mcp.json` in your project, same shape as the Claude Desktop config above.
|
|
193
|
+
|
|
194
|
+
### From source
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
git clone https://github.com/getmcpads-com/google-analytics-mcp-server.git
|
|
198
|
+
cd google-analytics-mcp-server
|
|
199
|
+
npm install && npm run build
|
|
200
|
+
cp .env.example .env # then fill in your credentials
|
|
201
|
+
npm start
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Configuration
|
|
205
|
+
|
|
206
|
+
| Variable | Default | Meaning |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| `GA4_CLIENT_ID` | none | **Required.** OAuth client ID |
|
|
209
|
+
| `GA4_CLIENT_SECRET` | none | **Required.** OAuth client secret |
|
|
210
|
+
| `GA4_REFRESH_TOKEN` | none | **Required.** From the consent flow |
|
|
211
|
+
| `GA4_PROPERTY_ID` | none | Optional default, saves passing it on every call |
|
|
212
|
+
| `LOG_LEVEL` | `info` | `debug`, `info`, `warn`, `error` |
|
|
213
|
+
|
|
214
|
+
Check your setup at any time:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npm run doctor
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Tools
|
|
223
|
+
|
|
224
|
+
<details>
|
|
225
|
+
<summary><b>27 read tools</b></summary>
|
|
226
|
+
|
|
227
|
+
### Discovery and health
|
|
228
|
+
| Tool | Purpose |
|
|
229
|
+
|---|---|
|
|
230
|
+
| `ga4_health_check` | Validates credentials and lists reachable properties |
|
|
231
|
+
| `ga4_list_accounts` / `ga4_list_properties` | Accounts and properties you can reach |
|
|
232
|
+
| `ga4_get_property_configuration` | Timezone, currency, industry, data retention |
|
|
233
|
+
| `ga4_get_metadata` | Metrics and dimensions available on a given property |
|
|
234
|
+
|
|
235
|
+
### Reporting
|
|
236
|
+
| Tool | Purpose |
|
|
237
|
+
|---|---|
|
|
238
|
+
| `ga4_run_report` | The main reporting tool. Named metrics and dimensions |
|
|
239
|
+
| `ga4_run_pivot_report` | Pivot tables |
|
|
240
|
+
| `ga4_batch_run_reports` / `ga4_batch_run_pivot_reports` | Several reports in one call |
|
|
241
|
+
| `ga4_run_realtime_report` | The last 30 minutes |
|
|
242
|
+
| `ga4_run_advanced_funnel_report` | Funnel analysis with step conditions |
|
|
243
|
+
| `ga4_run_funnel_recipe` | Prebuilt funnels for common journeys |
|
|
244
|
+
| `ga4_validate_query` / `ga4_check_compatibility` | Check a combination *before* running it |
|
|
245
|
+
|
|
246
|
+
### Configuration
|
|
247
|
+
| Tool | Purpose |
|
|
248
|
+
|---|---|
|
|
249
|
+
| `ga4_list_admin_resources` | Data streams, users, links. Access-binding identifiers redacted |
|
|
250
|
+
| `ga4_get_custom_definitions` | Custom dimensions and metrics |
|
|
251
|
+
| `ga4_get_key_events` | Key events and their counting method |
|
|
252
|
+
| `ga4_get_channel_groups` | Default and custom channel groupings |
|
|
253
|
+
| `ga4_get_event_parameters` | Parameters actually collected on an event |
|
|
254
|
+
|
|
255
|
+
### Audiences
|
|
256
|
+
| Tool | Purpose |
|
|
257
|
+
|---|---|
|
|
258
|
+
| `ga4_get_audience_diagnostics` | Audience definitions and their health |
|
|
259
|
+
| `ga4_list_audience_exports` / `ga4_query_audience_export` | Audience exports and their rows |
|
|
260
|
+
| `ga4_get_audience_export_diagnostics` | Why an export is empty or stale |
|
|
261
|
+
|
|
262
|
+
### Diagnostics
|
|
263
|
+
| Tool | Purpose |
|
|
264
|
+
|---|---|
|
|
265
|
+
| `ga4_get_ecommerce_diagnostics` | Whether ecommerce events are complete and coherent |
|
|
266
|
+
| `ga4_get_bigquery_export_diagnostics` | BigQuery export configuration and freshness |
|
|
267
|
+
| `ga4_get_server_side_tagging_diagnostics` | Server-side tagging signals |
|
|
268
|
+
| `ga4_get_property_quotas_snapshot` | Remaining Data API quota tokens |
|
|
269
|
+
|
|
270
|
+
</details>
|
|
271
|
+
|
|
272
|
+
<details>
|
|
273
|
+
<summary><b>6 resources</b></summary>
|
|
274
|
+
|
|
275
|
+
| URI | Contents |
|
|
276
|
+
|---|---|
|
|
277
|
+
| `ga4://manifest` | What this server exposes, and which tool to run first |
|
|
278
|
+
| `ga4://metrics` | All 51 metrics with categories and formats |
|
|
279
|
+
| `ga4://dimensions` | All 62 dimensions and where they are valid |
|
|
280
|
+
| `ga4://compatibility` | The compatibility matrix |
|
|
281
|
+
| `ga4://recipes` | 12 step-by-step workflows |
|
|
282
|
+
| `ga4://p2-diagnostics` | Diagnostic playbooks |
|
|
283
|
+
|
|
284
|
+
</details>
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Security
|
|
289
|
+
|
|
290
|
+
- **The client secret and refresh token are never logged**, at any log level, or written to disk.
|
|
291
|
+
- **Three hosts are contacted, and only three**: `analyticsdata.googleapis.com`,
|
|
292
|
+
`analyticsadmin.googleapis.com` and `oauth2.googleapis.com`. *A test fails the build if a
|
|
293
|
+
fourth host appears in the source.*
|
|
294
|
+
- **No fetch follows a redirect.** Every outbound call sets `redirect: "error"`, so a redirect
|
|
295
|
+
cannot forward a bearer token or client secret to another host. *A test fails the build if
|
|
296
|
+
any fetch omits this.*
|
|
297
|
+
- **No telemetry.** The server makes no network call other than to Google.
|
|
298
|
+
|
|
299
|
+
Full policy, including how personal data is handled: [SECURITY.md](SECURITY.md).
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Looking for a managed, multi-platform version?
|
|
304
|
+
|
|
305
|
+
This server does one platform, on your machine, with your credentials. That is on purpose.
|
|
306
|
+
|
|
307
|
+
If you'd rather not run it yourself, or you need Google Analytics **alongside Meta Ads, Google
|
|
308
|
+
Ads, TikTok Ads, Pinterest Ads and Search Console** behind one endpoint, with hosted OAuth and
|
|
309
|
+
cross-platform reporting, that's what we build at **[getmcpads.com](https://www.getmcpads.com)**.
|
|
310
|
+
|
|
311
|
+
Same philosophy, less plumbing. This project stays open source and independently useful
|
|
312
|
+
either way.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Contributing
|
|
317
|
+
|
|
318
|
+
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
319
|
+
Please read [SECURITY.md](SECURITY.md) before reporting anything security-related.
|
|
320
|
+
|
|
321
|
+
## Licence
|
|
322
|
+
|
|
323
|
+
[Apache License 2.0](LICENSE). See also [NOTICE](NOTICE).
|
|
324
|
+
|
|
325
|
+
Google, Google Analytics and GA4 are trademarks of Google LLC.
|
|
326
|
+
**This project is not affiliated with, endorsed by, or sponsored by Google LLC.**
|
|
327
|
+
It is an independent client of a public API.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|