Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PostHog/skills --skill integration-react-vite -a claude-code
Open on GitHub

What 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 extra useEffect

How to install integration-react-vite

1Skills CLI (Vercel)

npx skills add PostHog/skills --skill integration-react-vite -a claude-code

2Manually: put the files in place

~/.claude/skills/integration-react-vite/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/integration-react-vite/

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

Similar skills

All skills for Frontend and UI →

From the same set112

The whole set →
feature-flags-api The feature-flags-api skill guides agents through adding PostHog feature flag checks to API applications. Use it when you want to introduce flags without restructuring existing code. CX Codex +1 111installs integration-react-native The integration-react-native skill guides an agent through adding PostHog analytics to a React Native app, including user identification and error tracking. CX Codex +1 109installs feature-flags-react-native feature-flags-react-native integrates PostHog feature flags into React Native apps following best practices for hooks, environment variables, and navigation. CX Codex +1 109installs integration-astro-ssr integration-astro-ssr adds PostHog analytics to server-rendered Astro setups with API endpoints. Connects frontend tracking with backend routes. CX Codex +1 109installs integration-swift integration-swift guides PostHog analytics integration into Swift applications across iOS and macOS targets. CX Codex +1 108installs omnibus-instrument-llm-analytics omnibus-instrument-llm-analytics adds PostHog LLM analytics to your code so each generation reports tokens, latency and cost. Installs the SDK too when the project has none. CX Codex +1 106installs integration-nextjs-pages-router The integration-nextjs-pages-router skill guides PostHog setup in Next.js Pages Router apps. It covers analytics events, user identity, feature flags, and error tracking. CX Codex +1 103installs integration-react-react-router-7-declarative integration-react-react-router-7-declarative integrates PostHog analytics into React Router v7 declarative mode projects. CX Codex +1 102installs

Project sponsors

Companies that keep this analytics open