MCPcopy
hub / github.com/janhq/jan / AnalyticProvider

Function AnalyticProvider

web-app/src/providers/AnalyticProvider.tsx:7–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { useAnalytic } from '@/hooks/useAnalytic'
6
7export function AnalyticProvider() {
8 const { productAnalytic } = useAnalytic()
9 const serviceHub = useServiceHub()
10
11 useEffect(() => {
12 if (!POSTHOG_KEY || !POSTHOG_HOST) {
13 console.warn(
14 'PostHog not initialized: Missing POSTHOG_KEY or POSTHOG_HOST environment variables'
15 )
16 return
17 }
18 if (productAnalytic) {
19 posthog.init(POSTHOG_KEY, {
20 api_host: POSTHOG_HOST,
21 autocapture: false,
22 capture_pageview: false,
23 capture_pageleave: false,
24 disable_session_recording: true,
25 person_profiles: 'always',
26 persistence: 'localStorage',
27 opt_out_capturing_by_default: true,
28
29 sanitize_properties: function (properties) {
30 const denylist = [
31 '$pathname',
32 '$initial_pathname',
33 '$current_url',
34 '$initial_current_url',
35 '$host',
36 '$initial_host',
37 '$initial_person_info',
38 ]
39
40 denylist.forEach((key) => {
41 if (properties[key]) {
42 properties[key] = null // Set each denied property to null
43 }
44 })
45
46 return properties
47 },
48 })
49 // Attempt to restore distinct Id from app global settings
50 serviceHub
51 .analytic()
52 .getAppDistinctId()
53 .then((id) => {
54 if (id) posthog.identify(id)
55 })
56 .finally(() => {
57 posthog.opt_in_capturing()
58 posthog.register({ app_version: VERSION })
59 serviceHub.analytic().updateDistinctId(posthog.get_distinct_id())
60 })
61 } else {
62 posthog.opt_out_capturing()
63 }
64 }, [productAnalytic, serviceHub])

Callers

nothing calls this directly

Calls 9

useAnalyticFunction · 0.90
useServiceHubFunction · 0.90
identifyMethod · 0.80
getAppDistinctIdMethod · 0.65
analyticMethod · 0.65
updateDistinctIdMethod · 0.65
forEachMethod · 0.45
thenMethod · 0.45
registerMethod · 0.45

Tested by

no test coverage detected