发送统计数据

POST /api/send

要注册一个 event,需要向 /api/send 发送 POST 请求,数据格式如下:

对于 Umami Cloud,请发送 POST 请求到 https://cloud.umami.is/api/send

参数说明

payload

  • hostname:(字符串)主机名。
  • screen:(字符串)屏幕分辨率(例如 "1920x1080")
  • language:(字符串)访客语言(例如 "en-US")
  • url:(字符串)页面 URL。
  • referrer:(字符串)来源 URL。
  • title:(字符串)页面标题。
  • tag:(字符串)额外标签描述。
  • id:(字符串)会话标识符。
  • website:(字符串)网站 ID。
  • name:(字符串)事件名称。
  • data:(对象 | 可选)事件的额外数据。

type:(字符串)目前唯一支持的类型为 event

示例负载

{
  "payload": {
    "hostname": "your-hostname",
    "language": "en-US",
    "referrer": "",
    "screen": "1920x1080",
    "title": "dashboard",
    "url": "/",
    "website": "your-website-id",
    "name": "event-name",
    "data": {
      "foo": "bar"
    }
  },
  "type": "event"
}

注意,向 /api/send 发送请求时不需要提供认证令牌。

同时,需要发送正确的 User-Agent HTTP 头,否则请求将不会被注册。

示例响应

{
  "cache": "xxxxxxxxxxxxxxx",
  "sessionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "visitId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

程序生成示例

你可以使用浏览器的 JavaScript API 程序生成大部分参数。例如:

const data = {
  payload: {
    hostname: window.location.hostname,
    language: navigator.language,
    referrer: document.referrer,
    screen: `${window.screen.width}x${window.screen.height}`,
    title: document.title,
    url: window.location.pathname,
    website: 'your-website-id',
    name: 'event-name',
  },
  type: 'event',
};

On this page