-
Notifications
You must be signed in to change notification settings - Fork 198
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @segment/[email protected]
for the project I'm working on.
I recently upgraded @react-native-firebase
to v22, which includes a migration guide to upgrade from the namespaced API to the modular API.
"dependencies": {
"react": "19.0.0",
"react-native": "0.79.3",
"@react-native-firebase/analytics": "^22.2.0",
"@react-native-firebase/app": "^22.2.0",
"@segment/analytics-react-native": "2.21.1",
"@segment/analytics-react-native-plugin-firebase": "^0.4.3",
"@segment/sovran-react-native": "^1.1.3",
}
With deprecation strict mode enabled to help locate any remaining usage of the deprecated namespace API, we noticed that our purchase
event was no longer logging any revenue data, which we traced back to an internal error on the FirebasePlugin
Here's the error

So we made a patch that allows @segment/analytics-react-native-plugin-firebase
to continue working for both users who are using the modular and the namespaced API by simply toggling the RNFB_MODULAR_DEPRECATION_STRICT_MODE
On the project's root index.js
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE = true; // Toggle this as needed
AppRegistry.registerComponent(appName, () => App);
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..8f0ad70 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
@@ -1,24 +1,30 @@
+import firebaseAnalyticsCompat, * as firebaseAnalyticsModular from '@react-native-firebase/analytics';
import {
DestinationPlugin,
+ ErrorType,
IdentifyEventType,
PluginType,
ScreenEventType,
SegmentError,
- ErrorType,
TrackEventType,
} from '@segment/analytics-react-native';
+import reset from './methods/reset';
import screen from './methods/screen';
import track from './methods/track';
-import reset from './methods/reset';
-import firebaseAnalytics from '@react-native-firebase/analytics';
export class FirebasePlugin extends DestinationPlugin {
type = PluginType.destination;
key = 'Firebase';
async identify(event: IdentifyEventType) {
if (event.userId !== undefined) {
- await firebaseAnalytics().setUserId(event.userId);
+ if (globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) {
+ const analytics = firebaseAnalyticsModular.getAnalytics();
+ await firebaseAnalyticsModular.setUserId(analytics, event.userId);
+ } else {
+ await firebaseAnalyticsCompat().setUserId(event.userId);
+ }
}
+
if (event.traits) {
const eventTraits = event.traits;
@@ -45,8 +51,14 @@ export class FirebasePlugin extends DestinationPlugin {
{}
);
- await firebaseAnalytics().setUserProperties(safeTraits);
+ if (globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) {
+ const analytics = firebaseAnalyticsModular.getAnalytics();
+ await firebaseAnalyticsModular.setUserProperties(analytics, safeTraits);
+ } else {
+ await firebaseAnalyticsCompat().setUserProperties(safeTraits);
+ }
}
+
return event;
}
@@ -72,7 +84,7 @@ export class FirebasePlugin extends DestinationPlugin {
this.analytics?.reportInternalError(
new SegmentError(
ErrorType.PluginError,
- 'Error on Firebase Track',
+ 'Error on Firebase Screen',
error
)
);
@@ -87,7 +99,7 @@ export class FirebasePlugin extends DestinationPlugin {
this.analytics?.reportInternalError(
new SegmentError(
ErrorType.PluginError,
- 'Error on Firebase Track',
+ 'Error on Firebase Reset',
error
)
);
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..6648dbe 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,10 @@
-import firebaseAnalytics from '@react-native-firebase/analytics';
+import firebaseAnalyticsCompat, * as firebaseAnalyticsModular from '@react-native-firebase/analytics';
export default async () => {
- await firebaseAnalytics().resetAnalyticsData();
+ if (globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) {
+ const analytics = firebaseAnalyticsModular.getAnalytics();
+ await firebaseAnalyticsModular.resetAnalyticsData(analytics);
+ } else {
+ await firebaseAnalyticsCompat().resetAnalyticsData();
+ }
};
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..bdfc01f 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 firebaseAnalyticsCompat, * as firebaseAnalyticsModular from '@react-native-firebase/analytics';
import type { ScreenEventType } from '@segment/analytics-react-native';
export default async (event: ScreenEventType) => {
@@ -8,5 +8,10 @@ export default async (event: ScreenEventType) => {
...event.properties,
};
- await firebaseAnalytics().logScreenView(screenProps);
+ if (globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) {
+ const analytics = firebaseAnalyticsModular.getAnalytics();
+ await firebaseAnalyticsModular.logScreenView(analytics, screenProps);
+ } else {
+ await firebaseAnalyticsCompat().logScreenView(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..6cd00b8 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 firebaseAnalyticsCompat, * as firebaseAnalyticsModular from '@react-native-firebase/analytics';
import {
generateMapTransform,
TrackEventType,
@@ -22,5 +22,11 @@ export default async (event: TrackEventType) => {
if (safeEventName.length > 40) {
safeEventName = safeEventName.substring(0, 40);
}
- await firebaseAnalytics().logEvent(safeEventName, safeProps);
+
+ if (globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) {
+ const analytics = firebaseAnalyticsModular.getAnalytics();
+ await firebaseAnalyticsModular.logEvent(analytics, safeEventName, safeProps);
+ } else {
+ await firebaseAnalyticsCompat().logEvent(safeEventName, safeProps);
+ }
};
This issue body was partially generated by patch-package.