You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: context/commandments.yaml
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ commandments:
34
34
# Server-side feature flags
35
35
- Server Components and Route Handlers cannot use React hooks - use posthog-node SDK instead
36
36
- Create a server-side PostHog client with posthog-node, call getAllFlags() or getFeatureFlag(), then await posthog.shutdown()
37
-
- 'Route Handlers and Server Actions are short-lived per request — create the posthog-node client with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the function freezes before the event is sent and it is silently dropped'
37
+
- 'Route Handlers and Server Actions are short-lived per request. Create the posthog-node client with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the function freezes before the event is sent and it is silently dropped'
38
38
- Pass flag values from server to client components as props to avoid hydration mismatches
39
39
# Avoiding flicker
40
40
- For flags that affect initial render, evaluate server-side and pass as props to prevent UI flicker
@@ -57,8 +57,8 @@ commandments:
57
57
- 'Include enableExceptionAutocapture: true in the PostHog constructor options'
58
58
- Add posthog.capture() calls in route handlers for meaningful user actions – every route that creates, updates, or deletes data should track an event with contextual properties
59
59
- Add posthog.captureException(err, distinctId) in the application's error handler (e.g., Express error middleware, Fastify setErrorHandler, Koa app.on('error'))
60
-
- The SDK batches events and flushes asynchronously. Only rely on that default in a process you keep alive yourself — a standalone server you run, or a long-lived worker.
61
-
- '`posthog.capture()` enqueues synchronously and returns; the batched HTTP send happens afterwards. Treat every per-request handler as short-lived even when the framework feels like a server — Next.js / Nuxt / SvelteKit / Remix route handlers, serverless and edge functions, and Lambda are torn down per invocation before the send runs. Create the client with flushAt 1 and flushInterval 0, then await the send before returning — `await posthog.flush()` for a shared/singleton client, `await posthog.shutdown()` for a per-request client. Skip the awaited flush and the enqueued event is silently dropped.'
60
+
- The SDK batches events and flushes asynchronously. await flush() or await shutdown() before letting that process exit. If unsure, set flushAt 1 and flushInterval 0.
61
+
- '`posthog.capture()` enqueues synchronously and returns; the batched HTTP send happens afterwards. Treat every per-request handler as short-lived even when the framework feels like a server: Next.js / Nuxt / SvelteKit / Remix route handlers, serverless and edge functions, and Lambda are torn down per invocation before the send runs. Create the client with flushAt 1 and flushInterval 0, then await the send before returning. Always use `await posthog.flush()` for a shared/singleton client, `await posthog.shutdown()` for a per-request client. Never skip the awaited flush or risk the enqueued event being silently dropped.'
62
62
- Reverse proxy is NOT needed for server-side Node.js – only client-side JavaScript needs a proxy to avoid ad blockers
63
63
64
64
python:
@@ -196,7 +196,7 @@ commandments:
196
196
- Test queries in the PostHog SQL editor before using them in insights or the API
197
197
198
198
sveltekit:
199
-
- 'For server-side capture (+server.ts endpoints, actions, hooks like handleError), the handler is short-lived per request — configure the posthog-node singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the batched event is silently dropped when the request ends'
199
+
- 'For server-side capture (+server.ts endpoints, actions, hooks like handleError), the handler is short-lived per request. Configure the posthog-node singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the batched event is silently dropped when the request ends'
200
200
- Set paths.relative to false in svelte.config.js — this is required for PostHog session replay to work correctly with SSR and is easy to miss
201
201
- Use the Svelte MCP server tools to check Svelte documentation (list-sections, get-documentation) and validate components (svelte-autofixer) — always run svelte-autofixer on new or modified .svelte files before finishing
202
202
@@ -256,13 +256,13 @@ commandments:
256
256
astro-ssr:
257
257
- Use posthog-node in API routes under src/pages/api/ for server-side event tracking
258
258
- Store the posthog-node client instance in a singleton pattern (src/lib/posthog-server.ts) to avoid creating multiple clients
259
-
- Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response — an SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped
259
+
- 'Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response. An SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped'
260
260
- Pass the client session ID to server via X-PostHog-Session-Id header for unified session tracking
261
261
262
262
astro-hybrid:
263
263
- Use posthog-node in API routes under src/pages/api/ for server-side event tracking
264
264
- Store the posthog-node client instance in a singleton pattern (src/lib/posthog-server.ts) to avoid creating multiple clients
265
-
- Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response — an SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped
265
+
- 'Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response. An SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped'
266
266
- In Astro 5, use output static (the default) with an adapter - pages are prerendered by default
267
267
- Use export const prerender = false to opt specific pages into SSR when they need server-side rendering
268
268
- Only pages that need server-side PostHog tracking (like API-backed forms) should opt out of prerendering
0 commit comments