Repository navigation
Refactors Firebase plugin to migrate to Modular API #1105
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @segment/analytics-react-native-plugin-firebase@0.4.3 for the project I'm working on.
I recently noticed that I was seeing various firebase deprecation warnings in Sentry breadcrumbs for our project. For example:
This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22 Please use
getApp()instead.
The instructions as described at that URL are fairly easy to follow, so the replacement wasn't difficult, though it's worth noting I've only tested this patch on my project.
I also think you might want to set higher versions of the '@react-native-firebase/analytics' and '@react-native-firebase/app' peer dependencies in package.json. Our project is using version 22.4.0 for both.
Here is the diff that solved my problem:
diff --git a/node_modules/@segment/analytics-react-native-plugin-firebase/src/FirebasePlugin.tsx b/node_modules/@segment/analytics-react-native-plugin-firebase/src/FirebasePlugin.tsx
index cb47226..7b16c3e 100644
--- a/node_modules/@segment/analytics-react-native-plugin-firebase/src/FirebasePlugin.tsx
+++ b/node_modules/@segment/analytics-react-native-plugin-firebase/src/FirebasePlugin.tsx
@@ -10,14 +10,29 @@ import {
import screen from './methods/screen';
import track from './methods/track';
import reset from './methods/reset';
-import firebaseAnalytics from '@react-native-firebase/analytics';
+import { getAnalytics, setUserId, setUserProperties } from '@react-native-firebase/analytics';
export class FirebasePlugin extends DestinationPlugin {
type = PluginType.destination;
key = 'Firebase';
async identify(event: IdentifyEventType) {
+ let firebaseAnalyticsInstance;
+
+ try {
+ firebaseAnalyticsInstance = await getAnalytics();
+ } catch (error) {
+ this.analytics?.reportInternalError(
+ new SegmentError(
+ ErrorType.PluginError,
+ 'Error on Firebase Identify',
+ error
+ )
+ );
+ return event;
+ }
+
if (event.userId !== undefined) {
- await firebaseAnalytics().setUserId(event.userId);
+ await setUserId(firebaseAnalyticsInstance, event.userId);
}
if (event.traits) {
const eventTraits = event.traits;
@@ -45,7 +60,7 @@ export class FirebasePlugin extends DestinationPlugin {
{}
);
- await firebaseAnalytics().setUserProperties(safeTraits);
+ await setUserProperties(firebaseAnalyticsInstance, safeTraits);
}
return event;
}
diff --git a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/reset.ts b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/reset.ts
index 6f4d6a7..38e2e6e 100644
--- a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/reset.ts
+++ b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/reset.ts
@@ -1,5 +1,6 @@
-import firebaseAnalytics from '@react-native-firebase/analytics';
+import { getAnalytics, resetAnalyticsData } from '@react-native-firebase/analytics';
export default async () => {
- await firebaseAnalytics().resetAnalyticsData();
+ const firebaseAnalyticsInstance = await getAnalytics();
+ await resetAnalyticsData(firebaseAnalyticsInstance);
};
diff --git a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/screen.ts b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/screen.ts
index a0e8c1e..6bbd1ae 100644
--- a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/screen.ts
+++ b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/screen.ts
@@ -1,4 +1,4 @@
-import firebaseAnalytics from '@react-native-firebase/analytics';
+import { getAnalytics, logEvent } from '@react-native-firebase/analytics';
import type { ScreenEventType } from '@segment/analytics-react-native';
export default async (event: ScreenEventType) => {
@@ -8,5 +8,6 @@ export default async (event: ScreenEventType) => {
...event.properties,
};
- await firebaseAnalytics().logScreenView(screenProps);
+ const firebaseAnalyticsInstance = await getAnalytics();
+ await logEvent(firebaseAnalyticsInstance, 'screen_view', screenProps);
};
diff --git a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/track.ts b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/track.ts
index 3926228..9c8e112 100644
--- a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/track.ts
+++ b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/track.ts
@@ -1,4 +1,4 @@
-import firebaseAnalytics from '@react-native-firebase/analytics';
+import { getAnalytics, logEvent } from '@react-native-firebase/analytics';
import {
generateMapTransform,
TrackEventType,
@@ -22,5 +22,6 @@ export default async (event: TrackEventType) => {
if (safeEventName.length > 40) {
safeEventName = safeEventName.substring(0, 40);
}
- await firebaseAnalytics().logEvent(safeEventName, safeProps);
+ const firebaseAnalyticsInstance = await getAnalytics();
+ await logEvent(firebaseAnalyticsInstance, safeEventName, safeProps);
};
This issue body was partially generated by patch-package.
Activity
mattlennon3 commentedon Nov 24, 2025
Hi @Jack-Gill-TH , thanks for creating the patch! I see the same warnings flooding my logs.
We are using these versions:
"@segment/analytics-react-native-plugin-firebase": "0.4.3","@react-native-firebase/analytics": "22.4.0",Your patch did not work for the first file
FirebasePlugin.tsx, I had to apply your changes manually and regenerate the patch file. Here it is below:Jack-Gill-TH commentedon Nov 24, 2025
Ah sorry about that @mattlennon3 , perhaps I made a mistake while copy and pasting!
daniel-nagish commentedon Dec 28, 2025
Hit the same issue, glad to see it wasn't just us
abueide commentedon Feb 19, 2026
closed via #1075 let me know if this solves your issue in the next release
Jack-Gill-TH commentedon Oct 15, 2026
@abueide thanks for #1075, apologies for the long wait for confirmation. I happen to just now be looking at upgrading the firebase plugin version, and have found that the changes merged are only a partial fix.
What 1.0.0 fixes: the Please use getApp() instead warning is gone. The plugin now creates the instance with the modular getAnalytics(getApp()).
What is still open: the plugin still calls methods on that instance (logEvent, logScreenView, setUserId, setUserProperties, resetAnalyticsData). React Native Firebase logs a deprecation warning for each call. In one iOS session (Expo SDK 55, React Native 0.83, @react-native-firebase 22.4.0) I counted 18 warnings for 18 plugin calls, for example:
I opened #1341 to finish the migration. It calls the modular functions with the instance as the first argument. With that change, the same kind of session showed 16 plugin calls on the modular path and no deprecation warnings.
One detail: logScreenView is deprecated in both APIs, so the PR sends logEvent(analytics, 'screen_view', ...). The RNFB typings for that overload use the web names (firebase_screen), but the native SDKs read screen_name and screen_class. The PR keeps the old payload and casts the type.
Could you reopen this issue, or let me know if you prefer to track the remaining work in #1341 only?