Skip to content

访问统计

访问统计接口用于获取页面访问数据、浏览趋势等信息。

所有接口都需要在请求头中携带 Bearer Token。

http
Authorization: Bearer <token>

1.1 获取访问统计概览

GET /admin/analytics/overview

用于管理后台「访问统计」页面展示整体访问数据,包括总 PV、总页面数、今日/昨日/本周/上周/本月/上月访问量以及最近 30 天的访问趋势。

  • 方法:GET
  • 路径:/admin/analytics/overview
  • 鉴权:需要(Bearer Token)

查询参数

名称位置类型必填说明
siteIdquerystring按站点 ID 筛选访问数据,如 blogdocs

成功响应

  • 状态码:200
json
{
  "totalPv": 1000,
  "totalPages": 50,
  "todayPv": 100,
  "yesterdayPv": 80,
  "weekPv": 500,
  "lastWeekPv": 400,
  "monthPv": 800,
  "lastMonthPv": 650,
  "last30Days": [
    {
      "date": "2026-01-15",
      "total": 20
    },
    {
      "date": "2026-01-16",
      "total": 25
    }
  ]
}

字段说明:

字段名类型说明
totalPvnumber总访问量(PV)
totalPagesnumber总页面数
todayPvnumber今日访问量
yesterdayPvnumber昨日访问量
weekPvnumber本周访问量
lastWeekPvnumber上周访问量(用于同比对比)
monthPvnumber本月访问量
lastMonthPvnumber上月访问量(用于同比对比)
last30DaysArray<DailyStat>最近 30 天的每日访问数(按自然日聚合)
last30Days[].datestring (YYYY-MM-DD)日期,UTC 时间格式化后的自然日
last30Days[].totalnumber当日访问总数

说明

  • weekPv:本周(从周一到当天)的总访问量
  • lastWeekPv:上周(上周一到上周日)的总访问量,用于与本周进行同比对比
  • monthPv:本月(从本月1号到当天)的总访问量
  • lastMonthPv:上月(上月1号到上月最后一天)的总访问量,用于与本月进行进行同比对比

错误响应

  • 状态码:500
json
{
  "message": "获取访问统计概览失败"
}

1.2 获取页面访问统计

GET /admin/analytics/pages

用于管理后台「访问统计」页面展示各个页面的访问明细,支持按 PV 排序或最新访问排序。

  • 方法:GET
  • 路径:/admin/analytics/pages
  • 鉴权:需要(Bearer Token)

查询参数

名称位置类型必填说明
siteIdquerystring按站点 ID 筛选访问数据,如 blogdocs
orderquerystring排序方式,pv(按访问量排序,默认)或 latest(最新访问)

说明:

  • 当前实现中固定返回前 20 条数据
  • order=pv:按访问量降序排序,访问量相同时按最后访问时间降序排序
  • order=latest:按最后访问时间降序排序,访问时间相同时按访问量降序排序

成功响应

  • 状态码:200
json
{
  "items": [
    {
      "postSlug": "https://example.com/blog/hello-world",
      "postTitle": "Hello World",
      "postUrl": "https://example.com/blog/hello-world",
      "pv": 100,
      "lastVisitAt": 1737593600000
    }
  ],
  "itemsByPv": [
    {
      "postSlug": "https://example.com/blog/hello-world",
      "postTitle": "Hello World",
      "postUrl": "https://example.com/blog/hello-world",
      "pv": 100,
      "lastVisitAt": 1737593600000
    }
  ],
  "itemsByLatest": [
    {
      "postSlug": "https://example.com/blog/hello-world",
      "postTitle": "Hello World",
      "postUrl": "https://example.com/blog/hello-world",
      "pv": 100,
      "lastVisitAt": 1737593600000
    }
  ]
}

字段说明:

字段名类型说明
itemsArray根据 order 参数返回的主列表
itemsByPvArrayorder=pv 规则排序后的前 20 条数据
itemsByLatestArrayorder=latest 规则排序后的前 20 条数据
postSlugstring文章唯一标识符
postTitlestring | null文章标题
postUrlstring | null文章 URL
pvnumber访问量(PV)
lastVisitAtnumber | null最后访问时间戳(毫秒)

错误响应

  • 状态码:500
json
{
  "message": "获取页面访问统计失败"
}

基于 Cloudflare Workers 构建