TanStackT
TanStack3mo ago
1 reply
urgent-maroon

Anyone had any luck setting up Posthog with error tracking?

Hey folks,
I've been struggling with setting up Posthog in my Tanstack Start app. I've followed their official React docs but I can't get the error tracking to work.

I've initialized the <PosthogProvider /> inside __root.tsx and wrapped my RootDocument with it.
Seems to me that it would make sense to capture errors in the defaultOnCatch handler inside createTanStackRouter like so:
defaultOnCatch(error, errorInfo) {
  console.log("Router caught an error:", { error, errorInfo });
  if (typeof window !== "undefined" && posthog.__loaded) {
    posthog.captureException(error);
 }


However this doesn't seem to work at all as I don't see the errors inside my dashboard. Any suggestions?
PostHog makes it easy to get data about traffic and usage of your React app. Integrating PostHog into your site enables analytics about user behavior
Was this page helpful?