@@ -33,7 +33,9 @@ import { ServerInstallModal } from '@/components/ServerInstallModal';
3333import { SpaceSwitcher } from '@/components/SpaceSwitcher' ;
3434import { ConnectIDEs } from '@/components/ConnectIDEs' ;
3535import { useDataSync } from '@/hooks/useDataSync' ;
36- import { useAppStore , useActiveSpace , useViewSpace , useTheme } from '@/stores' ;
36+ import { useAnalytics } from '@/hooks/useAnalytics' ;
37+ import { initAnalytics , capture , optIn , optOut } from '@/lib/analytics' ;
38+ import { useAppStore , useActiveSpace , useViewSpace , useTheme , useAnalyticsEnabled } from '@/stores' ;
3739import { RegistryPage } from '@/features/registry' ;
3840import { FeatureSetsPage } from '@/features/featuresets' ;
3941import { ClientsPage } from '@/features/clients' ;
@@ -111,6 +113,7 @@ function AppContent() {
111113 const setTheme = useAppStore ( ( state ) => state . setTheme ) ;
112114 const activeSpace = useActiveSpace ( ) ;
113115 const viewSpace = useViewSpace ( ) ;
116+ const analyticsEnabled = useAnalyticsEnabled ( ) ;
114117
115118 // App version from Rust backend
116119 const [ appVersion , setAppVersion ] = useState ( '' ) ;
@@ -120,6 +123,36 @@ function AppContent() {
120123 . catch ( ( err ) => console . error ( 'Failed to get version:' , err ) ) ;
121124 } , [ ] ) ;
122125
126+ // Initialize analytics once we have the app version
127+ useEffect ( ( ) => {
128+ if ( ! appVersion ) return ;
129+ initAnalytics ( appVersion ) ;
130+ if ( analyticsEnabled ) {
131+ optIn ( ) ;
132+ capture ( 'app_opened' ) ;
133+ } else {
134+ optOut ( ) ;
135+ }
136+ } , [ appVersion ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
137+
138+ // Sync opt-in/out when user toggles analytics
139+ useEffect ( ( ) => {
140+ if ( ! appVersion ) return ;
141+ if ( analyticsEnabled ) {
142+ optIn ( ) ;
143+ } else {
144+ optOut ( ) ;
145+ }
146+ } , [ analyticsEnabled , appVersion ] ) ;
147+
148+ // Track domain events (server install/uninstall)
149+ useAnalytics ( ) ;
150+
151+ // Track page navigation
152+ useEffect ( ( ) => {
153+ capture ( 'page_viewed' , { page : activeNav } ) ;
154+ } , [ activeNav ] ) ;
155+
123156 // Gateway status for sidebar footer
124157 const [ gatewayUrl , setGatewayUrl ] = useState < string | null > ( null ) ;
125158 const loadGatewayUrl = useCallback ( async ( ) => {
0 commit comments