diff --git a/app/src/core/analytics/PostHogProvider.tsx b/app/src/core/analytics/PostHogProvider.tsx index 367cf64d..e964076c 100644 --- a/app/src/core/analytics/PostHogProvider.tsx +++ b/app/src/core/analytics/PostHogProvider.tsx @@ -11,7 +11,7 @@ */ import React from 'react'; -import { PostHogProvider as PHProvider } from 'posthog-react-native'; +import { PostHogProvider as PHProvider, usePostHog } from 'posthog-react-native'; import { useConsentStore } from '@/core/stores/consentStore'; import { env } from '@/core/config/env'; @@ -23,6 +23,26 @@ interface PostHogProviderProps { children: React.ReactNode; } +/** + * Tags every PostHog event with `surface: 'app'` so the app's data + * stays distinguishable from being-website's data in the shared PostHog + * project (free-tier constraint: 1 project per account). The website + * mirrors this with `ph.register({ surface: 'web' })` in its own + * PosthogProvider — see mp2ez/being-website#42. + * + * Renders inside so `usePostHog()` returns the initialized + * instance. Runs once when the instance becomes available. + */ +function RegisterSurfaceProperty(): null { + const posthog = usePostHog(); + React.useEffect(() => { + if (posthog) { + posthog.register({ surface: 'app' }); + } + }, [posthog]); + return null; +} + /** * PostHog Provider Component * @@ -69,6 +89,7 @@ export function PostHogProvider({ children }: PostHogProviderProps): React.React captureAppLifecycleEvents: false, // We handle this ourselves }} > + {children} );