TanStack Start 集成 PostHog
integration-tanstack-start
为 TanStack Start 全栈应用集成 PostHog
- License 许可
- AGPL-3.0
- 所属仓库
- baisharg/ASTN
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 2
01 前言 Front Matter
- name
- integration-tanstack-start
- metadata
- { "author": "PostHog", "version": "1.6.1" }
- description
- PostHog integration for TanStack Start full-stack applications
02 资源文件 7
- 参考文档references/basic-integration-1.0-begin.md2.1 KB
- 参考文档references/basic-integration-1.1-edit.md2.5 KB
- 参考文档references/basic-integration-1.2-revise.md914 B
- 参考文档references/basic-integration-1.3-conclude.md1.5 KB
- 参考文档references/EXAMPLE.md28.5 KB
- 参考文档references/identify-users.md8.1 KB
- 参考文档references/tanstack-start.md4.6 KB
03 SKILL.md 正文
PostHog integration for TanStack Start
This skill helps you add PostHog analytics to TanStack Start applications.
Workflow
Follow these steps in order to complete the integration:
basic-integration-1.0-begin.md- PostHog Setup - Begin ← Start herebasic-integration-1.1-edit.md- PostHog Setup - Editbasic-integration-1.2-revise.md- PostHog Setup - Revisebasic-integration-1.3-conclude.md- PostHog Setup - Conclusion
Reference files
EXAMPLE.md- TanStack Start example project codetanstack-start.md- Tanstack start - docsidentify-users.md- Identify users - docsbasic-integration-1.0-begin.md- PostHog setup - beginbasic-integration-1.1-edit.md- PostHog setup - editbasic-integration-1.2-revise.md- PostHog setup - revisebasic-integration-1.3-conclude.md- PostHog setup - conclusion
The example project shows the target implementation pattern. Consult the documentation for API details.
Key principles
- Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
- Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
- Match the example: Your implementation should follow the example project's patterns as closely as possible.
Framework guidelines
- For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
- Add analytics capture in event handlers where user actions occur, NOT in useEffect reacting to state changes
- Do NOT use useEffect for data transformation - calculate derived values during render instead
- Do NOT use useEffect to respond to user events - put that logic in the event handler itself
- Do NOT use useEffect to chain state updates - calculate all related updates together in the event handler
- Do NOT use useEffect to notify parent components - call the parent callback alongside setState in the event handler
- To reset component state when a prop changes, pass the prop as the component's key instead of using useEffect
- useEffect is ONLY for synchronizing with external systems (non-React widgets, browser APIs, network subscriptions)
- Use PostHogProvider in the root route (__root.tsx) for client-side tracking
- Use posthog-node for server-side event capture in API routes (src/routes/api/) - do NOT use posthog-js on the server
- Create a singleton PostHog server client to avoid re-initialization on every request
- Use TanStack Router's built-in navigation events for pageview tracking instead of useEffect
- Use PostHogProvider in the root component defined in either the file-based convention (__root.tsx) or code-based convention (wherever createRootRoute() is called) so all child routes have access to the PostHog client
- Remember that source code is available in the node_modules directory
- Check package.json for type checking or build scripts to validate changes
- posthog-js is the JavaScript SDK package name
Identifying users
Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to maintain correlation.
Error tracking
Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.
04 同仓库更多 Skills
Convex 数据库模式设计
schema-builder
设计并生成 Convex 数据库模式(schema),包含完善的验证、索引和关系。在创建 schema.ts 或修改表定义时使用。
migration-helper
Plan and execute Convex schema migrations safely, including adding fields, creating tables, and data transformations. Use when schema changes affect existing data.
gsd:sprint
Autonomous phase execution with Codex validation. Runs plan/execute/verify cycles in a bash loop until done or halted.
gsd:second-opinion
Get a second opinion from OpenAI Codex (GPT-5.2-codex) on code, architecture, or implementation decisions. Use when you want independent verification or an alternative perspective.
gsd:milestone-sprint
Run entire milestone autonomously with Codex validation. Auto-detects current milestone, executes all phases, and runs audit.
gsd:health-check
Verify GSD setup - checks Claude, Codex, skills, and MCP servers are working correctly.