Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-socks-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@posthog/nuxt': patch
---

add posthog nuxt package
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: "@posthog/react"
- name: "@posthog/ai"
- name: "@posthog/nextjs-config"
- name: "@posthog/nuxt"

steps:
- name: Checkout the repository
Expand Down
24 changes: 24 additions & 0 deletions examples/example-nuxt-module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
7 changes: 7 additions & 0 deletions examples/example-nuxt-module/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 120
}
14 changes: 14 additions & 0 deletions examples/example-nuxt-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PostHog Nuxt module Example

This interactive example demonstrates error tracking capabilities of PostHog's Nuxt module.

## How to run

1. Run `pnpm i` in the repo root.
2. Run `pnpm build` in the repo root.
3. Run `pnpm package` in the repo root.
4. Run `pnpm i` inside this package.
5. Run `pnpm build` inside this package.
6. Run `node .output/server/index.mjs` inside this package

Now you can either visit `localhost:3000` and press buttons to throw frontend errors or visit `localhost:3000/error` to throw a nitro error
6 changes: 6 additions & 0 deletions examples/example-nuxt-module/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
<NuxtRouteAnnouncer />
<NuxtPage />
</div>
</template>
32 changes: 32 additions & 0 deletions examples/example-nuxt-module/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ['@posthog/nuxt'],
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
sourcemap: { client: 'hidden' },
nitro: {
rollupConfig: {
output: {
sourcemapExcludeSources: false,
},
},
},
posthogConfig: {
host: 'http://localhost:8010',
publicKey: process.env.POSTHOG_PROJECT_API_KEY!,
debug: true,
clientConfig: {
capture_exceptions: true,
},
serverConfig: {
enableExceptionAutocapture: true,
},
sourcemaps: {
enabled: true,
version: 'V1',
envId: '2',
project: 'i-love-nuxt-1',
personalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!,
},
},
})
18 changes: 18 additions & 0 deletions examples/example-nuxt-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "example-nuxt-module",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"nuxt": "^3.19.3",
"vue": "^3.5.22",
"vue-router": "^4.5.1",
"@posthog/nuxt": "*"
}
}
86 changes: 86 additions & 0 deletions examples/example-nuxt-module/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<div style="padding: 20px; font-family: sans-serif">
<h1>Error Testing Page</h1>
<p>Test various hard-to-catch errors:</p>

<div style="display: flex; flex-direction: column; gap: 10px; max-width: 400px">
<button @click="throwSimpleError" style="padding: 10px; cursor: pointer">1. Simple Synchronous Error</button>

<button @click="throwUncaughtPromiseRejection" style="padding: 10px; cursor: pointer">
2. Uncaught Promise Rejection
</button>

<button @click="throwAsyncError" style="padding: 10px; cursor: pointer">
3. Async Function Error (no catch)
</button>

<button @click="throwTimeoutError" style="padding: 10px; cursor: pointer">4. setTimeout Error</button>

<button @click="throwPromiseChainError" style="padding: 10px; cursor: pointer">5. Promise Chain Error</button>

<button @click="throwEventLoopError" style="padding: 10px; cursor: pointer">6. NextTick/Event Loop Error</button>

<button @click="throwNestedAsyncError" style="padding: 10px; cursor: pointer">7. Nested Async Error</button>
</div>
</div>
</template>

<script setup lang="ts">
import { throwSimpleError as utilThrowError } from '~/utils/errorUtils'

// 1. Simple synchronous error
const throwSimpleError = () => {
utilThrowError()
}

// 2. Uncaught promise rejection
const throwUncaughtPromiseRejection = () => {
Promise.reject(new Error('Uncaught promise rejection!'))
// Intentionally no .catch()
}

// 3. Async function error
const throwAsyncError = async () => {
await new Promise((resolve) => setTimeout(resolve, 100))
throw new Error('Async function error without catch!')
}

// 4. setTimeout error
const throwTimeoutError = () => {
setTimeout(() => {
throw new Error('Error thrown in setTimeout!')
}, 100)
}

// 5. Promise chain error
const throwPromiseChainError = () => {
Promise.resolve()
.then(() => {
return Promise.resolve('step 1')
})
.then(() => {
throw new Error('Error in promise chain!')
})
}

// 6. Error in nextTick
const throwEventLoopError = () => {
nextTick(() => {
throw new Error('Error in nextTick!')
})
}

// 7. Nested async error
const throwNestedAsyncError = () => {
const innerAsync = async () => {
await new Promise((resolve) => setTimeout(resolve, 50))
throw new Error('Nested async error!')
}

const outerAsync = async () => {
innerAsync()
}

outerAsync()
}
</script>
Loading
Loading