'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 {children} }