Files
memind/docs/local-analytics.md
T

80 lines
3.2 KiB
Markdown
Raw Normal View History

2026-07-24 23:53:32 +08:00
# Local Memind analytics (Umami + Rybbit)
2026-07-16 21:06:28 +08:00
2026-07-24 23:53:32 +08:00
## Umami (optional)
2026-07-16 21:06:28 +08:00
2026-07-24 23:53:32 +08:00
Memind can still proxy `/analytics/*` to a local Umami service at
`http://127.0.0.1:3100`.
2026-07-16 21:06:28 +08:00
2026-07-24 23:53:32 +08:00
```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>
2026-07-20 20:49:44 +08:00
MEMIND_ANALYTICS_IDENTITY_MODE=raw
2026-07-24 23:53:32 +08:00
MEMIND_ANALYTICS_DOMAINS=127.0.0.1,localhost
```
2026-07-20 20:49:44 +08:00
`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.
2026-07-20 20:19:52 +08:00
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.
```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
2026-07-20 20:49:44 +08:00
same configured identity as generated pages while remaining in the separate
2026-07-20 20:19:52 +08:00
product Website.
2026-07-24 23:53:32 +08:00
## Rybbit (recommended for behavior analytics)
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:
2026-07-16 21:06:28 +08:00
2026-07-24 23:53:32 +08:00
```text
Generated Page
-> /rybbit/script.js -> https://rybbit.tkmind.cn/api/script.js
-> /rybbit/track -> https://rybbit.tkmind.cn/api/track
```
2026-07-16 21:06:28 +08:00
2026-07-24 23:53:32 +08:00
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`:
2026-07-16 21:06:28 +08:00
```dotenv
2026-07-24 23:53:32 +08:00
MEMIND_RYBBIT_ENABLED=true
MEMIND_RYBBIT_URL=https://rybbit.tkmind.cn
MEMIND_RYBBIT_SITE_ID=2
MEMIND_RYBBIT_ID_SECRET=<random-local-secret>
2026-07-16 21:06:28 +08:00
```
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 配置).
2026-07-24 23:53:32 +08:00
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
2026-07-24 23:53:32 +08:00
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.