MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / PostHogProvider

Function PostHogProvider

packages/web/src/app/posthogProvider.tsx:41–111  ·  view source on GitHub ↗
({
    children,
    isDisabled,
    isPiiEnabled,
    posthogApiKey,
    sourcebotVersion,
    sourcebotInstallId,
}: PostHogProviderProps)

Source from the content-addressed store, hash-verified

39}
40
41export function PostHogProvider({
42 children,
43 isDisabled,
44 isPiiEnabled,
45 posthogApiKey,
46 sourcebotVersion,
47 sourcebotInstallId,
48}: PostHogProviderProps) {
49 const { data: session } = useSession();
50
51 useEffect(() => {
52 if (!isDisabled) {
53 posthog.init(posthogApiKey, {
54 // @see next.config.mjs for path rewrites to the "/ingest" route.
55 api_host: "/ingest",
56 person_profiles: 'identified_only',
57 capture_pageview: false,
58 autocapture: false,
59 // If PII is not enabled, we don't want to capture the following
60 // default properties that may contain PII.
61 // @see: https://posthog.com/docs/data/events#default-properties
62 property_denylist: isPiiEnabled === false ? [
63 '$current_url',
64 '$pathname',
65 '$session_entry_url',
66 '$session_entry_host',
67 '$session_entry_pathname',
68 '$session_entry_referrer',
69 '$session_entry_referring_domain',
70 '$referrer',
71 '$referring_domain',
72 '$ip',
73 ] : [],
74 loaded: (posthog) => {
75 // Include install id & version in all events.
76 posthog.register({
77 sourcebot_version: sourcebotVersion,
78 install_id: sourcebotInstallId,
79 });
80 posthog.group('company', sourcebotInstallId);
81 }
82 });
83 } else {
84 console.debug("PostHog telemetry disabled");
85 }
86 }, [isDisabled, isPiiEnabled, posthogApiKey, sourcebotInstallId, sourcebotVersion]);
87
88 useEffect(() => {
89 if (!session) {
90 return;
91 }
92
93 posthog.identify(
94 session.user.id,
95 isPiiEnabled === true ? {
96 email: session.user.email,
97 name: session.user.name,
98 } : undefined

Callers

nothing calls this directly

Calls 1

initMethod · 0.80

Tested by

no test coverage detected