plausible
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlausible Analytics API
Plausible Analytics API
Query website analytics and manage sites with Plausible's privacy-friendly analytics platform.
通过Plausible这款注重隐私的分析平台,查询网站分析数据并管理站点。
When to Use
适用场景
- Query visitor statistics and pageviews
- Analyze traffic sources and referrers
- Get geographic and device breakdowns
- Track conversions and goals
- Manage analytics sites programmatically
- 查询访客统计数据与页面浏览量
- 分析流量来源与引荐链接
- 获取地域分布及设备类型细分数据
- 追踪转化与目标完成情况
- 以编程方式管理分析站点
Prerequisites
前置条件
bash
export PLAUSIBLE_API_KEY=your-api-key
export PLAUSIBLE_SITE_ID=example.combash
export PLAUSIBLE_API_KEY=your-api-key
export PLAUSIBLE_SITE_ID=example.comGet API Key
获取API密钥
- Log in to Plausible: https://plausible.io/login
- Go to Account Settings (top-right menu)
- Navigate to "API Keys" in sidebar
- Click "New API Key"
- Choose key type:
- Stats API - For querying analytics data
- Sites API - For managing sites programmatically
- Save the key (shown only once)
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
- 登录Plausible:https://plausible.io/login
- 进入账户设置(右上角菜单)
- 在侧边栏中找到「API Keys」
- 点击「New API Key」
- 选择密钥类型:
- Stats API - 用于查询分析数据
- Sites API - 用于以编程方式管理站点
- 保存密钥(仅显示一次)
重要提示:当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
Stats API (v2)
Stats API (v2)
Basic Query - Total Visitors
基础查询 - 总访客数
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d"
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d"
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Query with Dimensions (Breakdown)
带维度的查询(细分)
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews", "bounce_rate"],
"date_range": "30d",
"dimensions": ["visit:source"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews", "bounce_rate"],
"date_range": "30d",
"dimensions": ["visit:source"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Top Pages
热门页面
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d",
"dimensions": ["event:page"],
"order_by": [["pageviews", "desc"]],
"pagination": {
"limit": 10
}
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d",
"dimensions": ["event:page"],
"order_by": [["pageviews", "desc"]],
"pagination": {
"limit": 10
}
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Geographic Breakdown
地域分布数据
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors"],
"date_range": "30d",
"dimensions": ["visit:country_name", "visit:city_name"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors"],
"date_range": "30d",
"dimensions": ["visit:country_name", "visit:city_name"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Device & Browser Stats
设备与浏览器统计
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors"],
"date_range": "7d",
"dimensions": ["visit:device"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors"],
"date_range": "7d",
"dimensions": ["visit:device"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Time Series (Daily)
时间序列(按日)
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "30d",
"dimensions": ["time:day"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "30d",
"dimensions": ["time:day"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Filter by Page Path
按页面路径过滤
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d",
"filters": [["contains", "event:page", ["/blog"]]]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": "7d",
"filters": [["contains", "event:page", ["/blog"]]]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'UTM Campaign Analysis
UTM推广活动分析
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "conversion_rate"],
"date_range": "30d",
"dimensions": ["visit:utm_source", "visit:utm_campaign"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "conversion_rate"],
"date_range": "30d",
"dimensions": ["visit:utm_source", "visit:utm_campaign"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Custom Date Range
自定义日期范围
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": ["2024-01-01", "2024-01-31"]
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"metrics": ["visitors", "pageviews"],
"date_range": ["2024-01-01", "2024-01-31"]
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X POST "https://plausible.io/api/v2/query" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Site Provisioning API
站点配置API
List Sites
列出所有站点
bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites"'bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites"'Create Site
创建站点
Write to :
/tmp/plausible_request.jsonjson
{
"domain": "newsite.com",
"timezone": "America/New_York"
}Then run:
bash
bash -c 'curl -s -X POST "https://plausible.io/api/v1/sites" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"domain": "newsite.com",
"timezone": "America/New_York"
}然后执行:
bash
bash -c 'curl -s -X POST "https://plausible.io/api/v1/sites" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Get Site Details
获取站点详情
Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/<your-site-id>"'替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/<your-site-id>"'Delete Site
删除站点
Warning: This will permanently delete the site and all its data.
Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X DELETE -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/<your-site-id>"'警告:此操作将永久删除该站点及其所有数据。
替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X DELETE -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/<your-site-id>"'Create Goal
创建目标
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"goal_type": "event",
"event_name": "Signup"
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/goals" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"goal_type": "event",
"event_name": "Signup"
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/goals" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Create Page Goal
创建页面目标
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"goal_type": "page",
"page_path": "/thank-you"
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/goals" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"goal_type": "page",
"page_path": "/thank-you"
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/goals" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'List Goals
列出所有目标
Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/goals?site_id=<your-site-id>"'替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -H "Authorization: Bearer $PLAUSIBLE_API_KEY" "https://plausible.io/api/v1/sites/goals?site_id=<your-site-id>"'Create Shared Link
创建共享链接
Write to :
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"name": "Public Dashboard"
}Replace with your actual site ID (typically your domain like "example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/shared-links" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'将以下内容写入:
/tmp/plausible_request.jsonjson
{
"site_id": "<your-site-id>",
"name": "Public Dashboard"
}替换为实际的站点ID(通常是你的域名,如"example.com"):
<your-site-id>bash
bash -c 'curl -s -X PUT "https://plausible.io/api/v1/sites/shared-links" -H "Authorization: Bearer $PLAUSIBLE_API_KEY" -H "Content-Type: application/json" -d @/tmp/plausible_request.json'Available Metrics
可用指标
| Metric | Type | Description |
|---|---|---|
| int | Unique visitors |
| int | Total sessions |
| int | Page views |
| float | Bounce rate (%) |
| int | Avg duration (seconds) |
| float | Pages per session |
| float | Goal conversion rate (requires goal to be configured) |
| int | Total events |
Note: Themetric requires at least one goal to be configured for your site. Create a goal first using the "Create Goal" or "Create Page Goal" endpoints before querying conversion rates.conversion_rate
| 指标 | 类型 | 描述 |
|---|---|---|
| int | 独立访客数 |
| int | 总会话数 |
| int | 页面浏览量 |
| float | 跳出率(%) |
| int | 平均会话时长(秒) |
| float | 每次会话浏览页面数 |
| float | 目标转化率(需先配置目标) |
| int | 总事件数 |
注意:指标要求你的站点至少配置一个目标。在查询转化率之前,请先使用「创建目标」或「创建页面目标」接口添加目标。conversion_rate
Available Dimensions
可用维度
Event Dimensions
事件维度
- - Custom goals
event:goal - - Page path
event:page - - Hostname
event:hostname
- - 自定义目标
event:goal - - 页面路径
event:page - - 主机名
event:hostname
Visit Dimensions
访问维度
- - Traffic source
visit:source - - Full referrer URL
visit:referrer - - UTM source
visit:utm_source - - UTM medium
visit:utm_medium - - UTM campaign
visit:utm_campaign - - Country
visit:country_name - - Region/State
visit:region_name - - City
visit:city_name - - Device type
visit:device - - Browser name
visit:browser - - Browser version
visit:browser_version - - Operating system
visit:os - - OS version
visit:os_version
- - 流量来源
visit:source - - 完整引荐链接URL
visit:referrer - - UTM来源
visit:utm_source - - UTM媒介
visit:utm_medium - - UTM推广活动
visit:utm_campaign - - 国家
visit:country_name - - 地区/州
visit:region_name - - 城市
visit:city_name - - 设备类型
visit:device - - 浏览器名称
visit:browser - - 浏览器版本
visit:browser_version - - 操作系统
visit:os - - 操作系统版本
visit:os_version
Time Dimensions
时间维度
- - Auto granularity
time - - Hourly
time:hour - - Daily
time:day - - Weekly
time:week - - Monthly
time:month
- - 自动粒度
time - - 按小时
time:hour - - 按天
time:day - - 按周
time:week - - 按月
time:month
Filter Operators
过滤运算符
| Operator | Description |
|---|---|
| Equals any value |
| Not equals |
| Contains substring |
| Regex match |
| 运算符 | 描述 |
|---|---|
| 等于任意指定值 |
| 不等于 |
| 包含指定子串 |
| 正则匹配 |
Complex Filters
复杂过滤
json
["and", [
["is", "visit:country_name", ["United States"]],
["contains", "event:page", ["/blog"]]
]]json
["and", [
["is", "visit:country_name", ["United States"]],
["contains", "event:page", ["/blog"]]
]]Date Range Options
日期范围选项
| Value | Description |
|---|---|
| Today |
| Last 7 days |
| Last 28 days |
| Last 30 days |
| Current month |
| Last 6 months |
| Last 12 months |
| Current year |
| All time |
| Custom range |
| 值 | 描述 |
|---|---|
| 今天 |
| 过去7天 |
| 过去28天 |
| 过去30天 |
| 当前月份 |
| 过去6个月 |
| 过去12个月 |
| 当前年份 |
| 所有时间 |
| 自定义范围 |
Rate Limits
请求频率限制
- 600 requests per hour per API key
- 每个API密钥每小时最多600次请求
API Reference
API参考文档
- Stats API: https://plausible.io/docs/stats-api
- Sites API: https://plausible.io/docs/sites-api
- Main Docs: https://plausible.io/docs
- Stats API: https://plausible.io/docs/stats-api
- Sites API: https://plausible.io/docs/sites-api
- 主文档: https://plausible.io/docs