@umituz/react-native-firebase 1.13.6 → 1.13.8
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 +3 -4
- package/src/index.ts +2 -10
- package/src/infrastructure/config/FirebaseClient.ts +2 -19
- package/src/infrastructure/config/services/FirebaseServiceInitializer.ts +5 -20
- package/src/analytics/application/ports/IAnalyticsService.ts +0 -92
- package/src/analytics/index.ts +0 -20
- package/src/analytics/infrastructure/adapters/index.ts +0 -10
- package/src/analytics/infrastructure/adapters/native-analytics.adapter.ts +0 -63
- package/src/analytics/infrastructure/adapters/web-analytics.adapter.ts +0 -63
- package/src/analytics/infrastructure/services/FirebaseAnalyticsService.ts +0 -165
- package/src/analytics/infrastructure/services/PerformanceTracker.ts +0 -49
- package/src/analytics/infrastructure/services/analytics-event.service.ts +0 -72
- package/src/analytics/infrastructure/services/analytics-initializer.service.ts +0 -141
- package/src/analytics/infrastructure/services/analytics-user.service.ts +0 -98
- package/src/analytics/infrastructure/services/index.ts +0 -12
- package/src/analytics/presentation/decorators/PerformanceDecorator.ts +0 -73
- package/src/analytics/presentation/decorators/TrackingDecorator.ts +0 -38
- package/src/analytics/presentation/hooks/useNavigationAnalytics.ts +0 -118
- package/src/analytics/presentation/hooks/useNavigationTracking.ts +0 -62
- package/src/analytics/presentation/hooks/useScreenTime.ts +0 -69
- package/src/analytics/presentation/hooks/useScreenView.ts +0 -70
- package/src/analytics/presentation/utils/analyticsUtils.ts +0 -78
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
4
|
-
"description": "Unified Firebase package for React Native apps -
|
|
3
|
+
"version": "1.13.8",
|
|
4
|
+
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
"keywords": [
|
|
15
15
|
"react-native",
|
|
16
16
|
"firebase",
|
|
17
|
-
"firebase-
|
|
17
|
+
"firebase-js-sdk",
|
|
18
18
|
"auth",
|
|
19
19
|
"authentication",
|
|
20
20
|
"firestore",
|
|
21
21
|
"database",
|
|
22
22
|
"repository",
|
|
23
|
-
"analytics",
|
|
24
23
|
"ddd",
|
|
25
24
|
"domain-driven-design"
|
|
26
25
|
],
|
package/src/index.ts
CHANGED
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
* Domain-Driven Design (DDD) Architecture
|
|
5
5
|
*
|
|
6
6
|
* This package provides Firebase App initialization and core services:
|
|
7
|
-
* - Auth
|
|
8
|
-
* - Firestore
|
|
9
|
-
* - Analytics
|
|
7
|
+
* - Auth (Firebase JS SDK)
|
|
8
|
+
* - Firestore (Firebase JS SDK)
|
|
10
9
|
*
|
|
11
10
|
* Usage:
|
|
12
11
|
* import { initializeFirebase, getFirebaseApp } from '@umituz/react-native-firebase';
|
|
13
12
|
* import { useFirebaseAuth } from '@umituz/react-native-firebase';
|
|
14
13
|
* import { getFirestore, BaseRepository } from '@umituz/react-native-firebase';
|
|
15
|
-
* import { firebaseAnalyticsService } from '@umituz/react-native-firebase';
|
|
16
14
|
*/
|
|
17
15
|
|
|
18
16
|
// =============================================================================
|
|
@@ -58,9 +56,3 @@ export * from './auth';
|
|
|
58
56
|
|
|
59
57
|
export * from './firestore';
|
|
60
58
|
|
|
61
|
-
// =============================================================================
|
|
62
|
-
// ANALYTICS MODULE
|
|
63
|
-
// =============================================================================
|
|
64
|
-
|
|
65
|
-
export * from './analytics';
|
|
66
|
-
|
|
@@ -38,8 +38,6 @@ declare const __DEV__: boolean;
|
|
|
38
38
|
export interface ServiceInitializationResult {
|
|
39
39
|
app: FirebaseApp | null;
|
|
40
40
|
auth: unknown;
|
|
41
|
-
analytics: unknown;
|
|
42
|
-
crashlytics: unknown;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
/**
|
|
@@ -111,7 +109,7 @@ export function autoInitializeFirebase(): FirebaseApp | null {
|
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Initialize all Firebase services (App
|
|
112
|
+
* Initialize all Firebase services (App and Auth)
|
|
115
113
|
* This is the main entry point for applications - call this once at app startup
|
|
116
114
|
*
|
|
117
115
|
* IMPORTANT: Auth initialization is handled via callback to avoid require() issues.
|
|
@@ -141,36 +139,21 @@ export async function initializeAllFirebaseServices(
|
|
|
141
139
|
return {
|
|
142
140
|
app: null,
|
|
143
141
|
auth: null,
|
|
144
|
-
analytics: null,
|
|
145
|
-
crashlytics: null,
|
|
146
142
|
};
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
const { auth
|
|
150
|
-
await FirebaseServiceInitializer.initializeServices(options);
|
|
151
|
-
|
|
152
|
-
if (analytics && typeof (analytics as { init?: () => Promise<void> }).init === 'function') {
|
|
153
|
-
await (analytics as { init: () => Promise<void> }).init();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (crashlytics && typeof (crashlytics as { init?: () => Promise<void> }).init === 'function') {
|
|
157
|
-
await (crashlytics as { init: () => Promise<void> }).init();
|
|
158
|
-
}
|
|
145
|
+
const { auth } = await FirebaseServiceInitializer.initializeServices(options);
|
|
159
146
|
|
|
160
147
|
if (__DEV__) {
|
|
161
148
|
console.log('[Firebase] All services initialized:', {
|
|
162
149
|
app: !!app,
|
|
163
150
|
auth: !!auth,
|
|
164
|
-
analytics: !!analytics,
|
|
165
|
-
crashlytics: !!crashlytics,
|
|
166
151
|
});
|
|
167
152
|
}
|
|
168
153
|
|
|
169
154
|
return {
|
|
170
155
|
app,
|
|
171
156
|
auth,
|
|
172
|
-
analytics,
|
|
173
|
-
crashlytics,
|
|
174
157
|
};
|
|
175
158
|
}
|
|
176
159
|
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Firebase Service Initializer
|
|
3
|
-
* Handles initialization of Firebase
|
|
3
|
+
* Handles initialization of Firebase Auth service
|
|
4
4
|
*
|
|
5
5
|
* NOTE: Auth initialization is handled by the main app via callback.
|
|
6
6
|
* This removes the need for dynamic require() which causes issues in production.
|
|
7
7
|
*
|
|
8
|
-
* Single Responsibility: Only initializes Firebase
|
|
8
|
+
* Single Responsibility: Only initializes Firebase Auth service
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { firebaseAnalyticsService } from '../../../analytics';
|
|
12
|
-
import { firebaseCrashlyticsService } from '../../../crashlytics';
|
|
13
|
-
|
|
14
11
|
declare const __DEV__: boolean;
|
|
15
12
|
|
|
16
13
|
export type AuthInitializer = () => unknown;
|
|
@@ -21,8 +18,6 @@ export interface ServiceInitializationOptions {
|
|
|
21
18
|
|
|
22
19
|
export interface ServiceInitializationResult {
|
|
23
20
|
auth: unknown;
|
|
24
|
-
analytics: typeof firebaseAnalyticsService;
|
|
25
|
-
crashlytics: typeof firebaseCrashlyticsService;
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
export class FirebaseServiceInitializer {
|
|
@@ -30,7 +25,7 @@ export class FirebaseServiceInitializer {
|
|
|
30
25
|
options?: ServiceInitializationOptions
|
|
31
26
|
): Promise<ServiceInitializationResult> {
|
|
32
27
|
if (__DEV__) {
|
|
33
|
-
console.log('[Firebase] Initializing
|
|
28
|
+
console.log('[Firebase] Initializing auth service...');
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
let auth: unknown = null;
|
|
@@ -50,20 +45,10 @@ export class FirebaseServiceInitializer {
|
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
const analytics = firebaseAnalyticsService;
|
|
54
|
-
const crashlytics = firebaseCrashlyticsService;
|
|
55
|
-
|
|
56
48
|
if (__DEV__) {
|
|
57
|
-
console.log(
|
|
58
|
-
'[Firebase] Services initialized - Auth:',
|
|
59
|
-
!!auth,
|
|
60
|
-
'Analytics:',
|
|
61
|
-
!!analytics,
|
|
62
|
-
'Crashlytics:',
|
|
63
|
-
!!crashlytics
|
|
64
|
-
);
|
|
49
|
+
console.log('[Firebase] Auth service initialized:', !!auth);
|
|
65
50
|
}
|
|
66
51
|
|
|
67
|
-
return { auth
|
|
52
|
+
return { auth };
|
|
68
53
|
}
|
|
69
54
|
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics Service Interface
|
|
3
|
-
*
|
|
4
|
-
* Application Layer - Port
|
|
5
|
-
* Defines the contract for analytics operations
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface IAnalyticsService {
|
|
9
|
-
/**
|
|
10
|
-
* Initialize the analytics service
|
|
11
|
-
* @param userId Optional user ID to associate with analytics
|
|
12
|
-
*/
|
|
13
|
-
init(userId?: string): Promise<void>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Set the current user ID
|
|
17
|
-
* @param userId The unique user identifier
|
|
18
|
-
*/
|
|
19
|
-
setUserId(userId: string): Promise<void>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Log a custom event
|
|
23
|
-
* @param eventName Name of the event
|
|
24
|
-
* @param params Optional key-value pairs of parameters
|
|
25
|
-
*/
|
|
26
|
-
logEvent(
|
|
27
|
-
eventName: string,
|
|
28
|
-
params?: Record<string, string | number | boolean | null>,
|
|
29
|
-
): Promise<void>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Set a user property
|
|
33
|
-
* @param key Property key
|
|
34
|
-
* @param value Property value
|
|
35
|
-
*/
|
|
36
|
-
setUserProperty(key: string, value: string): Promise<void>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Set multiple user properties at once
|
|
40
|
-
* @param properties Key-value pairs of user properties
|
|
41
|
-
*/
|
|
42
|
-
setUserProperties(properties: Record<string, string>): Promise<void>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Clear all user data and reset initialization state
|
|
46
|
-
*/
|
|
47
|
-
clearUserData(): Promise<void>;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Get the current user ID if set
|
|
51
|
-
*/
|
|
52
|
-
getCurrentUserId(): string | null;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Log a screen view event
|
|
56
|
-
*/
|
|
57
|
-
logScreenView(params: { screen_name: string; screen_class?: string }): Promise<void>;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Log time spent on a screen
|
|
61
|
-
*/
|
|
62
|
-
logScreenTime(params: {
|
|
63
|
-
screen_name: string;
|
|
64
|
-
screen_class?: string;
|
|
65
|
-
time_spent_seconds: number;
|
|
66
|
-
}): Promise<void>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Log a navigation event between screens
|
|
70
|
-
*/
|
|
71
|
-
logNavigation(params: {
|
|
72
|
-
from_screen: string;
|
|
73
|
-
to_screen: string;
|
|
74
|
-
screen_class?: string;
|
|
75
|
-
}): Promise<void>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Log a button click event
|
|
79
|
-
*/
|
|
80
|
-
logButtonClick(params: {
|
|
81
|
-
button_id: string;
|
|
82
|
-
button_name?: string;
|
|
83
|
-
screen_name: string;
|
|
84
|
-
screen_class?: string;
|
|
85
|
-
}): Promise<void>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Enable or disable analytics collection
|
|
89
|
-
* @param enabled Whether collection should be enabled
|
|
90
|
-
*/
|
|
91
|
-
setAnalyticsCollectionEnabled(enabled: boolean): Promise<void>;
|
|
92
|
-
}
|
package/src/analytics/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Analytics Module
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { firebaseAnalyticsService } from './infrastructure/services/FirebaseAnalyticsService';
|
|
6
|
-
export type { IAnalyticsService } from './infrastructure/services/FirebaseAnalyticsService';
|
|
7
|
-
export { analyticsInitializerService } from './infrastructure/services/analytics-initializer.service';
|
|
8
|
-
export type { AnalyticsInstance } from './infrastructure/services/analytics-initializer.service';
|
|
9
|
-
export { analyticsEventService } from './infrastructure/services/analytics-event.service';
|
|
10
|
-
export { analyticsUserService } from './infrastructure/services/analytics-user.service';
|
|
11
|
-
export { performanceTracker } from './infrastructure/services/PerformanceTracker';
|
|
12
|
-
|
|
13
|
-
// Hooks
|
|
14
|
-
export { useScreenView } from './presentation/hooks/useScreenView';
|
|
15
|
-
export { useScreenTime } from './presentation/hooks/useScreenTime';
|
|
16
|
-
export { useNavigationTracking } from './presentation/hooks/useNavigationTracking';
|
|
17
|
-
export { useNavigationAnalytics } from './presentation/hooks/useNavigationAnalytics';
|
|
18
|
-
|
|
19
|
-
// Utility Functions
|
|
20
|
-
export { trackButtonClick, trackCRUDOperation } from './presentation/utils/analyticsUtils';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics Adapters
|
|
3
|
-
* Platform-specific implementations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { webAnalyticsAdapter } from './web-analytics.adapter';
|
|
7
|
-
export type { WebAnalyticsAdapter } from './web-analytics.adapter';
|
|
8
|
-
export { nativeAnalyticsAdapter } from './native-analytics.adapter';
|
|
9
|
-
export type { NativeAnalyticsAdapter } from './native-analytics.adapter';
|
|
10
|
-
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native Analytics Adapter
|
|
3
|
-
* Single Responsibility: Handle Firebase Analytics native implementation
|
|
4
|
-
* Uses React Native Firebase v23+ modular API
|
|
5
|
-
*
|
|
6
|
-
* NOTE: This adapter uses optional import to support Expo Go.
|
|
7
|
-
* Native modules are only available in development builds or standalone apps.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Optional import - will be null in Expo Go
|
|
11
|
-
let nativeAnalytics: any = null;
|
|
12
|
-
try {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
-
nativeAnalytics = require('@react-native-firebase/analytics');
|
|
15
|
-
} catch {
|
|
16
|
-
// Native module not available (e.g., Expo Go)
|
|
17
|
-
// eslint-disable-next-line no-console
|
|
18
|
-
if (__DEV__) console.warn('⚠️ Firebase Analytics: Native module not available');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface NativeAnalyticsAdapter {
|
|
22
|
-
getAnalytics(): any;
|
|
23
|
-
logEvent(analytics: any, eventName: string, params?: Record<string, any>): Promise<void>;
|
|
24
|
-
setUserId(analytics: any, userId: string): Promise<void>;
|
|
25
|
-
setUserProperties(analytics: any, properties: Record<string, string>): Promise<void>;
|
|
26
|
-
resetAnalyticsData(analytics: any): Promise<void>;
|
|
27
|
-
setAnalyticsCollectionEnabled(analytics: any, enabled: boolean): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare const __DEV__: boolean;
|
|
31
|
-
|
|
32
|
-
export const nativeAnalyticsAdapter: NativeAnalyticsAdapter | null = nativeAnalytics
|
|
33
|
-
? {
|
|
34
|
-
getAnalytics(): any {
|
|
35
|
-
return nativeAnalytics.getAnalytics();
|
|
36
|
-
},
|
|
37
|
-
async logEvent(
|
|
38
|
-
analytics: any,
|
|
39
|
-
eventName: string,
|
|
40
|
-
params?: Record<string, any>,
|
|
41
|
-
): Promise<void> {
|
|
42
|
-
await nativeAnalytics.logEvent(analytics, eventName, params);
|
|
43
|
-
},
|
|
44
|
-
async setUserId(analytics: any, userId: string): Promise<void> {
|
|
45
|
-
await nativeAnalytics.setUserId(analytics, userId);
|
|
46
|
-
},
|
|
47
|
-
async setUserProperties(
|
|
48
|
-
analytics: any,
|
|
49
|
-
properties: Record<string, string>,
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
await nativeAnalytics.setUserProperties(analytics, properties);
|
|
52
|
-
},
|
|
53
|
-
async resetAnalyticsData(analytics: any): Promise<void> {
|
|
54
|
-
await nativeAnalytics.resetAnalyticsData(analytics);
|
|
55
|
-
},
|
|
56
|
-
async setAnalyticsCollectionEnabled(
|
|
57
|
-
analytics: any,
|
|
58
|
-
enabled: boolean,
|
|
59
|
-
): Promise<void> {
|
|
60
|
-
await nativeAnalytics.setAnalyticsCollectionEnabled(analytics, enabled);
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
: null;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web Analytics Adapter
|
|
3
|
-
* Single Responsibility: Handle Firebase Analytics web implementation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface WebAnalyticsAdapter {
|
|
7
|
-
isSupported(): Promise<boolean>;
|
|
8
|
-
getAnalytics(app: any): any;
|
|
9
|
-
logEvent(analytics: any, eventName: string, params?: Record<string, any>): Promise<void>;
|
|
10
|
-
setUserId(analytics: any, userId: string): Promise<void>;
|
|
11
|
-
setUserProperties(analytics: any, properties: Record<string, string>): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let webAnalyticsModule: any = null;
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
18
|
-
const {
|
|
19
|
-
getAnalytics,
|
|
20
|
-
logEvent,
|
|
21
|
-
setUserId,
|
|
22
|
-
setUserProperties,
|
|
23
|
-
isSupported,
|
|
24
|
-
} = require('firebase/analytics');
|
|
25
|
-
webAnalyticsModule = {
|
|
26
|
-
getAnalytics,
|
|
27
|
-
logEvent,
|
|
28
|
-
setUserId,
|
|
29
|
-
setUserProperties,
|
|
30
|
-
isSupported,
|
|
31
|
-
};
|
|
32
|
-
} catch {
|
|
33
|
-
// firebase/analytics not available
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const webAnalyticsAdapter: WebAnalyticsAdapter | null = webAnalyticsModule
|
|
37
|
-
? {
|
|
38
|
-
async isSupported(): Promise<boolean> {
|
|
39
|
-
if (!webAnalyticsModule.isSupported) return true;
|
|
40
|
-
return webAnalyticsModule.isSupported();
|
|
41
|
-
},
|
|
42
|
-
getAnalytics(app: any): any {
|
|
43
|
-
return webAnalyticsModule.getAnalytics(app);
|
|
44
|
-
},
|
|
45
|
-
async logEvent(
|
|
46
|
-
analytics: any,
|
|
47
|
-
eventName: string,
|
|
48
|
-
params?: Record<string, any>,
|
|
49
|
-
): Promise<void> {
|
|
50
|
-
await webAnalyticsModule.logEvent(analytics, eventName, params);
|
|
51
|
-
},
|
|
52
|
-
async setUserId(analytics: any, userId: string): Promise<void> {
|
|
53
|
-
await webAnalyticsModule.setUserId(analytics, userId);
|
|
54
|
-
},
|
|
55
|
-
async setUserProperties(
|
|
56
|
-
analytics: any,
|
|
57
|
-
properties: Record<string, string>,
|
|
58
|
-
): Promise<void> {
|
|
59
|
-
await webAnalyticsModule.setUserProperties(analytics, properties);
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
: null;
|
|
63
|
-
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Analytics Service
|
|
3
|
-
* Single Responsibility: Orchestrate analytics operations
|
|
4
|
-
* Delegates to specialized services for initialization, events, and user management
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { analyticsInitializerService } from './analytics-initializer.service';
|
|
8
|
-
import { analyticsEventService } from './analytics-event.service';
|
|
9
|
-
import { analyticsUserService } from './analytics-user.service';
|
|
10
|
-
import type { AnalyticsInstance } from './analytics-initializer.service';
|
|
11
|
-
import type { IAnalyticsService } from '../../application/ports/IAnalyticsService';
|
|
12
|
-
import { nativeAnalyticsAdapter } from '../adapters/native-analytics.adapter';
|
|
13
|
-
|
|
14
|
-
export type { IAnalyticsService };
|
|
15
|
-
|
|
16
|
-
class FirebaseAnalyticsService implements IAnalyticsService {
|
|
17
|
-
private isInitialized = false;
|
|
18
|
-
private userId: string | null = null;
|
|
19
|
-
private userProperties: Record<string, string> = {};
|
|
20
|
-
private analyticsInstance: AnalyticsInstance | null = null;
|
|
21
|
-
|
|
22
|
-
async init(userId?: string): Promise<void> {
|
|
23
|
-
if (this.isInitialized) {
|
|
24
|
-
if (userId && userId !== this.userId) {
|
|
25
|
-
await this.setUserId(userId);
|
|
26
|
-
}
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
this.analyticsInstance = await analyticsInitializerService.initialize();
|
|
32
|
-
|
|
33
|
-
if (this.analyticsInstance) {
|
|
34
|
-
if (userId) {
|
|
35
|
-
this.userId = userId;
|
|
36
|
-
await analyticsUserService.setUserId(this.analyticsInstance, userId);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Explicitly enable analytics collection to ensure it's active
|
|
40
|
-
await this.setAnalyticsCollectionEnabled(true);
|
|
41
|
-
}
|
|
42
|
-
} catch (_error) {
|
|
43
|
-
// Analytics is non-critical, fail silently
|
|
44
|
-
} finally {
|
|
45
|
-
this.isInitialized = true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async setAnalyticsCollectionEnabled(enabled: boolean): Promise<void> {
|
|
50
|
-
if (!this.analyticsInstance) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
if (this.analyticsInstance.platform === 'native' && nativeAnalyticsAdapter) {
|
|
56
|
-
await nativeAnalyticsAdapter.setAnalyticsCollectionEnabled(
|
|
57
|
-
this.analyticsInstance.instance,
|
|
58
|
-
enabled,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
} catch (_error) {
|
|
62
|
-
// Fail silently
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async setUserId(userId: string): Promise<void> {
|
|
67
|
-
if (!this.isInitialized || !this.analyticsInstance) {
|
|
68
|
-
// Not initialized yet, will be set during init
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (this.userId === userId) {
|
|
73
|
-
// Already set to this user ID
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
this.userId = userId;
|
|
79
|
-
await analyticsUserService.setUserId(this.analyticsInstance, userId);
|
|
80
|
-
} catch (_error) {
|
|
81
|
-
// Analytics is non-critical, fail silently
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async logEvent(
|
|
86
|
-
eventName: string,
|
|
87
|
-
params?: Record<string, string | number | boolean | null>,
|
|
88
|
-
): Promise<void> {
|
|
89
|
-
if (!this.isInitialized) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
await analyticsEventService.logEvent(this.analyticsInstance, eventName, params);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async setUserProperty(key: string, value: string): Promise<void> {
|
|
96
|
-
this.userProperties[key] = value;
|
|
97
|
-
await analyticsUserService.setUserProperty(this.analyticsInstance, key, value);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async setUserProperties(properties: Record<string, string>): Promise<void> {
|
|
101
|
-
await analyticsUserService.setUserProperties(this.analyticsInstance, properties);
|
|
102
|
-
Object.assign(this.userProperties, properties);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async clearUserData(): Promise<void> {
|
|
106
|
-
await analyticsUserService.clearUserData(this.analyticsInstance);
|
|
107
|
-
this.userId = null;
|
|
108
|
-
this.userProperties = {};
|
|
109
|
-
this.isInitialized = false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getCurrentUserId(): string | null {
|
|
113
|
-
return this.userId;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async logScreenView(params: {
|
|
117
|
-
screen_name: string;
|
|
118
|
-
screen_class?: string;
|
|
119
|
-
}): Promise<void> {
|
|
120
|
-
await this.logEvent('screen_view', {
|
|
121
|
-
screen_name: params.screen_name,
|
|
122
|
-
screen_class: params.screen_class || params.screen_name,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async logScreenTime(params: {
|
|
127
|
-
screen_name: string;
|
|
128
|
-
screen_class?: string;
|
|
129
|
-
time_spent_seconds: number;
|
|
130
|
-
}): Promise<void> {
|
|
131
|
-
await this.logEvent('screen_time', {
|
|
132
|
-
screen_name: params.screen_name,
|
|
133
|
-
screen_class: params.screen_class || params.screen_name,
|
|
134
|
-
time_spent_seconds: params.time_spent_seconds,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async logNavigation(params: {
|
|
139
|
-
from_screen: string;
|
|
140
|
-
to_screen: string;
|
|
141
|
-
screen_class?: string;
|
|
142
|
-
}): Promise<void> {
|
|
143
|
-
await this.logEvent('navigation', {
|
|
144
|
-
from_screen: params.from_screen,
|
|
145
|
-
to_screen: params.to_screen,
|
|
146
|
-
screen_class: params.screen_class || params.to_screen,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async logButtonClick(params: {
|
|
151
|
-
button_id: string;
|
|
152
|
-
button_name?: string;
|
|
153
|
-
screen_name: string;
|
|
154
|
-
screen_class?: string;
|
|
155
|
-
}): Promise<void> {
|
|
156
|
-
await this.logEvent('button_click', {
|
|
157
|
-
button_id: params.button_id,
|
|
158
|
-
button_name: params.button_name || params.button_id,
|
|
159
|
-
screen_name: params.screen_name,
|
|
160
|
-
screen_class: params.screen_class || params.screen_name,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export const firebaseAnalyticsService = new FirebaseAnalyticsService();
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Performance Tracker Service
|
|
3
|
-
*
|
|
4
|
-
* Single Responsibility: Track performance metrics of operations
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export class PerformanceTracker {
|
|
8
|
-
private activeTracks = new Map<string, number>();
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Start tracking an operation
|
|
12
|
-
*/
|
|
13
|
-
start(trackingId: string): void {
|
|
14
|
-
this.activeTracks.set(trackingId, Date.now());
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* End tracking and return duration
|
|
19
|
-
*/
|
|
20
|
-
async end(trackingId: string, params: Record<string, any> = {}): Promise<number> {
|
|
21
|
-
const startTime = this.activeTracks.get(trackingId);
|
|
22
|
-
if (!startTime) return 0;
|
|
23
|
-
|
|
24
|
-
const duration = Date.now() - startTime;
|
|
25
|
-
this.activeTracks.delete(trackingId);
|
|
26
|
-
|
|
27
|
-
// In a full implementation, this could send to Firebase Performance
|
|
28
|
-
// For now, we just log it or handle it as a custom metric
|
|
29
|
-
if (__DEV__) {
|
|
30
|
-
console.log(`⏱️ [Performance] ${trackingId}: ${duration}ms`, params);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return duration;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Track a function execution
|
|
38
|
-
*/
|
|
39
|
-
async track<T>(trackingId: string, fn: () => Promise<T>): Promise<T> {
|
|
40
|
-
this.start(trackingId);
|
|
41
|
-
try {
|
|
42
|
-
return await fn();
|
|
43
|
-
} finally {
|
|
44
|
-
await this.end(trackingId);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const performanceTracker = new PerformanceTracker();
|