1+ import { getAnalyticsService } from './useAnalyticsConsentInit' ;
2+
3+ export function useAnalytics ( ) {
4+ const analytics = getAnalyticsService ( ) ;
5+
6+ const trackPageView = ( pageName : string , properties ?: Record < string , unknown > ) => {
7+ analytics . track ( 'Page View' , {
8+ page_name : pageName ,
9+ timestamp : new Date ( ) . toISOString ( ) ,
10+ session_duration : performance . now ( ) ,
11+ ...properties
12+ } ) ;
13+ } ;
14+
15+ const trackFeatureUsage = ( featureName : string , action : string , properties ?: Record < string , unknown > ) => {
16+ analytics . track ( 'Feature Used' , {
17+ feature_name : featureName ,
18+ action,
19+ timestamp : new Date ( ) . toISOString ( ) ,
20+ ...properties
21+ } ) ;
22+ } ;
23+
24+ const trackMonitoringAction = ( action : string , properties ?: Record < string , unknown > ) => {
25+ analytics . track ( 'Monitoring Action' , {
26+ action,
27+ timestamp : new Date ( ) . toISOString ( ) ,
28+ ...properties
29+ } ) ;
30+ } ;
31+
32+ const trackConfigurationChange = ( changeType : string , properties ?: Record < string , unknown > ) => {
33+ analytics . track ( 'Configuration Changed' , {
34+ change_type : changeType ,
35+ timestamp : new Date ( ) . toISOString ( ) ,
36+ ...properties
37+ } ) ;
38+ } ;
39+
40+ const trackDashboardInteraction = ( interactionType : string , properties ?: Record < string , unknown > ) => {
41+ analytics . track ( 'Dashboard Interaction' , {
42+ interaction_type : interactionType ,
43+ timestamp : new Date ( ) . toISOString ( ) ,
44+ ...properties
45+ } ) ;
46+ } ;
47+
48+ // Manufacturing-specific tracking methods
49+ const trackEndpointManagement = ( action : string , endpointData ?: Record < string , unknown > ) => {
50+ analytics . track ( 'Endpoint Management' , {
51+ action, // 'create', 'update', 'delete', 'test'
52+ endpoint_type : endpointData ?. type ,
53+ probe_interval : endpointData ?. interval ,
54+ timeout_seconds : endpointData ?. timeout ,
55+ has_authentication : ! ! endpointData ?. authentication ,
56+ timestamp : new Date ( ) . toISOString ( ) ,
57+ ...endpointData
58+ } ) ;
59+ } ;
60+
61+ const trackAlertInteraction = ( action : string , alertData ?: Record < string , unknown > ) => {
62+ analytics . track ( 'Alert Interaction' , {
63+ action, // 'acknowledge', 'resolve', 'escalate', 'view_details'
64+ alert_severity : alertData ?. severity ,
65+ alert_type : alertData ?. type ,
66+ response_time_seconds : alertData ?. responseTime ,
67+ resolution_method : alertData ?. resolutionMethod ,
68+ timestamp : new Date ( ) . toISOString ( )
69+ } ) ;
70+ } ;
71+
72+ const trackSystemMetrics = ( metrics : Record < string , unknown > ) => {
73+ analytics . track ( 'System Metrics' , {
74+ total_endpoints : metrics . totalEndpoints ,
75+ active_alerts : metrics . activeAlerts ,
76+ overall_availability : metrics . overallAvailability ,
77+ monitored_services : metrics . monitoredServices ,
78+ data_retention_days : metrics . dataRetentionDays ,
79+ uptime_percentage : metrics . uptimePercentage ,
80+ timestamp : new Date ( ) . toISOString ( )
81+ } ) ;
82+ } ;
83+
84+ const trackPerformanceMetrics = ( pageName : string , metrics ?: Record < string , unknown > ) => {
85+ analytics . track ( 'Performance Metrics' , {
86+ page_name : pageName ,
87+ load_time_ms : metrics ?. loadTime ,
88+ data_fetch_time_ms : metrics ?. dataFetchTime ,
89+ render_time_ms : metrics ?. renderTime ,
90+ memory_usage_mb : 'memory' in performance ? Math . round ( ( performance as any ) . memory . usedJSHeapSize / 1024 / 1024 ) : undefined ,
91+ timestamp : new Date ( ) . toISOString ( )
92+ } ) ;
93+ } ;
94+
95+ const trackManufacturingKPIs = ( kpiData : Record < string , unknown > ) => {
96+ analytics . track ( 'Manufacturing KPIs' , {
97+ monitoring_coverage_percentage : kpiData . monitoringCoverage ,
98+ mean_time_to_detection_seconds : kpiData . mttd ,
99+ mean_time_to_recovery_seconds : kpiData . mttr ,
100+ false_positive_rate : kpiData . falsePositiveRate ,
101+ network_segments_monitored : kpiData . networkSegments ,
102+ critical_endpoints_count : kpiData . criticalEndpoints ,
103+ timestamp : new Date ( ) . toISOString ( )
104+ } ) ;
105+ } ;
106+
107+ const trackConfigurationComplexity = ( configData : Record < string , unknown > ) => {
108+ analytics . track ( 'Configuration Complexity' , {
109+ total_rules : configData . totalRules ,
110+ unique_probe_types : configData . uniqueProbeTypes ,
111+ custom_intervals_count : configData . customIntervals ,
112+ advanced_features_used : configData . advancedFeatures ,
113+ configuration_size_kb : configData . configSizeKb ,
114+ validation_errors : configData . validationErrors ,
115+ timestamp : new Date ( ) . toISOString ( )
116+ } ) ;
117+ } ;
118+
119+ const trackUserEfficiency = ( efficiencyData : Record < string , unknown > ) => {
120+ analytics . track ( 'User Efficiency' , {
121+ tasks_completed_per_session : efficiencyData . tasksCompleted ,
122+ average_task_duration_seconds : efficiencyData . avgTaskDuration ,
123+ navigation_depth : efficiencyData . navigationDepth ,
124+ help_usage_count : efficiencyData . helpUsage ,
125+ keyboard_shortcuts_used : efficiencyData . keyboardShortcuts ,
126+ timestamp : new Date ( ) . toISOString ( )
127+ } ) ;
128+ } ;
129+
130+ return {
131+ track : analytics . track . bind ( analytics ) ,
132+ trackPageView,
133+ trackFeatureUsage,
134+ trackMonitoringAction,
135+ trackConfigurationChange,
136+ trackDashboardInteraction,
137+ // Manufacturing-specific methods
138+ trackEndpointManagement,
139+ trackAlertInteraction,
140+ trackSystemMetrics,
141+ trackPerformanceMetrics,
142+ trackManufacturingKPIs,
143+ trackConfigurationComplexity,
144+ trackUserEfficiency,
145+ isInitialized : analytics . isInitialized ( )
146+ } ;
147+ }
0 commit comments