T
TanStack5w ago
environmental-rose

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);
}
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?
React - Docs - PostHog
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…
1 Reply
inland-turquoise
inland-turquoise2w ago
Any luck with this? Also running into issues setting up PostHog with TanStack Start. Did you run into hydration issues? Stuck on that right now

Did you find this page helpful?