mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
36 lines
1009 B
TypeScript
36 lines
1009 B
TypeScript
'use client'
|
|
|
|
import posthog from 'posthog-js'
|
|
import { PostHogProvider as PHProvider } from 'posthog-js/react'
|
|
import { useEffect } from 'react'
|
|
|
|
function redactInviteUrl(defaultUrl: string): string {
|
|
const url = new URL(defaultUrl)
|
|
|
|
if (url.pathname.startsWith('/join/')) {
|
|
return `${url.origin}/join/[invite]`
|
|
}
|
|
|
|
return defaultUrl
|
|
}
|
|
|
|
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,
|
|
capture_pageleave: false,
|
|
get_current_url: redactInviteUrl,
|
|
})
|
|
}
|
|
}, [])
|
|
|
|
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) {
|
|
return <>{children}</>
|
|
}
|
|
|
|
return <PHProvider client={posthog}>{children}</PHProvider>
|
|
}
|