mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
25 lines
826 B
TypeScript
25 lines
826 B
TypeScript
'use client'
|
|
|
|
import posthog from 'posthog-js'
|
|
import { PostHogProvider as PHProvider } from 'posthog-js/react'
|
|
import { useEffect } from 'react'
|
|
|
|
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_POSTHOG_KEY) {
|
|
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
|
|
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://eu.i.posthog.com',
|
|
person_profiles: 'identified_only',
|
|
capture_pageview: false, // We'll capture pageviews manually for better control
|
|
capture_pageleave: true,
|
|
})
|
|
}
|
|
}, [])
|
|
|
|
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) {
|
|
return <>{children}</>
|
|
}
|
|
|
|
return <PHProvider client={posthog}>{children}</PHProvider>
|
|
}
|