@umituz/react-native-firebase 1.7.5 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Centralized initialization and core services (Analytics, Crashlytics).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/analytics/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { performanceTracker } from './infrastructure/services/PerformanceTracker
|
|
|
14
14
|
export { useScreenView } from './presentation/hooks/useScreenView';
|
|
15
15
|
export { useScreenTime } from './presentation/hooks/useScreenTime';
|
|
16
16
|
export { useNavigationTracking } from './presentation/hooks/useNavigationTracking';
|
|
17
|
+
export { useNavigationAnalytics } from './presentation/hooks/useNavigationAnalytics';
|
|
17
18
|
|
|
18
19
|
// Utility Functions
|
|
19
20
|
export { trackButtonClick, trackCRUDOperation } from './presentation/utils/analyticsUtils';
|
|
@@ -38,22 +38,6 @@ class FirebaseAnalyticsService implements IAnalyticsService {
|
|
|
38
38
|
|
|
39
39
|
// Explicitly enable analytics collection to ensure it's active
|
|
40
40
|
await this.setAnalyticsCollectionEnabled(true);
|
|
41
|
-
|
|
42
|
-
/* eslint-disable-next-line no-console */
|
|
43
|
-
if (__DEV__) {
|
|
44
|
-
console.log('✅ Firebase Analytics initialized successfully', {
|
|
45
|
-
platform: this.analyticsInstance.platform,
|
|
46
|
-
userId: userId || 'guest',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
/* eslint-disable-next-line no-console */
|
|
51
|
-
if (__DEV__) {
|
|
52
|
-
console.warn('⚠️ Firebase Analytics: Initialization returned null instance', {
|
|
53
|
-
reason: 'Native module not available or web analytics not supported',
|
|
54
|
-
note: 'Events will be logged to console but not sent to Firebase',
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
41
|
}
|
|
58
42
|
} catch (_error) {
|
|
59
43
|
// Analytics is non-critical, fail silently
|
|
@@ -103,12 +87,6 @@ class FirebaseAnalyticsService implements IAnalyticsService {
|
|
|
103
87
|
params?: Record<string, string | number | boolean | null>,
|
|
104
88
|
): Promise<void> {
|
|
105
89
|
if (!this.isInitialized) {
|
|
106
|
-
/* eslint-disable-next-line no-console */
|
|
107
|
-
if (__DEV__) {
|
|
108
|
-
console.warn('⚠️ Firebase Analytics: Cannot log event - Service not initialized', {
|
|
109
|
-
eventName,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
90
|
return;
|
|
113
91
|
}
|
|
114
92
|
await analyticsEventService.logEvent(this.analyticsInstance, eventName, params);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useNavigationAnalytics Hook
|
|
3
|
+
*
|
|
4
|
+
* Tracks navigation analytics at app level for NavigationContainer
|
|
5
|
+
* Migrated to Firebase modular SDK (v22+)
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Screen view tracking
|
|
9
|
+
* - Screen time measurement
|
|
10
|
+
* - Navigation flow analytics
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { useNavigationAnalytics } from '@umituz/react-native-firebase';
|
|
15
|
+
*
|
|
16
|
+
* function App() {
|
|
17
|
+
* const { handleNavigationReady, handleNavigationStateChange } = useNavigationAnalytics();
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <NavigationContainer
|
|
21
|
+
* onReady={() => handleNavigationReady(navigationRef)}
|
|
22
|
+
* onStateChange={() => handleNavigationStateChange(navigationRef)}
|
|
23
|
+
* >
|
|
24
|
+
* <AppNavigator />
|
|
25
|
+
* </NavigationContainer>
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { useRef } from "react";
|
|
32
|
+
import { firebaseAnalyticsService } from "../../infrastructure/services/FirebaseAnalyticsService";
|
|
33
|
+
|
|
34
|
+
export const useNavigationAnalytics = () => {
|
|
35
|
+
const routeNameRef = useRef<string | undefined>(undefined);
|
|
36
|
+
const screenStartTimeRef = useRef<number | undefined>(undefined);
|
|
37
|
+
|
|
38
|
+
const getActiveRouteName = (state: any): string | undefined => {
|
|
39
|
+
if (!state || !state.routes) return undefined;
|
|
40
|
+
const route = state.routes[state.index];
|
|
41
|
+
if (route.state) {
|
|
42
|
+
return getActiveRouteName(route.state);
|
|
43
|
+
}
|
|
44
|
+
return route.name;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleNavigationReady = (navigationRef: any) => {
|
|
48
|
+
const currentRouteName = getActiveRouteName(
|
|
49
|
+
navigationRef.current?.getRootState(),
|
|
50
|
+
);
|
|
51
|
+
routeNameRef.current = currentRouteName;
|
|
52
|
+
screenStartTimeRef.current = Date.now();
|
|
53
|
+
|
|
54
|
+
if (currentRouteName) {
|
|
55
|
+
firebaseAnalyticsService
|
|
56
|
+
.logScreenView({
|
|
57
|
+
screen_name: currentRouteName,
|
|
58
|
+
screen_class: currentRouteName,
|
|
59
|
+
})
|
|
60
|
+
.catch(() => {
|
|
61
|
+
// Silent fail - analytics is non-critical
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const handleNavigationStateChange = async (navigationRef: any) => {
|
|
67
|
+
const previousRouteName = routeNameRef.current;
|
|
68
|
+
const currentRouteName = getActiveRouteName(
|
|
69
|
+
navigationRef.current?.getRootState(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (previousRouteName !== currentRouteName && currentRouteName) {
|
|
73
|
+
if (previousRouteName && screenStartTimeRef.current) {
|
|
74
|
+
const timeSpent = Math.round(
|
|
75
|
+
(Date.now() - screenStartTimeRef.current) / 1000,
|
|
76
|
+
);
|
|
77
|
+
await firebaseAnalyticsService
|
|
78
|
+
.logScreenTime({
|
|
79
|
+
screen_name: previousRouteName,
|
|
80
|
+
screen_class: previousRouteName,
|
|
81
|
+
time_spent_seconds: timeSpent,
|
|
82
|
+
})
|
|
83
|
+
.catch(() => {
|
|
84
|
+
// Silent fail - analytics is non-critical
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await firebaseAnalyticsService
|
|
89
|
+
.logScreenView({
|
|
90
|
+
screen_name: currentRouteName,
|
|
91
|
+
screen_class: currentRouteName,
|
|
92
|
+
})
|
|
93
|
+
.catch(() => {
|
|
94
|
+
// Silent fail - analytics is non-critical
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (previousRouteName) {
|
|
98
|
+
await firebaseAnalyticsService
|
|
99
|
+
.logNavigation({
|
|
100
|
+
from_screen: previousRouteName,
|
|
101
|
+
to_screen: currentRouteName,
|
|
102
|
+
screen_class: currentRouteName,
|
|
103
|
+
})
|
|
104
|
+
.catch(() => {
|
|
105
|
+
// Silent fail - analytics is non-critical
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
routeNameRef.current = currentRouteName;
|
|
110
|
+
screenStartTimeRef.current = Date.now();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
handleNavigationReady,
|
|
116
|
+
handleNavigationStateChange,
|
|
117
|
+
};
|
|
118
|
+
};
|
|
@@ -44,14 +44,6 @@ export function useNavigationTracking(
|
|
|
44
44
|
|
|
45
45
|
// Log navigation if coming from another screen
|
|
46
46
|
if (previousScreenRef.current && previousScreenRef.current !== screenName) {
|
|
47
|
-
/* eslint-disable-next-line no-console */
|
|
48
|
-
if (__DEV__) {
|
|
49
|
-
console.log("📊 Navigation tracked:", {
|
|
50
|
-
from: previousScreenRef.current,
|
|
51
|
-
to: screenName,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
47
|
firebaseAnalyticsService
|
|
56
48
|
.logNavigation({
|
|
57
49
|
from_screen: previousScreenRef.current,
|