DataDog / dd-sdk-reactnative

Datadog SDK for ReactNative
Apache License 2.0
120 stars 41 forks source link

feat: add support for route params to be passed to the `startView` tracking for react-navigation #579

Open angelo-hub opened 9 months ago

angelo-hub commented 9 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @datadog/mobile-react-navigation@2.0.1 for the project I'm working on.

This adds more detailed tracking of Views by passing the data to the Datadog package

Here is the diff that solved my problem:

diff --git a/node_modules/@datadog/mobile-react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.tsx b/node_modules/@datadog/mobile-react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.tsx
index 0e4828a..1b2de2c 100644
--- a/node_modules/@datadog/mobile-react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.tsx
+++ b/node_modules/@datadog/mobile-react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.tsx
@@ -184,7 +184,7 @@ export class DdRumReactNavigationTracking {
             // On iOS, the app can start in either "active", "background" or "unknown" state
             if (appStateStatus !== 'background') {
                 DdRumReactNavigationTracking.trackingState = 'TRACKING';
-                DdRum.startView(key, screenName);
+                DdRum.startView(key, screenName, { params: route.params });
             }
         }
     }
@@ -210,7 +210,7 @@ export class DdRumReactNavigationTracking {
                 // case when app goes into foreground,
                 // in that case navigation listener won't be called
                 DdRumReactNavigationTracking.trackingState = 'TRACKING';
-                DdRum.startView(key, screenName);
+                DdRum.startView(key, screenName, { params: route.params });
             }
         }
     }

This issue body was partially generated by patch-package.

louiszawadzki commented 8 months ago

Hi @angelo-hub, thanks for reaching out!

I've added a task in our backlog to see if we can add this feature :)

There are a few things we need to be cautious about when implementing it. You first need to make sure that no personal user information leaks through the route parameters. Then you also need to be sure that there is no parameter that cannot be serialized into JSON. If this is the case, when calling the native SDK the serialization done by React Native will fail and the app could crash.

For all these reasons I believe we need to consider a way to edit the params that are passed so some of them can be removed.

compwron commented 4 days ago

My team would also like this :)