nuxt-posthog icon indicating copy to clipboard operation
nuxt-posthog copied to clipboard

Feature request: Add posthog error tracking features

Open ghost opened this issue 5 months ago • 2 comments

Hello, is it possible to implement all error tracking features as listed here?: https://posthog.com/docs/error-tracking/installation?tab=Nuxt

  • Capture vue errors via hook
  • Source maps uploading

Thanks!

ghost avatar Jul 03 '25 09:07 ghost

@mitjans Im not certain, but maybe adding :

module.ts

  /**
   * If set to true, the module will catch server-side errors and log them to PostHog.
   * @default true
   * @type boolean
   */
  captureServerErrors?: boolean;
/**
   * If set to true, the module will catch client-side errors and log them to PostHog.
   * @default true
   * @type boolean
   */
  captureClientErrors?: boolean;
  
  ...

  captureServerErrors: true,
  captureClientErrors: true,

posthog.server.ts

    if (config.captureServerErrors) {
      nuxtApp.hook('app:error', (error) => {
        posthog.captureException(error);
      });
    }

posthog.client.ts

    if (config.captureClientErrors) {
      nuxtApp.hook('vue:error', (error) => {
        posthog.captureException(error);
      });
    }

would be enough?

rafazafar avatar Jul 16 '25 10:07 rafazafar

@mitjans please look at the suggestion from @rafazafar . Looks really easy to implement. I solved the source maps myself, but would also be nice...

Sourcemap example via nuxt.config.ts:

 'nitro:build:public-assets': async (nitro) => {
                // Upload sourcemaps to posthog in production
                if (process.env.ENV === 'production') {
                    console.log('Running PostHog sourcemap injection...');
                    try {
                        execSync(
                            'posthog-cli --host https://eu.posthog.com sourcemap inject --directory ' + nitro.options.output.publicDir,
                            {
                                stdio: 'inherit',
                            },
                        );
                        console.log('PostHog sourcemap injection completed successfully');
                    }
                    catch (error) {
                        console.error('PostHog sourcemap injection failed:', error);
                    }

                    console.log('Running PostHog sourcemap upload...');
                    try {
                        execSync(
                            'posthog-cli --host https://eu.posthog.com sourcemap upload --directory ' + nitro.options.output.publicDir,
                            {
                                stdio: 'inherit',
                            },
                        );
                        console.log('PostHog sourcemap upload completed successfully');
                    }
                    catch (error) {
                        console.error('PostHog sourcemap upload failed:', error);
                    }
                }
            },
```

ghost avatar Jul 23 '25 09:07 ghost