-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathRNFBAnalyticsModule.js
More file actions
119 lines (105 loc) · 2.92 KB
/
Copy pathRNFBAnalyticsModule.js
File metadata and controls
119 lines (105 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { getApp } from '@react-native-firebase/app/lib/internal/web/firebaseApp';
import { guard } from '@react-native-firebase/app/lib/internal/web/utils';
import { AnalyticsApi } from './api';
let analyticsInstances = {};
function getAnalyticsApi(appName) {
const app = getApp(appName);
const measurementId = app.options.measurementId;
if (!measurementId) {
// eslint-disable-next-line no-console
console.warn(
'No measurement id (`FirebaseOptions.measurementId`) found for Firebase Analytics. Analytics will be unavailable.',
);
}
if (!analyticsInstances[measurementId]) {
analyticsInstances[measurementId] = new AnalyticsApi('[DEFAULT]', measurementId);
if (globalThis.RNFBDebug) {
analyticsInstances[measurementId].setDebug(true);
}
}
return analyticsInstances[measurementId];
}
/**
* This is a 'NativeModule' for the web platform.
* Methods here are identical to the ones found in
* the native android/ios modules e.g. `@ReactMethod` annotated
* java methods on Android.
*/
export default {
logEvent(name, params) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.logEvent(name, params);
return null;
});
},
setUserId(userId) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.setUserId(userId);
return null;
});
},
setUserProperty(key, value) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.setUserProperty(key, value);
return null;
});
},
setUserProperties(properties) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.setUserProperties(properties);
return null;
});
},
setDefaultEventParameters(params) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.setDefaultEventParameters(params);
return null;
});
},
setConsent(consent) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
// TODO currently we only support ad_personalization
if (consent && consent.ad_personalization) {
api.setConsent({ ad_personalization: consent.ad_personalization });
}
return null;
});
},
setAnalyticsCollectionEnabled(enabled) {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
api.setAnalyticsCollectionEnabled(enabled);
return null;
});
},
resetAnalyticsData() {
// Unsupported for web.
return guard(async () => {
return null;
});
},
setSessionTimeoutDuration() {
// Unsupported for web.
return guard(async () => {
return null;
});
},
getAppInstanceId() {
return guard(async () => {
const api = getAnalyticsApi('[DEFAULT]');
return api._getCid();
});
},
getSessionId() {
// Unsupported for web.
return guard(async () => {
return null;
});
},
};