apps-sdk 2.0.9 → 2.1.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 +6 -2
- package/src/libraries/Firebase.js +48 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "2.0
|
|
4
|
-
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - Firebase optional",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "ASD",
|
|
7
7
|
"license": "ISC",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"react-native-btr": "^2.2.1",
|
|
37
37
|
"semver": "^7.6.0"
|
|
38
38
|
},
|
|
39
|
+
"optionalDependencies": {
|
|
40
|
+
"@react-native-firebase/analytics": "^21.10.0",
|
|
41
|
+
"@react-native-firebase/app": "^21.10.0"
|
|
42
|
+
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"expo": "~54.0.0",
|
|
41
45
|
"expo-asset": "~12.0.0",
|
|
@@ -1,51 +1,87 @@
|
|
|
1
|
-
import analytics from '@react-native-firebase/analytics';
|
|
2
1
|
import config from '../../config';
|
|
3
2
|
|
|
3
|
+
// Lazy load Firebase (optional dependency)
|
|
4
|
+
let analyticsModule = null;
|
|
5
|
+
let isAvailable = null;
|
|
6
|
+
|
|
7
|
+
function getAnalytics() {
|
|
8
|
+
if (isAvailable === false) return null;
|
|
9
|
+
|
|
10
|
+
if (analyticsModule === null && isAvailable === null) {
|
|
11
|
+
try {
|
|
12
|
+
analyticsModule = require('@react-native-firebase/analytics').default;
|
|
13
|
+
isAvailable = true;
|
|
14
|
+
} catch {
|
|
15
|
+
isAvailable = false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return analyticsModule;
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
class Firebase {
|
|
23
|
+
isAvailable() {
|
|
24
|
+
return getAnalytics() !== null;
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
async initialize() {
|
|
28
|
+
const analytics = getAnalytics();
|
|
29
|
+
if (!analytics) return;
|
|
30
|
+
|
|
6
31
|
try {
|
|
7
|
-
|
|
8
|
-
config.DEBUG_MODE && console.log('Firebase Analytics is ready to use');
|
|
32
|
+
config.DEBUG_MODE && console.log('[SDK] Firebase Analytics initialized');
|
|
9
33
|
} catch (error) {
|
|
10
|
-
console.error('Error initializing Firebase:', error);
|
|
34
|
+
console.error('[SDK] Error initializing Firebase:', error);
|
|
11
35
|
}
|
|
12
36
|
}
|
|
13
37
|
|
|
14
38
|
async getAppInstanceId() {
|
|
39
|
+
const analytics = getAnalytics();
|
|
40
|
+
if (!analytics) return null;
|
|
41
|
+
|
|
15
42
|
try {
|
|
16
43
|
const appInstanceId = await analytics().getAppInstanceId();
|
|
17
|
-
config.DEBUG_MODE && console.log('Firebase App Instance ID:', appInstanceId);
|
|
44
|
+
config.DEBUG_MODE && console.log('[SDK] Firebase App Instance ID:', appInstanceId);
|
|
18
45
|
return appInstanceId;
|
|
19
46
|
} catch (error) {
|
|
20
|
-
console.error('Error getting Firebase App Instance ID:', error);
|
|
47
|
+
console.error('[SDK] Error getting Firebase App Instance ID:', error);
|
|
21
48
|
return null;
|
|
22
49
|
}
|
|
23
50
|
}
|
|
24
51
|
|
|
25
52
|
async logEvent(eventName, params = {}) {
|
|
53
|
+
const analytics = getAnalytics();
|
|
54
|
+
if (!analytics) return;
|
|
55
|
+
|
|
26
56
|
try {
|
|
27
57
|
await analytics().logEvent(eventName, params);
|
|
28
|
-
config.DEBUG_MODE && console.log('Firebase event logged:', eventName, params);
|
|
58
|
+
config.DEBUG_MODE && console.log('[SDK] Firebase event logged:', eventName, params);
|
|
29
59
|
} catch (error) {
|
|
30
|
-
console.error('Error logging Firebase event:', error);
|
|
60
|
+
console.error('[SDK] Error logging Firebase event:', error);
|
|
31
61
|
}
|
|
32
62
|
}
|
|
33
63
|
|
|
34
64
|
async setUserId(userId) {
|
|
65
|
+
const analytics = getAnalytics();
|
|
66
|
+
if (!analytics) return;
|
|
67
|
+
|
|
35
68
|
try {
|
|
36
69
|
await analytics().setUserId(userId);
|
|
37
|
-
config.DEBUG_MODE && console.log('Firebase user ID set:', userId);
|
|
70
|
+
config.DEBUG_MODE && console.log('[SDK] Firebase user ID set:', userId);
|
|
38
71
|
} catch (error) {
|
|
39
|
-
console.error('Error setting Firebase user ID:', error);
|
|
72
|
+
console.error('[SDK] Error setting Firebase user ID:', error);
|
|
40
73
|
}
|
|
41
74
|
}
|
|
42
75
|
|
|
43
76
|
async setUserProperty(name, value) {
|
|
77
|
+
const analytics = getAnalytics();
|
|
78
|
+
if (!analytics) return;
|
|
79
|
+
|
|
44
80
|
try {
|
|
45
81
|
await analytics().setUserProperty(name, value);
|
|
46
|
-
config.DEBUG_MODE && console.log('Firebase user property set:', name, value);
|
|
82
|
+
config.DEBUG_MODE && console.log('[SDK] Firebase user property set:', name, value);
|
|
47
83
|
} catch (error) {
|
|
48
|
-
console.error('Error setting Firebase user property:', error);
|
|
84
|
+
console.error('[SDK] Error setting Firebase user property:', error);
|
|
49
85
|
}
|
|
50
86
|
}
|
|
51
87
|
}
|