Skip to content

Commit 15ce95b

Browse files
docs: add PostHog analytics migration guide (#3314)
* docs: add PostHog analytics migration guide * fix(docs): address review comments on analytics migration guide - Correct feature flags service description: isEnabled() returns false (not fails-open) - Document requireFeatureFlag 401 for unauthenticated users - Remove undocumented personalApiKey references (not wired into PostHog client)
1 parent 28b371f commit 15ce95b

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

MIGRATIONS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@ Breaking changes and upgrade notes for downstream projects.
44

55
---
66

7+
## PostHog Analytics (2026-03-26)
8+
9+
Server-side analytics, user/org identification, API auto-capture, and feature flags via PostHog.
10+
11+
### New module
12+
13+
`modules/analytics/` — auto-discovered, no manual registration needed.
14+
15+
### Configuration
16+
17+
Uncomment and set in your env-specific config (e.g. `modules/analytics/config/analytics.development.config.js`):
18+
19+
```js
20+
posthog: {
21+
apiKey: process.env.DEVKIT_NODE_posthog_apiKey ?? '',
22+
host: process.env.DEVKIT_NODE_posthog_host ?? 'https://us.i.posthog.com',
23+
}
24+
```
25+
26+
All features are no-op when `apiKey` is empty — safe to deploy without PostHog.
27+
28+
### What's included
29+
30+
| Feature | File | Notes |
31+
|---------|------|-------|
32+
| Analytics service | `analytics.service.js` | `track()`, `identify()`, `groupIdentify()` |
33+
| Auto-capture middleware | `analytics.middleware.js` | Captures `api_request` on all routes (except health/public) |
34+
| Feature flags service | `analytics.featureFlags.service.js` | `isEnabled()` (safe default `false` when not configured), `getVariant()` (`undefined` when not configured) |
35+
| `requireFeatureFlag` middleware | `analytics.requireFeatureFlag.js` | 401 when unauthenticated, 403 when flag disabled, fail-open when analytics not configured |
36+
| Billing integration | `analytics.init.js` | Listens to `plan.changed` event → `groupIdentify` |
37+
38+
### Action for downstream
39+
40+
1. Run `/update-stack` to pull the new module
41+
2. Set env vars: `DEVKIT_NODE_posthog_apiKey`, `DEVKIT_NODE_posthog_host`
42+
3. No DB migration needed — all data stored in PostHog
43+
44+
---
45+
746
## Organizations & CASL v2 (2026-03-13)
847
948
This guide is for downstream projects (e.g. lou-node, pierreb-node) migrating to the new organizations + CASL document-level authorization system introduced on the `feature/signup-org-flow` branch.

modules/analytics/config/analytics.development.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const config = {
22
posthog: {
33
// apiKey: process.env.DEVKIT_NODE_posthog_apiKey ?? '',
44
// host: process.env.DEVKIT_NODE_posthog_host ?? 'https://us.i.posthog.com',
5-
// personalApiKey: process.env.DEVKIT_NODE_posthog_personalApiKey ?? '',
65
},
76
};
87

0 commit comments

Comments
 (0)