integration-react-vite — Claude Code skill: PostHog for React + Vite
integration-react-vite adds PostHog analytics to a React app built with Vite and no router: setup in four steps, user identification, feature flags and error tracking.
MIT 107 installs ★ 80 updated 2026-10-24
npx skills add PostHog/skills --skill integration-react-vite -a claude-codeWhat integration-react-vite does
Four steps, in order: basic-integration-1.0-begin.md, then basic-integration-1.1-edit.md, basic-integration-1.2-revise.md and basic-integration-1.3-conclude.md. React docs and a user-identification guide sit next to them in references/. The skill edits the app you already have; it does not restructure it.
PostHog keys belong in environment variables and nowhere else. For flags there are useFeatureFlagEnabled() and useFeatureFlagPayload(), which take care of loading state and external sync on their own. useEffect gets a short leash: derived values are computed during render, user events are handled in the handler, parent callbacks fire beside setState, and a changed prop resets state through key. The hook stays for syncing with systems outside React.
Identification happens at login and signup. When a backend exists, the client session and distinct ID travel in X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers so the two sides correlate. Error tracking covers critical flows and API boundaries. The target is narrow: Vite, no router. Put a router in the app and the example stops matching.
What it helps with
- Wire PostHog into a Vite React app
- Move PostHog keys out of source into environment variables
- Track errors around critical user flows
- Correlate frontend events with backend sessions
- Swap manual flag checks for PostHog hooks
Example prompts for the agent
- Add PostHog to my Vite app, starting from
basic-integration-1.0-begin.md - Identify users on login following
references/identify-users.md - Set up a feature flag with
useFeatureFlagEnabled()and drop the extrauseEffect
How to install integration-react-vite
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-react-vite -a claude-code2Manually: put the files in place
~/.claude/skills/integration-react-vite/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/integration-react-vite/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-react-vite -a codex2Manually: put the files in place
.agents/skills/integration-react-vite/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-react-vite -a cursor2Manually: put the files in place
.cursor/skills/integration-react-vite/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PostHog/skills skills/posthog/all/skills/integration-react-vite2Manually: put the files in place
.github/skills/integration-react-vite/SKILL.md1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-react-vite -a gemini-cli2Platform CLI
gemini skills install https://github.com/PostHog/skills --path skills/posthog/all/skills/integration-react-viteManually: put the files in place
.devin/skills/integration-react-vite/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-react-vite -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about integration-react-vite
How do I install integration-react-vite in Claude Code?
Run npx skills add PostHog/skills --skill integration-react-vite -a claude-code. The skill file lands at ~/.claude/skills/integration-react-vite/SKILL.md.
What does integration-react-vite do?
It walks an agent through adding PostHog to a React app on Vite: four setup steps, user identification at login and signup, feature-flag hooks, error tracking around critical flows.
Will it work in an app that has a router?
The skill is written for Vite apps without a router, and the example project follows that structure. With a router in place you adapt the steps yourself.
Source text
SKILL.md · MIT
--- name: integration-react-vite description: PostHog integration for React applications built with Vite (no router) metadata: author: PostHog version: 1.9.4 --- # PostHog integration for React (Vite) This skill helps you add PostHog analytics to React (Vite) applications. ## Workflow Follow these steps in order to complete the integration: 1. `basic-integration-1.0-begin.md` - PostHog Setup - Begin ← **Start here** 2. `basic-integration-1.1-edit.md` - PostHog Setup - Edit 3. `basic-integration-1.2-revise.md` - PostHog Setup - Revise 4. `basic-integration-1.3-conclude.md` - PostHog Setup - Conclusion ## Reference files - `references/react.md` - React - docs - `references/identify-users.md` - Identify users - docs - `references/basic-integration-1.0-begin.md` - PostHog setup - begin - `references/basic-integration-1.1-edit.md` - PostHog setup - edit - `references/basic-integration-1.2-revise.md` - PostHog setup - revise - `references/basic-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) ## 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.
© PostHog · MIT · PostHog/skills