如何透過 Privatus Analytics MCP Server 向 Claude 或 ChatGPT 查詢網站流量
Ask Claude or ChatGPT About Your Website Traffic with an MCP Server
Privatus Analytics 教程示範如何透過其 MCP server 連接 Claude 或 ChatGPT,讓用戶以自然語言查詢網站分析數據。文章列出 OAuth 和 API token 兩種登入方式,建議首次使用 OAuth 的 Read-only 權限,並示範設定與 curl 測試。
You want to know a simple thing. Which blog post brought the most visitors last month?
So you open your analytics dashboard. You pick a date range. You open three menus. You export a table. Then you copy it into a chat with an AI to ask what it means. Next week you do it all again.
There is a better way. You can let the AI look at your numbers itself. You just type a question, like you would ask a coworker.
This works through something called MCP. In this tutorial you will connect Claude or ChatGPT to your analytics, step by step. You will also learn how to keep it safe, so the AI can only read and cannot break anything.
What is MCP?
MCP stands for Model Context Protocol. It is a standard way for an AI app to talk to other tools. Think of a plug that fits many sockets. A tool that offers an MCP server says, "Here is a list of things you can ask me to do." The AI picks the right ones.
Privatus Analytics runs a hosted MCP server. It is a cookieless web analytics tool. The free plan gives you 10,000 events a month and up to 3 sites, with no card. If you use another analytics tool, check whether it has an MCP server too.
The server lives at this address:
https://privatusanalytics.com/mcp
It works with Claude, ChatGPT, Gemini CLI, Cursor and VS Code. This guide covers the most common ones.
Step 1: Pick how to sign in
You have two choices.
- OAuth. You click "connect", sign in, and approve. No secret key to copy. This is the easiest. You choose the workspace, and you choose Read-only or Full access.
-
API token. You make a key (it starts with
pat_) and put it in the config. This gives you the most control over exactly what the AI can touch.
For your first try, I suggest OAuth with Read-only. The read-only choice gives the AI the analytics.read permission and nothing more.
Step 2A: Connect Claude (desktop or web)
- Open Settings, then Connectors.
- Click Add custom connector.
- Name it "Privatus Analytics". Enter
https://privatusanalytics.com/mcpas the address. - A browser window opens. Sign in to Privatus Analytics, pick your workspace, choose Read-only, and approve.
Step 2B: Connect Claude Code
If you use Claude Code in a terminal, run this with your own token:
claude mcp add --transport http privatus https://privatusanalytics.com/mcp \
--header "Authorization: Bearer pat_YOUR_TOKEN"
Add --scope user to use it in every project. Add --scope project to share it with your team through a .mcp.json file. If you share it, use an environment variable for the token, so you never commit a secret.
Prefer OAuth? Leave out --header. Then run /mcp inside Claude Code and sign in there.
To make a token, go to Workspace settings, then API tokens. Pick only the analytics.read permission. Pick the sites it may see, and set an expiry date. The authentication page explains each option.
Step 2C: Connect ChatGPT
ChatGPT uses "custom connectors" for MCP.
- Turn on developer mode in ChatGPT's settings.
- Create a new connector.
- Enter
https://privatusanalytics.com/mcp. - Choose OAuth for sign-in.
- A window opens. Sign in to Privatus Analytics and approve.
Other tools have their own steps. Gemini CLI, Cursor and VS Code are covered on the MCP docs page.
Step 3: Check that it works
Before you ask the AI anything, you can test your token with curl. This lists the tools the server will give you:
curl https://privatusanalytics.com/mcp \
-H "Authorization: Bearer $PRIVATUS_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
With a read-only token the list is short. The server only shows tools that your token is allowed to use. That is a handy proof that the limits work.
Now call one tool by hand:
curl https://privatusanalytics.com/mcp \
-H "Authorization: Bearer $PRIVATUS_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0", "id": 2, "method": "tools/call",
"params": {
"name": "stats_aggregate",
"arguments": { "site_id": "pa_YOURSITEID", "period": "7d", "compare": "previous_period" }
}
}'
You get back the same numbers the dashboard shows. If this works, the AI will work too.
Step 4: Ask real questions
Open a chat in Claude or ChatGPT, and try prompts like these. They come from the docs:
- "Which pages on example.com got the most visitors from AI assistants last month, and how did that change from the month before?"
- "Compare signup conversion rate by channel for the last 90 days."
- "Are any of my uptime checks down right now?"
- "How do I track outbound links with Privatus Analytics?"
Replace example.com with your own site.
Behind the scenes, the AI picks tools by name. Tools are named like resource_verb. For the first prompt, it may call stats_breakdown with the page as the dimension, last month as the period, and a filter for the AI assistants channel. A usual path is: workspaces_list to find your workspace, sites_list to find your site, and then a stats tool for the numbers. The last example uses docs_search, which lets the AI read the docs.
You do not need to know any of this to use it. It is just good to know what is going on.
Staying safe
Giving an AI access to your tools is a big step. Here is how to keep it small and safe.
-
Use the smallest key. Give each AI its own token, with just the permissions and sites it needs, and an expiry date. If you only need reports,
analytics.readis enough. - Some actions are left to you. An AI can pick the wrong tool or the wrong ID. So the hard-to-undo actions are not done by the AI. These include deleting data, billing, access settings and API tokens. The AI only gets a link to the right page in the app, and you do it yourself.
- No secrets go through the chat. No tool takes a password or an API key, because chats are saved in a transcript.
- You get an email for risky actions. If an AI creates an export or changes a webhook with your token, you receive an email that names the action and the token.
- Check the list of tokens. An OAuth connection makes a token named after the app, with "(MCP)" at the end. You can see it in your token list and revoke it any time.
The full rules are on the MCP docs page.
When the AI gets it wrong
Language models can make mistakes. If a number looks odd, ask the AI which tool it called and with which settings. Then compare it with the dashboard. Stats come straight from the API, so the data is reliable, but the AI's reading of it may not be. Treat it like a quick helper and not a final judge.
What you get
- Plain-English questions about your traffic, in the chat app you already use
- No more exporting tables and pasting them into prompts
- A read-only connection, with hard-to-undo actions left to you
- Numbers with bots filtered out and no tracking cookies behind them
- A setup for Claude, Claude Code, ChatGPT, Gemini CLI, Cursor and VS Code
- A free plan with 10,000 events a month and up to 3 sites, no card needed
Try it
Start with a free account at privatusanalytics.com, add the script to your site, and wait for some visits. Then connect your AI of choice with the steps above. The pricing page shows what the paid plans add. The open-source parts of the project live in the Privatus Analytics GitHub organization.
來源:DEV Community · dev.to