segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
360 stars 185 forks source link

Cart Viewed not mapping to Firebase #856

Closed ZimboPro closed 1 year ago

ZimboPro commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @segment/analytics-react-native-plugin-firebase@0.3.9 for the project I'm working on.

The string type check was causing issues and so we updated the check accordingly and the Cart Viewed event was not being mapped correctly to the view_cart event in Firebase.

Here is the diff that solved my problem:

diff --git a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/parameterMapping.ts b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/parameterMapping.ts
index 7229fb0..943cabe 100644
--- a/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/parameterMapping.ts
+++ b/node_modules/@segment/analytics-react-native-plugin-firebase/src/methods/parameterMapping.ts
@@ -1,5 +1,3 @@
-import { isString } from '@segment/analytics-react-native';
-
 const mapEventNames: { [key: string]: string } = {
   'Product Clicked': 'select_content',
   'Product Viewed': 'view_item',
@@ -15,6 +13,7 @@ const mapEventNames: { [key: string]: string } = {
   'Product Shared': 'share',
   'Cart Shared': 'share',
   'Products Searched': 'search',
+  'Cart Viewed': 'view_cart'
 };

 export const mapEventProps: { [key: string]: string } = {
@@ -30,7 +29,7 @@ export const mapEventProps: { [key: string]: string } = {

 export const transformMap: { [key: string]: (value: unknown) => unknown } = {
   event: (value: unknown) => {
-    if (isString(value) && value in mapEventNames) {
+    if (typeof value === 'string' && value in mapEventNames) {
       return mapEventNames[value];
     }
     return value;

This issue body was partially generated by patch-package.