Skip to content
Merged
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
23 changes: 22 additions & 1 deletion app/src/core/analytics/PostHogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 <PHProvider> 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
*
Expand Down Expand Up @@ -69,6 +89,7 @@ export function PostHogProvider({ children }: PostHogProviderProps): React.React
captureAppLifecycleEvents: false, // We handle this ourselves
}}
>
<RegisterSurfaceProperty />
{children}
</PHProvider>
);
Expand Down
Loading