发送统计数据
POST /api/send
要注册一个 event,需要向 /api/send 发送 POST 请求,数据格式如下:
对于 Umami Cloud,请发送 POST 请求到 https://cloud.umami.is/api/send。
参数说明
| Parameter | Type | Description |
|---|---|---|
payload.hostname | string | 主机名。 |
payload.screen | string | 屏幕分辨率(例如 "1920x1080")。 |
payload.language | string | 访问者语言(例如 "en-US")。 |
payload.url | string | 页面 URL。 |
payload.referrer | string | 引荐来源 URL。 |
payload.title | string | 页面标题。 |
payload.tag | string | 额外的标签描述。 |
payload.id | string | 会话标识符。 |
payload.website | string | 网站 ID。 |
payload.name | string | 事件名称。 |
payload.data | object | (可选)事件的附加数据。 |
type | string | 目前唯一可用的类型是 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',
};