feat(analytics): retire Rybbit and add SEO/GEO discovery tracking

Document Umami as the sole analytics platform, remove Rybbit proxy and
tracker code, and classify public page traffic with discovery_channel for
adm SEO/GEO dashboards.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-12 01:34:05 +08:00
parent c58a23d155
commit c122bd5664
26 changed files with 466 additions and 449 deletions
+15 -56
View File
@@ -1,79 +1,38 @@
# Local Memind analytics (Umami + Rybbit)
# Local Memind analytics (Umami)
## Umami (optional)
> **Rybbit 已退役**,见 [analytics-platform.md](analytics-platform.md)。下文仅描述 Umami。
Memind can still proxy `/analytics/*` to a local Umami service at
`http://127.0.0.1:3100`.
Memind 通过同源 `/analytics/*` 代理本地或远程 Umami 服务(默认 `http://127.0.0.1:3100`)。
```dotenv
MEMIND_ANALYTICS_ENABLED=true
MEMIND_ANALYTICS_URL=http://127.0.0.1:3100
MEMIND_ANALYTICS_WEBSITE_ID=<website-id>
MEMIND_ANALYTICS_ID_SECRET=<random-local-secret>
MEMIND_ANALYTICS_IDENTITY_MODE=raw
MEMIND_ANALYTICS_IDENTITY_MODE=pseudonymous
MEMIND_ANALYTICS_DOMAINS=127.0.0.1,localhost
```
`MEMIND_ANALYTICS_IDENTITY_MODE=raw` sends the stable Memind user ID to an
explicitly approved first-party analytics service. Omit it elsewhere to keep the
pseudonymous default.
`MEMIND_ANALYTICS_IDENTITY_MODE=raw` 仅在明确批准的第一方分析环境中使用;其他环境保持 pseudonymous 默认。
Create a second Umami Website for the Memind product shell. Keeping it separate
prevents chat, MindSpace, and feedback navigation from inflating generated-page
views. Do not create a Website per page or per user.
## Product shell(独立 Website
为 Memind 产品壳(H5 SPA)创建第二个 Umami Website,避免聊天与导航事件污染生成页 PV:
```dotenv
MEMIND_PRODUCT_ANALYTICS_ENABLED=true
MEMIND_PRODUCT_ANALYTICS_WEBSITE_ID=<product-website-id>
```
The product shell loads its tracker from the same-origin
`/analytics/script.js` endpoint. It records one standard page view per SPA route
transition, `product_click` for links/buttons, and 10/30-second route engagement
events. Query strings are restricted to a small allowlist and click labels never
copy arbitrary chat or generated-page text. Authenticated product events use the
same configured identity as generated pages while remaining in the separate
product Website.
产品壳 tracker 同样走 `/analytics/script.js`,记录 SPA 路由 PV、`product_click` 与 10/30 秒参与事件。
## Rybbit (recommended for behavior analytics)
## SEO / GEO 发现流量
Rybbit runs on 105 as `https://rybbit.tkmind.cn`. Local Memind does not talk to
103 for analytics. It proxies same-origin `/rybbit/*` to Rybbit `/api/*` so the
browser script stays first-party:
公开页 Umami 事件附带 `discovery_channel``seo` / `geo` / `direct` / `referral`)与 `discovery_source`。memind_adm **Analytics → SEO / GEO 流量** 看板按页展示 SEO 与 GEO 来源的浏览明细(口径与 Umami「生成页明细」一致)。
```text
Generated Page
-> /rybbit/script.js -> https://rybbit.tkmind.cn/api/script.js
-> /rybbit/track -> https://rybbit.tkmind.cn/api/track
```
## 管理后台
1. In Rybbit, create one Site for the local host you use (`127.0.0.1` or
`localhost`). Do not create a Site per page or per user.
2. Put the numeric Site ID and a local pseudonymization secret in Memind `.env`:
- **memind_adm → Analytics 配置**Umami Website ID、密钥、SSO 入口
- **memind_adm → SEO / GEO 流量**:按页监控搜索引擎 / 生成式引擎来源访问
```dotenv
MEMIND_RYBBIT_ENABLED=true
MEMIND_RYBBIT_URL=https://rybbit.tkmind.cn
MEMIND_RYBBIT_SITE_ID=2
MEMIND_RYBBIT_ID_SECRET=<random-local-secret>
```
If `MEMIND_RYBBIT_ID_SECRET` is omitted, Portal bootstrap reuses the
MindSpace analytics secret stored in `mindspace_config` (the same value
configured below in memind_adm → Analytics 配置).
3. Restart the local Memind server. Full generated HTML pages receive a
same-origin `/rybbit/script.js` tracker. Publication routes under
`/u/:owner/pages/:slug` and `/MindSpace/:user/public/...` both receive
the tracker. The tracker identifies the visitor
with a stable pseudonymous owner ID, then records engagement events such as
`page_click`, scroll depth, and dwell time. Initial pageviews come from
Rybbit's site setting `trackInitialPageView`.
4. Open Rybbit from local `memind_adm` → Analytics 配置 →「打开 Rybbit 分析后台」
(SSO). That path requires matching `MEMIND_RYBBIT_SSO_SECRET` /
`RYBBIT_SSO_EMAIL` with the 105 Rybbit deployment.
Both integrations are fail-open: missing configuration or a down analytics
service leaves page generation and page delivery unchanged. Do not expose the
Rybbit or Umami dashboards directly to end users.
Analytics 服务 fail-open:未配置或 Umami 不可用时,页面生成与交付不受影响。勿向终端用户暴露 Umami 控制台。