React error tracking installation
Install Add your PostHog API key and host to your environment variables. For Vite-based React apps, use the Wrap your app with the The Use the You can also import Click around and view a couple pages to generate some events. PostHog automatically captures pageviews, clicks, and other interactions for you. If you'd like, you can also manually capture custom events: You can enable exception autocapture for the JavaScript Web SDK in the Error tracking section of your project settings. When enabled, this automatically captures You can use the It is also possible to manually capture exceptions using the Install the package
Requiredposthog-js and @posthog/react using your package manager:Add environment variables
RequiredVITE_PUBLIC_ prefix:Initialize PostHog
RequiredPostHogProvider component at the root of your application (such as main.tsx if you're using Vite):defaults option automatically configures PostHog with recommended settings for new projects. See SDK defaults for details.Accessing PostHog in your code
RecommendedusePostHog hook to access the PostHog instance in any component wrapped by PostHogProvider:posthog directly for non-React code or utility functions:Send events
RecommendedSet up exception autocapture
Recommended$exception events when errors are thrown by wrapping the window.onerror and window.onunhandledrejection listeners.Set up error boundaries
OptionalPostHogErrorBoundary component to capture rendering errors thrown by components:Manually capture exceptions
OptionalcaptureException method:

