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/red-dots-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@posthog/nuxt': minor
---

added name to nuxt client plugin
59 changes: 31 additions & 28 deletions packages/nuxt/src/runtime/vue-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#app'
import posthog from 'posthog-js'
import type { PostHogClientConfig, PostHogCommon } from '../module'

export default defineNuxtPlugin((nuxtApp) => {
const runtimeConfig = useRuntimeConfig()
const posthogCommon = runtimeConfig.public.posthog as PostHogCommon
const posthogClientConfig = runtimeConfig.public.posthogClientConfig as PostHogClientConfig

// prevent nitro from trying to load this
if (!window || posthog.__loaded) {
return
}

posthog.init(posthogCommon.publicKey, {
api_host: posthogCommon.host,
...posthogClientConfig,
})

if (posthogCommon.debug) {
posthog.debug(true)
}

if (autocaptureEnabled(posthogClientConfig)) {
nuxtApp.hook('vue:error', (error, info) => {
posthog.captureException(error, { info })
export default defineNuxtPlugin({
name: 'posthog-client',
setup(nuxtApp) {
const runtimeConfig = useRuntimeConfig()
const posthogCommon = runtimeConfig.public.posthog as PostHogCommon
const posthogClientConfig = runtimeConfig.public.posthogClientConfig as PostHogClientConfig

// prevent nitro from trying to load this
if (!window || posthog.__loaded) {
return
}

posthog.init(posthogCommon.publicKey, {
api_host: posthogCommon.host,
...posthogClientConfig,
})
}

return {
provide: {
posthog: () => posthog,
},
}
if (posthogCommon.debug) {
posthog.debug(true)
}

if (autocaptureEnabled(posthogClientConfig)) {
nuxtApp.hook('vue:error', (error, info) => {
posthog.captureException(error, { info })
})
}

return {
provide: {
posthog: () => posthog,
},
}
},
})

function autocaptureEnabled(config: PostHogClientConfig): boolean {
Expand Down
Loading