@react-native-firebase/analytics 23.8.0 → 23.8.2

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.
@@ -0,0 +1,71 @@
1
+ require 'json'
2
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
3
+ appPackage = JSON.parse(File.read(File.join('..', 'app', 'package.json')))
4
+
5
+ coreVersionDetected = appPackage['version']
6
+ coreVersionRequired = package['peerDependencies'][appPackage['name']]
7
+ firebase_sdk_version = appPackage['sdkVersions']['ios']['firebase']
8
+ if coreVersionDetected != coreVersionRequired
9
+ Pod::UI.warn "NPM package '#{package['name']}' depends on '#{appPackage['name']}' v#{coreVersionRequired} but found v#{coreVersionDetected}, this might cause build issues or runtime crashes."
10
+ end
11
+ firebase_ios_target = appPackage['sdkVersions']['ios']['iosTarget']
12
+ firebase_macos_target = appPackage['sdkVersions']['ios']['macosTarget']
13
+ firebase_tvos_target = appPackage['sdkVersions']['ios']['tvosTarget']
14
+
15
+ Pod::Spec.new do |s|
16
+ s.name = "RNFBAnalytics"
17
+ s.version = package["version"]
18
+ s.description = package["description"]
19
+ s.summary = <<-DESC
20
+ A well tested feature rich Firebase implementation for React Native, supporting iOS & Android.
21
+ DESC
22
+ s.homepage = "http://invertase.io/oss/react-native-firebase"
23
+ s.license = package['license']
24
+ s.authors = "Invertase Limited"
25
+ s.source = { :git => "https://github.com/invertase/react-native-firebase.git", :tag => "v#{s.version}" }
26
+ s.social_media_url = 'http://twitter.com/invertaseio'
27
+ s.ios.deployment_target = firebase_ios_target
28
+ s.macos.deployment_target = firebase_macos_target
29
+ s.tvos.deployment_target = firebase_tvos_target
30
+ s.source_files = 'ios/**/*.{h,m}'
31
+
32
+ # React Native dependencies
33
+ s.dependency 'React-Core'
34
+ s.dependency 'RNFBApp'
35
+
36
+ if defined?($FirebaseSDKVersion)
37
+ Pod::UI.puts "#{s.name}: Using user specified Firebase SDK version '#{$FirebaseSDKVersion}'"
38
+ firebase_sdk_version = $FirebaseSDKVersion
39
+ end
40
+
41
+ # Firebase dependencies
42
+ s.dependency 'FirebaseAnalytics/Core', firebase_sdk_version
43
+ if defined?($RNFirebaseAnalyticsWithoutAdIdSupport) && ($RNFirebaseAnalyticsWithoutAdIdSupport == true)
44
+ Pod::UI.puts "#{s.name}: Not installing FirebaseAnalytics/IdentitySupport Pod, no IDFA will be collected."
45
+ else
46
+ if !defined?($RNFirebaseAnalyticsWithoutAdIdSupport)
47
+ Pod::UI.puts "#{s.name}: Using FirebaseAnalytics/IdentitySupport with Ad Ids. May require App Tracking Transparency. Not allowed for Kids apps."
48
+ Pod::UI.puts "#{s.name}: You may set variable `$RNFirebaseAnalyticsWithoutAdIdSupport=true` in Podfile to use analytics without ad ids."
49
+ end
50
+ s.dependency 'FirebaseAnalytics/IdentitySupport', firebase_sdk_version
51
+
52
+ # Special pod for on-device conversion
53
+ if defined?($RNFirebaseAnalyticsEnableAdSupport) && ($RNFirebaseAnalyticsEnableAdSupport == true)
54
+ Pod::UI.puts "#{s.name}: Adding Apple AdSupport.framework dependency for optional analytics features"
55
+ s.frameworks = 'AdSupport'
56
+ end
57
+ end
58
+
59
+ # Special pod for on-device conversion
60
+ if defined?($RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion) && ($RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion == true)
61
+ Pod::UI.puts "#{s.name}: GoogleAdsOnDeviceConversion pod added"
62
+ s.dependency 'GoogleAdsOnDeviceConversion'
63
+ end
64
+
65
+ if defined?($RNFirebaseAsStaticFramework)
66
+ Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNFirebaseAsStaticFramework}'"
67
+ s.static_framework = $RNFirebaseAsStaticFramework
68
+ else
69
+ s.static_framework = false
70
+ end
71
+ end
@@ -0,0 +1,10 @@
1
+ # editorconfig
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
@@ -0,0 +1,177 @@
1
+ /* groovylint-disable DuplicateStringLiteral */
2
+
3
+ import com.android.Version
4
+ import io.invertase.gradle.common.PackageJson
5
+
6
+ buildscript {
7
+ // The Android Gradle plugin is only required when opening the android folder stand-alone.
8
+ // This avoids unnecessary downloads and potential conflicts when the library is included as a
9
+ // module dependency in an application project.
10
+ if (project == rootProject) {
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+
16
+ dependencies {
17
+ classpath("com.android.tools.build:gradle:8.4.0")
18
+ }
19
+ }
20
+ }
21
+
22
+ plugins {
23
+ id "io.invertase.gradle.build" version "1.5"
24
+ }
25
+
26
+ def appProject
27
+ if (findProject(':@react-native-firebase_app')) {
28
+ appProject = project(':@react-native-firebase_app')
29
+ } else if (findProject(':react-native-firebase_app')) {
30
+ appProject = project(':react-native-firebase_app')
31
+ } else {
32
+ throw new GradleException('Could not find the react-native-firebase/app package, have you installed it?')
33
+ }
34
+ def packageJson = PackageJson.getForProject(project)
35
+ def appPackageJson = PackageJson.getForProject(appProject)
36
+ def firebaseBomVersion = appPackageJson['sdkVersions']['android']['firebase']
37
+ def jsonMinSdk = appPackageJson['sdkVersions']['android']['minSdk']
38
+ def jsonTargetSdk = appPackageJson['sdkVersions']['android']['targetSdk']
39
+ def jsonCompileSdk = appPackageJson['sdkVersions']['android']['compileSdk']
40
+ def coreVersionDetected = appPackageJson['version']
41
+ def coreVersionRequired = packageJson['peerDependencies'][appPackageJson['name']]
42
+ if (coreVersionDetected != coreVersionRequired) {
43
+ project.logger.warn("ReactNativeFirebase WARNING: NPM package '${packageJson['name']}' depends on '${appPackageJson['name']}' v${coreVersionRequired} but found v${coreVersionDetected}, this might cause build issues or runtime crashes.")
44
+ }
45
+
46
+ project.ext {
47
+ set('react-native', [
48
+ versions: [
49
+ android : [
50
+ minSdk : jsonMinSdk,
51
+ targetSdk : jsonTargetSdk,
52
+ compileSdk: jsonCompileSdk,
53
+ ],
54
+
55
+ firebase: [
56
+ bom: firebaseBomVersion,
57
+ ],
58
+ ],
59
+ ])
60
+ }
61
+
62
+ apply from: file('./../../app/android/firebase-json.gradle')
63
+
64
+ String collectionDeactivated = 'false'
65
+ String adidEnabled = 'true'
66
+ String ssaidEnabled = 'true'
67
+ String automaticScreenReportingEnabled = 'true'
68
+ String analyticsStorageEnabled = 'true'
69
+ String adStorageEnabled = 'true'
70
+ String adUserDataEnabled = 'true'
71
+ String personalizationEnabled = 'true'
72
+
73
+ // If nothing is defined, data collection defaults to true
74
+ String dataCollectionEnabled = 'true'
75
+
76
+ if (rootProject.ext && rootProject.ext.firebaseJson) {
77
+ /* groovylint-disable-next-line NoDef, VariableTypeRequired */
78
+ def rnfbConfig = rootProject.ext.firebaseJson
79
+ // If the SDK-wide data collection flag is defined and false, our default flips to false
80
+ if (rnfbConfig.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
81
+ dataCollectionEnabled = 'false'
82
+ }
83
+ // If our specific collection flag is defined, it's status takes precedence
84
+ if (rnfbConfig.isDefined('analytics_auto_collection_enabled')) {
85
+ if (rnfbConfig.isFlagEnabled('analytics_auto_collection_enabled', true)) {
86
+ dataCollectionEnabled = 'true'
87
+ } else {
88
+ dataCollectionEnabled = 'false'
89
+ }
90
+ }
91
+
92
+ if (rnfbConfig.isFlagEnabled('analytics_collection_deactivated', false) == true) {
93
+ collectionDeactivated = 'true'
94
+ }
95
+ if (rnfbConfig.isFlagEnabled('google_analytics_adid_collection_enabled', true) == false) {
96
+ adidEnabled = 'false'
97
+ }
98
+ if (rnfbConfig.isFlagEnabled('google_analytics_ssaid_collection_enabled', true) == false) {
99
+ ssaidEnabled = 'false'
100
+ }
101
+ if (rnfbConfig.isFlagEnabled('google_analytics_automatic_screen_reporting_enabled', true) == false) {
102
+ automaticScreenReportingEnabled = 'false'
103
+ }
104
+ if (rnfbConfig.isFlagEnabled('analytics_default_allow_analytics_storage', true) == false) {
105
+ analyticsStorageEnabled = 'false'
106
+ }
107
+ if (rnfbConfig.isFlagEnabled('analytics_default_allow_ad_storage', true) == false) {
108
+ adStorageEnabled = 'false'
109
+ }
110
+ if (rnfbConfig.isFlagEnabled('analytics_default_allow_ad_user_data', true) == false) {
111
+ adUserDataEnabled = 'false'
112
+ }
113
+ if (rnfbConfig.isFlagEnabled('analytics_default_allow_ad_personalization_signals', true) == false) {
114
+ personalizationEnabled = 'false'
115
+ }
116
+ }
117
+
118
+ android {
119
+ def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
120
+ if (agpVersion >= 7) {
121
+ namespace = 'io.invertase.firebase.analytics'
122
+ }
123
+
124
+ defaultConfig {
125
+ multiDexEnabled = true
126
+ manifestPlaceholders = [
127
+ firebaseJsonAutoCollectionEnabled: dataCollectionEnabled,
128
+ firebaseJsonCollectionDeactivated: collectionDeactivated,
129
+ firebaseJsonAdidEnabled: adidEnabled,
130
+ firebaseJsonSsaidEnabled: ssaidEnabled,
131
+ firebaseJsonAutomaticScreenReportingEnabled: automaticScreenReportingEnabled,
132
+ firebaseJsonAnalyticsStorageEnabled: analyticsStorageEnabled,
133
+ firebaseJsonAdStorageEnabled: adStorageEnabled,
134
+ firebaseJsonAdUserDataEnabled: adUserDataEnabled,
135
+ firebaseJsonPersonalizationEnabled: personalizationEnabled
136
+ ]
137
+ }
138
+
139
+ buildFeatures {
140
+ // AGP 8 no longer builds config by default
141
+ buildConfig = true
142
+ }
143
+
144
+ lintOptions {
145
+ disable 'GradleCompatible'
146
+ abortOnError = false
147
+ }
148
+
149
+ if (agpVersion < 8) {
150
+ compileOptions {
151
+ sourceCompatibility = JavaVersion.VERSION_11
152
+ targetCompatibility = JavaVersion.VERSION_11
153
+ }
154
+ }
155
+
156
+ sourceSets {
157
+ main {
158
+ java.srcDirs = ['src/main/java', 'src/reactnative/java']
159
+ }
160
+ }
161
+ }
162
+
163
+ repositories {
164
+ google()
165
+ mavenCentral()
166
+ }
167
+
168
+ dependencies {
169
+ api appProject
170
+ implementation platform("com.google.firebase:firebase-bom:${ReactNative.ext.getVersion("firebase", "bom")}")
171
+ implementation "com.google.firebase:firebase-analytics"
172
+ }
173
+
174
+ ReactNative.shared.applyPackageVersion()
175
+ ReactNative.shared.applyDefaultExcludes()
176
+ ReactNative.module.applyAndroidVersions()
177
+ ReactNative.module.applyReactNativeDependency("api")
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <lint>
3
+ <!-- Disable the given check in this project -->
4
+ <issue id="GradleCompatible" severity="ignore" />
5
+ </lint>
@@ -0,0 +1 @@
1
+ rootProject.name = '@react-native-firebase_analytics'
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest package="io.invertase.firebase.analytics"
3
+ xmlns:android="http://schemas.android.com/apk/res/android">
4
+
5
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6
+ <uses-permission android:name="android.permission.INTERNET" />
7
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
8
+
9
+ <application>
10
+ <meta-data android:name="firebase_analytics_collection_enabled" android:value="${firebaseJsonAutoCollectionEnabled}"/>
11
+ <meta-data android:name="firebase_analytics_collection_deactivated" android:value="${firebaseJsonCollectionDeactivated}" />
12
+ <meta-data android:name="google_analytics_adid_collection_enabled" android:value="${firebaseJsonAdidEnabled}" />
13
+ <meta-data android:name="google_analytics_ssaid_collection_enabled" android:value="${firebaseJsonSsaidEnabled}" />
14
+ <meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="${firebaseJsonAutomaticScreenReportingEnabled}" />
15
+ <meta-data android:name="google_analytics_default_allow_analytics_storage" android:value="${firebaseJsonAnalyticsStorageEnabled}" />
16
+ <meta-data android:name="google_analytics_default_allow_ad_storage" android:value="${firebaseJsonAdStorageEnabled}" />
17
+ <meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="${firebaseJsonAdUserDataEnabled}" />
18
+ <meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="${firebaseJsonPersonalizationEnabled}" />
19
+
20
+ </application>
21
+ </manifest>
@@ -0,0 +1,141 @@
1
+ package io.invertase.firebase.analytics;
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.content.Context;
21
+ import android.os.Bundle;
22
+ import com.google.android.gms.tasks.Task;
23
+ import com.google.android.gms.tasks.Tasks;
24
+ import com.google.firebase.analytics.FirebaseAnalytics;
25
+ import com.google.firebase.analytics.FirebaseAnalytics.ConsentStatus;
26
+ import com.google.firebase.analytics.FirebaseAnalytics.ConsentType;
27
+ import io.invertase.firebase.common.UniversalFirebaseModule;
28
+ import java.util.EnumMap;
29
+ import java.util.Map;
30
+ import java.util.Set;
31
+
32
+ @SuppressWarnings("WeakerAccess")
33
+ public class UniversalFirebaseAnalyticsModule extends UniversalFirebaseModule {
34
+
35
+ UniversalFirebaseAnalyticsModule(Context context, String serviceName) {
36
+ super(context, serviceName);
37
+ }
38
+
39
+ Task<Void> logEvent(String name, Bundle parameters) {
40
+ return Tasks.call(
41
+ () -> {
42
+ FirebaseAnalytics.getInstance(getContext()).logEvent(name, parameters);
43
+ return null;
44
+ });
45
+ }
46
+
47
+ Task<Void> setAnalyticsCollectionEnabled(Boolean enabled) {
48
+ return Tasks.call(
49
+ () -> {
50
+ FirebaseAnalytics.getInstance(getContext()).setAnalyticsCollectionEnabled(enabled);
51
+ return null;
52
+ });
53
+ }
54
+
55
+ Task<Void> setSessionTimeoutDuration(long milliseconds) {
56
+ return Tasks.call(
57
+ () -> {
58
+ FirebaseAnalytics.getInstance(getContext()).setSessionTimeoutDuration(milliseconds);
59
+ return null;
60
+ });
61
+ }
62
+
63
+ Task<String> getAppInstanceId() {
64
+ return FirebaseAnalytics.getInstance(getContext()).getAppInstanceId();
65
+ }
66
+
67
+ Task<Long> getSessionId() {
68
+ return FirebaseAnalytics.getInstance(getContext()).getSessionId();
69
+ }
70
+
71
+ Task<Void> setUserId(String id) {
72
+ return Tasks.call(
73
+ () -> {
74
+ FirebaseAnalytics.getInstance(getContext()).setUserId(id);
75
+ return null;
76
+ });
77
+ }
78
+
79
+ Task<Void> setUserProperty(String name, String value) {
80
+ return Tasks.call(
81
+ () -> {
82
+ FirebaseAnalytics.getInstance(getContext()).setUserProperty(name, value);
83
+ return null;
84
+ });
85
+ }
86
+
87
+ Task<Void> setUserProperties(Bundle properties) {
88
+ return Tasks.call(
89
+ () -> {
90
+ Set<String> bundleKeys = properties.keySet();
91
+ FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(getContext());
92
+
93
+ for (String bundleKey : bundleKeys) {
94
+ firebaseAnalytics.setUserProperty(bundleKey, (String) properties.get(bundleKey));
95
+ }
96
+
97
+ return null;
98
+ });
99
+ }
100
+
101
+ Task<Void> resetAnalyticsData() {
102
+ return Tasks.call(
103
+ () -> {
104
+ FirebaseAnalytics.getInstance(getContext()).resetAnalyticsData();
105
+ return null;
106
+ });
107
+ }
108
+
109
+ Task<Void> setDefaultEventParameters(Bundle parameters) {
110
+ return Tasks.call(
111
+ () -> {
112
+ FirebaseAnalytics.getInstance(getContext()).setDefaultEventParameters(parameters);
113
+ return null;
114
+ });
115
+ }
116
+
117
+ Task<Void> setConsent(Bundle consentSettings) {
118
+ return Tasks.call(
119
+ () -> {
120
+ boolean analyticsStorage = consentSettings.getBoolean("analytics_storage");
121
+ boolean adStorage = consentSettings.getBoolean("ad_storage");
122
+ boolean adUserData = consentSettings.getBoolean("ad_user_data");
123
+ boolean adPersonalization = consentSettings.getBoolean("ad_personalization");
124
+
125
+ Map<ConsentType, ConsentStatus> consentMap = new EnumMap<>(ConsentType.class);
126
+ consentMap.put(
127
+ ConsentType.ANALYTICS_STORAGE,
128
+ analyticsStorage ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
129
+ consentMap.put(
130
+ ConsentType.AD_STORAGE, adStorage ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
131
+ consentMap.put(
132
+ ConsentType.AD_USER_DATA, adUserData ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
133
+ consentMap.put(
134
+ ConsentType.AD_PERSONALIZATION,
135
+ adPersonalization ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
136
+
137
+ FirebaseAnalytics.getInstance(getContext()).setConsent(consentMap);
138
+ return null;
139
+ });
140
+ }
141
+ }
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest package="io.invertase.firebase.analytics" />
@@ -0,0 +1,213 @@
1
+ package io.invertase.firebase.analytics;
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.os.Bundle;
21
+ import com.facebook.react.bridge.Arguments;
22
+ import com.facebook.react.bridge.Promise;
23
+ import com.facebook.react.bridge.ReactApplicationContext;
24
+ import com.facebook.react.bridge.ReactMethod;
25
+ import com.facebook.react.bridge.ReadableMap;
26
+ import com.google.firebase.analytics.FirebaseAnalytics;
27
+ import io.invertase.firebase.common.ReactNativeFirebaseModule;
28
+ import java.util.ArrayList;
29
+ import javax.annotation.Nullable;
30
+
31
+ public class ReactNativeFirebaseAnalyticsModule extends ReactNativeFirebaseModule {
32
+ private static final String SERVICE_NAME = "Analytics";
33
+ private final UniversalFirebaseAnalyticsModule module;
34
+
35
+ ReactNativeFirebaseAnalyticsModule(ReactApplicationContext reactContext) {
36
+ super(reactContext, SERVICE_NAME);
37
+ module = new UniversalFirebaseAnalyticsModule(reactContext, SERVICE_NAME);
38
+ }
39
+
40
+ @ReactMethod
41
+ public void logEvent(String name, @Nullable ReadableMap params, Promise promise) {
42
+ module
43
+ .logEvent(name, toBundle(params))
44
+ .addOnCompleteListener(
45
+ task -> {
46
+ if (task.isSuccessful()) {
47
+ promise.resolve(task.getResult());
48
+ } else {
49
+ rejectPromiseWithExceptionMap(promise, task.getException());
50
+ }
51
+ });
52
+ }
53
+
54
+ @ReactMethod
55
+ public void setAnalyticsCollectionEnabled(Boolean enabled, Promise promise) {
56
+ module
57
+ .setAnalyticsCollectionEnabled(enabled)
58
+ .addOnCompleteListener(
59
+ task -> {
60
+ if (task.isSuccessful()) {
61
+ promise.resolve(task.getResult());
62
+ } else {
63
+ rejectPromiseWithExceptionMap(promise, task.getException());
64
+ }
65
+ });
66
+ }
67
+
68
+ @ReactMethod
69
+ public void setSessionTimeoutDuration(double milliseconds, Promise promise) {
70
+ module
71
+ .setSessionTimeoutDuration((long) milliseconds)
72
+ .addOnCompleteListener(
73
+ task -> {
74
+ if (task.isSuccessful()) {
75
+ promise.resolve(task.getResult());
76
+ } else {
77
+ rejectPromiseWithExceptionMap(promise, task.getException());
78
+ }
79
+ });
80
+ }
81
+
82
+ @ReactMethod
83
+ public void getAppInstanceId(Promise promise) {
84
+ module
85
+ .getAppInstanceId()
86
+ .addOnCompleteListener(
87
+ task -> {
88
+ if (task.isSuccessful()) {
89
+ promise.resolve(task.getResult());
90
+ } else {
91
+ rejectPromiseWithExceptionMap(promise, task.getException());
92
+ }
93
+ });
94
+ }
95
+
96
+ @ReactMethod
97
+ public void getSessionId(Promise promise) {
98
+ module
99
+ .getSessionId()
100
+ .addOnCompleteListener(
101
+ task -> {
102
+ if (task.isSuccessful()) {
103
+ Long result = task.getResult();
104
+ promise.resolve(result != null ? result.doubleValue() : null);
105
+ } else {
106
+ rejectPromiseWithExceptionMap(promise, task.getException());
107
+ }
108
+ });
109
+ }
110
+
111
+ @ReactMethod
112
+ public void setUserId(String id, Promise promise) {
113
+ module
114
+ .setUserId(id)
115
+ .addOnCompleteListener(
116
+ task -> {
117
+ if (task.isSuccessful()) {
118
+ promise.resolve(task.getResult());
119
+ } else {
120
+ rejectPromiseWithExceptionMap(promise, task.getException());
121
+ }
122
+ });
123
+ }
124
+
125
+ @ReactMethod
126
+ public void setUserProperty(String name, String value, Promise promise) {
127
+ module
128
+ .setUserProperty(name, value)
129
+ .addOnCompleteListener(
130
+ task -> {
131
+ if (task.isSuccessful()) {
132
+ promise.resolve(task.getResult());
133
+ } else {
134
+ rejectPromiseWithExceptionMap(promise, task.getException());
135
+ }
136
+ });
137
+ }
138
+
139
+ @ReactMethod
140
+ public void setUserProperties(ReadableMap properties, Promise promise) {
141
+ module
142
+ .setUserProperties(Arguments.toBundle(properties))
143
+ .addOnCompleteListener(
144
+ task -> {
145
+ if (task.isSuccessful()) {
146
+ promise.resolve(task.getResult());
147
+ } else {
148
+ rejectPromiseWithExceptionMap(promise, task.getException());
149
+ }
150
+ });
151
+ }
152
+
153
+ @ReactMethod
154
+ public void resetAnalyticsData(Promise promise) {
155
+ module
156
+ .resetAnalyticsData()
157
+ .addOnCompleteListener(
158
+ task -> {
159
+ if (task.isSuccessful()) {
160
+ promise.resolve(task.getResult());
161
+ } else {
162
+ rejectPromiseWithExceptionMap(promise, task.getException());
163
+ }
164
+ });
165
+ }
166
+
167
+ @ReactMethod
168
+ public void setDefaultEventParameters(@Nullable ReadableMap params, Promise promise) {
169
+ module
170
+ .setDefaultEventParameters(toBundle(params))
171
+ .addOnCompleteListener(
172
+ task -> {
173
+ if (task.isSuccessful()) {
174
+ promise.resolve(task.getResult());
175
+ } else {
176
+ rejectPromiseWithExceptionMap(promise, task.getException());
177
+ }
178
+ });
179
+ }
180
+
181
+ @ReactMethod
182
+ public void setConsent(ReadableMap consentSettings, Promise promise) {
183
+ module
184
+ .setConsent(Arguments.toBundle(consentSettings))
185
+ .addOnCompleteListener(
186
+ task -> {
187
+ if (task.isSuccessful()) {
188
+ promise.resolve(task.getResult());
189
+ } else {
190
+ rejectPromiseWithExceptionMap(promise, task.getException());
191
+ }
192
+ });
193
+ }
194
+
195
+ private Bundle toBundle(ReadableMap readableMap) {
196
+ Bundle bundle = Arguments.toBundle(readableMap);
197
+ if (bundle == null) {
198
+ return null;
199
+ }
200
+ ArrayList itemsArray = (ArrayList) bundle.getSerializable(FirebaseAnalytics.Param.ITEMS);
201
+ for (Object item : itemsArray != null ? itemsArray : new ArrayList()) {
202
+ if (item instanceof Bundle && ((Bundle) item).containsKey(FirebaseAnalytics.Param.QUANTITY)) {
203
+ double number = ((Bundle) item).getDouble(FirebaseAnalytics.Param.QUANTITY);
204
+ ((Bundle) item).putInt(FirebaseAnalytics.Param.QUANTITY, (int) number);
205
+ }
206
+ }
207
+ if (bundle.containsKey(FirebaseAnalytics.Param.EXTEND_SESSION)) {
208
+ double number = bundle.getDouble(FirebaseAnalytics.Param.EXTEND_SESSION);
209
+ bundle.putLong(FirebaseAnalytics.Param.EXTEND_SESSION, (long) number);
210
+ }
211
+ return bundle;
212
+ }
213
+ }
@@ -0,0 +1,41 @@
1
+ package io.invertase.firebase.analytics;
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import com.facebook.react.ReactPackage;
21
+ import com.facebook.react.bridge.NativeModule;
22
+ import com.facebook.react.bridge.ReactApplicationContext;
23
+ import com.facebook.react.uimanager.ViewManager;
24
+ import java.util.ArrayList;
25
+ import java.util.Collections;
26
+ import java.util.List;
27
+
28
+ @SuppressWarnings("unused")
29
+ public class ReactNativeFirebaseAnalyticsPackage implements ReactPackage {
30
+ @Override
31
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
32
+ List<NativeModule> modules = new ArrayList<>();
33
+ modules.add(new ReactNativeFirebaseAnalyticsModule(reactContext));
34
+ return modules;
35
+ }
36
+
37
+ @Override
38
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
39
+ return Collections.emptyList();
40
+ }
41
+ }