Plausible Analytics
Track events and query stats from Plausible Analytics (self-hosted or plausible.io).
Configuration
Set these environment variables before use:
CODEBLOCK0
Track Pageview
CODEBLOCK1
Options:
- -
--domain — Site domain (default: $PLAUSIBLESITEDOMAIN) - INLINECODE1 — Page URL being viewed (required)
- INLINECODE2 — Referring URL (optional)
- INLINECODE3 — Plausible base URL (default: $PLAUSIBLEBASEURL)
Track Custom Event
CODEBLOCK2
Options:
- -
--domain — Site domain - INLINECODE5 — Custom event name (e.g. "Signup", "Button Click")
- INLINECODE6 — JSON object with event properties (optional)
- INLINECODE7 — Plausible base URL
Get Stats Summary
CODEBLOCK3
Options:
- -
--domain — Site domain - INLINECODE9 — Time period:
6mo, 12mo, day, 7d, 30d, month (default: 30d) - INLINECODE16 — Compare to previous period:
previous_period (optional) - INLINECODE18 — Plausible base URL (default: $PLAUSIBLEBASEURL)
Returns: pageviews, unique visitors, bounce rate, visit duration, total pageviews
Get Top Pages
CODEBLOCK4
Options:
- -
--domain — Site domain - INLINECODE20 — Time period (default: 30d)
- INLINECODE21 — Number of pages to return (default: 10)
- INLINECODE22 — Plausible base URL
Get Realtime Visitors
CODEBLOCK5
Options:
- -
--domain — Site domain - INLINECODE24 — Plausible base URL
Returns: current visitors on site, pageviews in last 30 min, top pages currently viewed
Notes
- - The Events API (
/api/event) is used without authentication for tracking - The Stats API (
/api/v1/stats) requires PLAUSIBLE_API_KEY set in the request header - For self-hosted Plausible, set
PLAUSIBLE_BASE_URL to your instance - All scripts output JSON or plain text depending on the endpoint
Plausible Analytics
从 Plausible Analytics(自托管或 plausible.io)追踪事件并查询统计数据。
配置
使用前请设置以下环境变量:
bash
您的站点域名(例如 example.com)
export PLAUSIBLE
SITEDOMAIN=example.com
您的 Plausible API 密钥(用于统计接口)
export PLAUSIBLE
APIKEY=your-api-key
Plausible 基础 URL(托管版默认为 https://plausible.io)
自托管时,请设置为您的实例 URL
export PLAUSIBLE
BASEURL=https://plausible.io
追踪页面浏览
bash
bash skills/plausible-analytics/scripts/track.sh \
--domain $PLAUSIBLESITEDOMAIN \
--url https://example.com/blog/post-1 \
--referrer https://google.com
选项:
- - --domain — 站点域名(默认:$PLAUSIBLESITEDOMAIN)
- --url — 被浏览的页面 URL(必填)
- --referrer — 来源 URL(可选)
- --base-url — Plausible 基础 URL(默认:$PLAUSIBLEBASEURL)
追踪自定义事件
bash
bash skills/plausible-analytics/scripts/track.sh \
--domain $PLAUSIBLESITEDOMAIN \
--event Signup \
--props {\plan\:\pro\,\source\:\newsletter\}
选项:
- - --domain — 站点域名
- --event — 自定义事件名称(例如 Signup、Button Click)
- --props — 包含事件属性的 JSON 对象(可选)
- --base-url — Plausible 基础 URL
获取统计摘要
bash
bash skills/plausible-analytics/scripts/stats.sh \
--domain $PLAUSIBLESITEDOMAIN \
--period 30d \
--compare previous_period
选项:
- - --domain — 站点域名
- --period — 时间周期:6mo、12mo、day、7d、30d、month(默认:30d)
- --compare — 与上一周期比较:previousperiod(可选)
- --base-url — Plausible 基础 URL(默认:$PLAUSIBLEBASE_URL)
返回:页面浏览量、独立访客数、跳出率、访问时长、总页面浏览量
获取热门页面
bash
bash skills/plausible-analytics/scripts/top-pages.sh \
--domain $PLAUSIBLESITEDOMAIN \
--period 30d \
--limit 10
选项:
- - --domain — 站点域名
- --period — 时间周期(默认:30d)
- --limit — 返回的页面数量(默认:10)
- --base-url — Plausible 基础 URL
获取实时访客
bash
bash skills/plausible-analytics/scripts/realtime.sh \
--domain $PLAUSIBLESITEDOMAIN
选项:
- - --domain — 站点域名
- --base-url — Plausible 基础 URL
返回:站点当前访客数、最近 30 分钟页面浏览量、当前热门浏览页面
说明
- - 事件 API(/api/event)用于追踪,无需身份验证
- 统计 API(/api/v1/stats)需要在请求头中设置 PLAUSIBLEAPIKEY
- 对于自托管的 Plausible,请将 PLAUSIBLEBASEURL 设置为您的实例地址
- 所有脚本根据接口返回 JSON 或纯文本格式