npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@posthog/nuxt

v1.5.48

Published

Nuxt module for Posthog 🦔

Readme

PostHog Nuxt module

  • Handles sourcemap configuration and upload for the PostHog Error Tracking product
  • Provides posthog client and auto exception capture for Vue and Nitro

Please see the main PostHog Error tracking docs.

Usage

  1. Install the package
pnpm add @posthog/nuxt
  1. Configure posthog module
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@posthog/nuxt'], // Add module reference

  sourcemap: { client: 'hidden' }, // Make sure to set it (otherwise client sourcemaps will not be generated)

  nitro: {
    rollupConfig: {
      output: {
        sourcemapExcludeSources: false, // Make sure to set it (otherwise server sourcemaps will not be generated)
      },
    },
  },

  posthogConfig: {
    host: 'http://localhost:8010', // (optional) Host URL, defaults to https://us.posthog.com
    publicKey: 'public api key', // Your public web snippet key. You can find it in settings
    clientConfig?: Partial<PostHogConfig> // (optional) It will be passed to the posthog-js client on init in vue
    serverConfig?: PostHogOptions // (optional) It will be passed to the posthog-node client on init in nitro. Please note that this client instance is intended for error-tracking purposes only
    sourcemaps: {
      enabled: true, // Enables sourcemaps generation and upload
      projectId: '2', // Project ID, see https://app.posthog.com/settings/project#variables
      releaseName: 'my-application', // (optional) Release name, defaults to git repository name
      releaseVersion: '1.0.0', // (optional) Release version, defaults to current git commit
      personalApiKey: 'personal api key', // Your personal API key. You can generate it in settings -> Personal API keys
    },
  },
})
  1. You can access your vue posthog client inside vue using
// some-file.vue
const { $posthog } = useNuxtApp()

Composables

The module provides auto-imported composables for working with feature flags:

usePostHog()

Returns the PostHog client instance.

<script setup>
const posthog = usePostHog()

posthog.capture('event_name')
</script>

useFeatureFlagEnabled(flag: string)

Returns a reactive ref that checks if a feature flag is enabled (returns true/false/undefined).

<script setup>
const isEnabled = useFeatureFlagEnabled('my-flag')
</script>

<template>
  <div v-if="isEnabled">Feature is enabled!</div>
</template>

useFeatureFlagVariantKey(flag: string)

Returns a reactive ref containing the feature flag value/variant (returns the variant string, true/false, or undefined).

<script setup>
const variant = useFeatureFlagVariantKey('my-flag')
</script>

<template>
  <div v-if="variant === 'variant-a'">Show variant A</div>
  <div v-else-if="variant === 'variant-b'">Show variant B</div>
</template>

useFeatureFlagPayload(flag: string)

Returns a reactive ref containing the feature flag payload (returns any JSON value or undefined).

<script setup>
const payload = useFeatureFlagPayload('config-flag')
</script>

<template>
  <div v-if="payload">Config value: {{ payload.value }}</div>
</template>

All these composables automatically update when feature flags are loaded or changed.

  1. On the server side, the PostHog client instance initialized by the plugin is intended exclusively for error tracking. If you require additional PostHog client functionality for other purposes, please instantiate a separate client within your application as needed.

FAQ

Q: I see typescript errors in the posthog config after adding this module
A: It is possible that after adding a new module to `modules` typescript will complain about types. Solution is to remove `.nuxt` directory and regenerate it by running `build` command you are using. This will properly regenerate config types.
Q: I see stack traces but I do not see line context in the error tracking tab
A: Double check whether you enabled sourcemaps generation in the nuxt config both for vue and nitro. It is covered in the docs.

Developing this module

  1. Navigate into module directory
  2. Install dependencies using pnpm i
  3. Build the module using pnpm build
  4. Navigate into playground directory
  5. Install dependencies using npm i
  6. Build the playground using npm run build
  7. Run the playground using node .output/server/index.mjs

Questions?

Check out our community page.