@datadog/mobile-react-navigation 1.0.0-rc2 → 1.0.0-rc5

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.
Files changed (28) hide show
  1. package/README.md +8 -3
  2. package/lib/commonjs/index.js +8 -4
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +38 -16
  5. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  6. package/lib/module/index.js +2 -2
  7. package/lib/module/index.js.map +1 -1
  8. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +37 -15
  9. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  10. package/lib/typescript/core/src/DdSdkReactNative.d.ts +9 -0
  11. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +5 -2
  12. package/lib/typescript/core/src/InternalLog.d.ts +6 -0
  13. package/lib/typescript/core/src/ProxyConfiguration.d.ts +56 -0
  14. package/lib/typescript/core/src/SdkVerbosity.d.ts +9 -0
  15. package/lib/typescript/core/src/Timer.d.ts +20 -0
  16. package/lib/typescript/core/src/index.d.ts +3 -1
  17. package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -0
  18. package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
  19. package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +2 -2
  20. package/lib/typescript/core/src/types.d.ts +12 -11
  21. package/lib/typescript/core/src/version.d.ts +1 -0
  22. package/lib/typescript/react-navigation/src/index.d.ts +2 -2
  23. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +5 -3
  24. package/package.json +4 -4
  25. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +38 -3
  26. package/src/index.tsx +2 -2
  27. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +44 -17
  28. package/lib/typescript/core/src/NativeSdkVerbosity.d.ts +0 -9
package/README.md CHANGED
@@ -20,18 +20,23 @@ yarn add @datadog/mobile-react-navigation
20
20
 
21
21
  ### Track view navigation
22
22
 
23
- To track changes in navigation as RUM Views, set the `onready` callback of your `NavigationContainer` component:
23
+ To track changes in navigation as RUM Views, set the `onready` callback of your `NavigationContainer` component as follow. You can use the optional `ViewNamePredicate` parameter to replace the automatically detected View name with something more relevant to your use case.
24
24
 
25
25
  ```js
26
26
  import * as React from 'react';
27
- import { DdRumReactNavigationTracking } from '@datadog/mobile-react-navigation';
27
+ import { DdRumReactNavigationTracking, ViewNamePredicate } from '@datadog/mobile-react-navigation';
28
+ import { Route } from "@react-navigation/native";
29
+
30
+ const viewNamePredicate: ViewNamePredicate = function customViewNamePredicate(route: Route<string, any | undefined>, trackedName: string) {
31
+ return "My custom View Name"
32
+ }
28
33
 
29
34
  function App() {
30
35
  const navigationRef = React.useRef(null);
31
36
  return (
32
37
  <View>
33
38
  <NavigationContainer ref={navigationRef} onReady={() => {
34
- DdRumReactNavigationTracking.startTrackingViews(navigationRef.current)
39
+ DdRumReactNavigationTracking.startTrackingViews(navigationRef.current, viewNamePredicate)
35
40
  }}>
36
41
  // …
37
42
  </NavigationContainer>
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "DdRumReactNavigationTracking", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _DdRumReactNavigationTracking.default;
9
+ return _DdRumReactNavigationTracking.DdRumReactNavigationTracking;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ViewNamePredicate", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _DdRumReactNavigationTracking.ViewNamePredicate;
10
16
  }
11
17
  });
12
18
 
13
- var _DdRumReactNavigationTracking = _interopRequireDefault(require("./rum/instrumentation/DdRumReactNavigationTracking"));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ var _DdRumReactNavigationTracking = require("./rum/instrumentation/DdRumReactNavigationTracking");
16
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAMA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport DdRumReactNavigationTracking from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking };\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRumReactNavigationTracking, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.DdRumReactNavigationTracking = void 0;
7
7
 
8
8
  var _mobileReactNative = require("@datadog/mobile-react-native");
9
9
 
@@ -20,13 +20,19 @@ class DdRumReactNavigationTracking {
20
20
  * @param navigationRef the reference to the real NavigationContainer.
21
21
  */
22
22
  static startTrackingViews(navigationRef) {
23
+ let viewNamePredicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_route, trackedName) {
24
+ return trackedName;
25
+ };
26
+
23
27
  if (navigationRef == null) {
28
+ console.log("Cannot track views with a null navigationRef");
24
29
  return;
25
30
  }
26
31
 
27
32
  if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
28
33
  console.error('Cannot track new navigation container while another one is still tracked');
29
34
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
35
+ DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
30
36
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
31
37
  DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
32
38
  navigationRef.addListener("state", listener);
@@ -45,15 +51,35 @@ class DdRumReactNavigationTracking {
45
51
  if (navigationRef != null) {
46
52
  navigationRef.removeListener("state", DdRumReactNavigationTracking.navigationStateChangeListener);
47
53
  DdRumReactNavigationTracking.registeredContainer = null;
54
+
55
+ DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
56
+ return trackedName;
57
+ };
48
58
  }
49
59
  }
50
60
 
51
61
  static handleRouteNavigation(route) {
52
- const key = route === null || route === void 0 ? void 0 : route.key;
53
- const screenName = route === null || route === void 0 ? void 0 : route.name;
62
+ var _predicate;
63
+
64
+ let appStateStatus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
65
+
66
+ if (route == undefined || route == null) {
67
+ // RUMM-1400 in some cases the route seem to be undefined
68
+ return;
69
+ }
70
+
71
+ const key = route.key;
72
+ const predicate = DdRumReactNavigationTracking.viewNamePredicate;
73
+ const screenName = (_predicate = predicate(route, route.name)) !== null && _predicate !== void 0 ? _predicate : route.name;
54
74
 
55
75
  if (key != null && screenName != null) {
56
- _mobileReactNative.DdRum.startView(key, screenName);
76
+ if (appStateStatus === 'background') {
77
+ _mobileReactNative.DdRum.stopView(key);
78
+ } else if (appStateStatus === 'active' || appStateStatus == undefined) {
79
+ // case when app goes into foreground,
80
+ // in that case navigation listener won't be called
81
+ _mobileReactNative.DdRum.startView(key, screenName);
82
+ }
57
83
  }
58
84
  }
59
85
 
@@ -93,18 +119,12 @@ class DdRumReactNavigationTracking {
93
119
  var _DdRumReactNavigation;
94
120
 
95
121
  const currentRoute = (_DdRumReactNavigation = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.getCurrentRoute();
96
- const currentViewKey = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.key;
97
- const currentViewName = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.name;
98
-
99
- if (currentViewKey != null && currentViewName != null) {
100
- if (appStateStatus === 'background') {
101
- _mobileReactNative.DdRum.stopView(currentViewKey);
102
- } else if (appStateStatus === 'active') {
103
- // case when app goes into foreground, in that case navigation listener
104
- // won't be called
105
- _mobileReactNative.DdRum.startView(currentViewKey, currentViewName);
106
- }
122
+
123
+ if (currentRoute == undefined) {
124
+ return;
107
125
  }
126
+
127
+ DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
108
128
  }; // AppState is singleton, so we should add a listener only once in the app lifetime
109
129
 
110
130
 
@@ -114,11 +134,13 @@ class DdRumReactNavigationTracking {
114
134
 
115
135
  }
116
136
 
117
- exports.default = DdRumReactNavigationTracking;
137
+ exports.DdRumReactNavigationTracking = DdRumReactNavigationTracking;
118
138
 
119
139
  _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
120
140
 
121
141
  _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
122
142
 
123
143
  _defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
144
+
145
+ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
124
146
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","registeredContainer","console","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","key","screenName","name","DdRum","startView","event","data","state","routes","index","undefined","nestedRoute","appStateListener","appStateStatus","currentRoute","currentViewKey","currentViewName","stopView","AppState","addEventListener"],"mappings":";;;;;;;AAOA;;AACA;;;;AAMA;AACA;AACA;AACe,MAAMA,4BAAN,CAAmC;AAQ9C;AACJ;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f;AACH,WAFD,MAEO,IAAIF,cAAc,KAAK,QAAvB,EAAiC;AACpC;AACA;AACAV,qCAAMC,SAAN,CAAgBW,cAAhB,EAAgCC,eAAhC;AACH;AACJ;AACJ,OAfD,CADuD,CAkBvD;;;AACAE,4BAASC,gBAAT,CAA0B,QAA1B,EAAoCnC,4BAA4B,CAAC4B,gBAAjE;AACH;AACJ;;AA/F6C;;;;gBAA7B5B,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport default class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef == null) {\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n }\n }\n\n private static handleRouteNavigation(route: Route<string, any | undefined> | undefined) {\n const key = route?.key;\n const screenName = route?.name;\n if (key != null && screenName != null) {\n DdRum.startView(key, screenName);\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n const currentViewKey = currentRoute?.key;\n const currentViewName = currentRoute?.name;\n\n if (currentViewKey != null && currentViewName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(currentViewKey);\n } else if (appStateStatus === 'active') {\n // case when app goes into foreground, in that case navigation listener\n // won't be called\n DdRum.startView(currentViewKey, currentViewName);\n }\n }\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","DdRum","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","AppState","addEventListener"],"mappings":";;;;;;;AAOA;;AACA;;;;AAcA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAUtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACjBC,aADiB,EAGb;AAAA,QADJC,iBACI,uEADmC,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,aAAOA,WAAP;AAAqB,KACjI;;AAER,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,MAAAA,OAAO,CAACC,GAAR,CAAa,8CAAb;AACA;AACH;;AAED,QAAIP,4BAA4B,CAACQ,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BN,aAA7F,EAA4G;AACxGI,MAAAA,OAAO,CAACG,KAAR,CAAc,0EAAd;AACH,KAFD,MAEO,IAAIT,4BAA4B,CAACQ,mBAA7B,IAAoD,IAAxD,EAA8D;AACjER,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMO,QAAQ,GAAGV,4BAA4B,CAACW,oCAA7B,EAAjB;AACAX,MAAAA,4BAA4B,CAACY,qBAA7B,CAAmDV,aAAa,CAACW,eAAd,EAAnD;AACAX,MAAAA,aAAa,CAACY,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAV,MAAAA,4BAA4B,CAACQ,mBAA7B,GAAmDN,aAAnD;AACH;;AAGDF,IAAAA,4BAA4B,CAACe,gCAA7B;AACH;AAED;AACJ;AACA;AACA;;;AAC4B,SAAjBC,iBAAiB,CAACd,aAAD,EAAqD;AACzE,QAAIA,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EAA0B,aAAYC,KAAtC,uDAA0B,mBAAmBE,KAA7C,CAAZ;;AAEA,YAAId,KAAK,IAAIE,SAAb,EAAwB;AACpB;AACA;AACH;;AAED,eAAOF,KAAK,CAACY,KAAN,IAAeV,SAAtB,EAAiC;AAC7B,gBAAMa,WAAW,GAAGf,KAAK,CAACY,KAAN,CAAYC,MAAZ,CAAmBb,KAAK,CAACY,KAAN,CAAYE,KAA/B,CAApB;;AACA,cAAIC,WAAW,IAAIb,SAAnB,EAA8B;AAC1B;AACA;AACH;;AACDF,UAAAA,KAAK,GAAGe,WAAR;AACH;;AAEDlC,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDO,KAAnD;AACH,OAlBD;AAmBH;;AACD,WAAOnB,4BAA4B,CAACkB,6BAApC;AACH;;AAE8C,SAAhCH,gCAAgC,GAAG;AAC9C,QAAIf,4BAA4B,CAACmC,gBAA7B,IAAiD,IAArD,EAA2D;AACvDnC,MAAAA,4BAA4B,CAACmC,gBAA7B,GAAiDf,cAAD,IAAoC;AAAA;;AAEhF,cAAMgB,YAAY,4BAAGpC,4BAA4B,CAACQ,mBAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIuB,YAAY,IAAIf,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDwB,YAAnD,EAAiEhB,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACAiB,4BAASC,gBAAT,CAA0B,QAA1B,EAAoCtC,4BAA4B,CAACmC,gBAAjE;AACH;AACJ;;AAlHqC;;;;gBAA7BnC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
@@ -3,6 +3,6 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
- import DdRumReactNavigationTracking from './rum/instrumentation/DdRumReactNavigationTracking';
7
- export { DdRumReactNavigationTracking };
6
+ import { DdRumReactNavigationTracking, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';
7
+ export { DdRumReactNavigationTracking, ViewNamePredicate };
8
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,4BAAP,MAAyC,oDAAzC;AAEA,SAASA,4BAAT","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport DdRumReactNavigationTracking from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking };\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,4BAAT,EAAuCC,iBAAvC,QAAgE,oDAAhE;AAEA,SAASD,4BAAT,EAAuCC,iBAAvC","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRumReactNavigationTracking, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
@@ -11,19 +11,25 @@ import { AppState } from 'react-native';
11
11
  /**
12
12
  * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
13
13
  */
14
- export default class DdRumReactNavigationTracking {
14
+ export class DdRumReactNavigationTracking {
15
15
  /**
16
16
  * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
17
17
  * @param navigationRef the reference to the real NavigationContainer.
18
18
  */
19
19
  static startTrackingViews(navigationRef) {
20
+ let viewNamePredicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_route, trackedName) {
21
+ return trackedName;
22
+ };
23
+
20
24
  if (navigationRef == null) {
25
+ console.log("Cannot track views with a null navigationRef");
21
26
  return;
22
27
  }
23
28
 
24
29
  if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
25
30
  console.error('Cannot track new navigation container while another one is still tracked');
26
31
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
32
+ DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
27
33
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
28
34
  DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
29
35
  navigationRef.addListener("state", listener);
@@ -42,15 +48,35 @@ export default class DdRumReactNavigationTracking {
42
48
  if (navigationRef != null) {
43
49
  navigationRef.removeListener("state", DdRumReactNavigationTracking.navigationStateChangeListener);
44
50
  DdRumReactNavigationTracking.registeredContainer = null;
51
+
52
+ DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
53
+ return trackedName;
54
+ };
45
55
  }
46
56
  }
47
57
 
48
58
  static handleRouteNavigation(route) {
49
- const key = route === null || route === void 0 ? void 0 : route.key;
50
- const screenName = route === null || route === void 0 ? void 0 : route.name;
59
+ var _predicate;
60
+
61
+ let appStateStatus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
62
+
63
+ if (route == undefined || route == null) {
64
+ // RUMM-1400 in some cases the route seem to be undefined
65
+ return;
66
+ }
67
+
68
+ const key = route.key;
69
+ const predicate = DdRumReactNavigationTracking.viewNamePredicate;
70
+ const screenName = (_predicate = predicate(route, route.name)) !== null && _predicate !== void 0 ? _predicate : route.name;
51
71
 
52
72
  if (key != null && screenName != null) {
53
- DdRum.startView(key, screenName);
73
+ if (appStateStatus === 'background') {
74
+ DdRum.stopView(key);
75
+ } else if (appStateStatus === 'active' || appStateStatus == undefined) {
76
+ // case when app goes into foreground,
77
+ // in that case navigation listener won't be called
78
+ DdRum.startView(key, screenName);
79
+ }
54
80
  }
55
81
  }
56
82
 
@@ -90,18 +116,12 @@ export default class DdRumReactNavigationTracking {
90
116
  var _DdRumReactNavigation;
91
117
 
92
118
  const currentRoute = (_DdRumReactNavigation = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.getCurrentRoute();
93
- const currentViewKey = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.key;
94
- const currentViewName = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.name;
95
-
96
- if (currentViewKey != null && currentViewName != null) {
97
- if (appStateStatus === 'background') {
98
- DdRum.stopView(currentViewKey);
99
- } else if (appStateStatus === 'active') {
100
- // case when app goes into foreground, in that case navigation listener
101
- // won't be called
102
- DdRum.startView(currentViewKey, currentViewName);
103
- }
119
+
120
+ if (currentRoute == undefined) {
121
+ return;
104
122
  }
123
+
124
+ DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
105
125
  }; // AppState is singleton, so we should add a listener only once in the app lifetime
106
126
 
107
127
 
@@ -116,4 +136,6 @@ _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
116
136
  _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
117
137
 
118
138
  _defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
139
+
140
+ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
119
141
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","AppState","DdRumReactNavigationTracking","startTrackingViews","navigationRef","registeredContainer","console","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","key","screenName","name","startView","event","data","state","routes","index","undefined","nestedRoute","appStateListener","appStateStatus","currentRoute","currentViewKey","currentViewName","stopView","addEventListener"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,KAAT,QAAsB,8BAAtB;AACA,SAASC,QAAT,QAAyC,cAAzC;;AAMA;AACA;AACA;AACA,eAAe,MAAMC,4BAAN,CAAmC;AAQ9C;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CAACC,aAAD,EAAqD;AAC1E,QAAIA,aAAa,IAAI,IAArB,EAA2B;AACvB;AACH;;AAED,QAAIF,4BAA4B,CAACG,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BD,aAA7F,EAA4G;AACxGE,MAAAA,OAAO,CAACC,KAAR,CAAc,0EAAd;AACH,KAFD,MAEO,IAAIL,4BAA4B,CAACG,mBAA7B,IAAoD,IAAxD,EAA8D;AACjE,YAAMG,QAAQ,GAAGN,4BAA4B,CAACO,oCAA7B,EAAjB;AACAP,MAAAA,4BAA4B,CAACQ,qBAA7B,CAAmDN,aAAa,CAACO,eAAd,EAAnD;AACAP,MAAAA,aAAa,CAACQ,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAN,MAAAA,4BAA4B,CAACG,mBAA7B,GAAmDD,aAAnD;AACH;;AAEDF,IAAAA,4BAA4B,CAACW,gCAA7B;AACH;AAED;AACJ;AACA;AACA;;;AAC4B,SAAjBC,iBAAiB,CAACV,aAAD,EAAqD;AACzE,QAAIA,aAAa,IAAI,IAArB,EAA2B;AACvBA,MAAAA,aAAa,CAACW,cAAd,CAA6B,OAA7B,EAAsCb,4BAA4B,CAACc,6BAAnE;AACAd,MAAAA,4BAA4B,CAACG,mBAA7B,GAAmD,IAAnD;AACH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iDC,cAAD,IAAoC;AAAA;;AAEhF,cAAMC,YAAY,4BAAG7B,4BAA4B,CAACG,mBAAhC,0DAAG,sBAAkDM,eAAlD,EAArB;AACA,cAAMqB,cAAc,GAAGD,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAEb,GAArC;AACA,cAAMe,eAAe,GAAGF,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAEX,IAAtC;;AAEA,YAAIY,cAAc,IAAI,IAAlB,IAA0BC,eAAe,IAAI,IAAjD,EAAuD;AACnD,cAAIH,cAAc,KAAK,YAAvB,EAAqC;AACjC9B,YAAAA,KAAK,CAACkC,QAAN,CAAeF,cAAf;AACH,WAFD,MAEO,IAAIF,cAAc,KAAK,QAAvB,EAAiC;AACpC;AACA;AACA9B,YAAAA,KAAK,CAACqB,SAAN,CAAgBW,cAAhB,EAAgCC,eAAhC;AACH;AACJ;AACJ,OAfD,CADuD,CAkBvD;;;AACAhC,MAAAA,QAAQ,CAACkC,gBAAT,CAA0B,QAA1B,EAAoCjC,4BAA4B,CAAC2B,gBAAjE;AACH;AACJ;;AA/F6C;;gBAA7B3B,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport default class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef == null) {\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n }\n }\n\n private static handleRouteNavigation(route: Route<string, any | undefined> | undefined) {\n const key = route?.key;\n const screenName = route?.name;\n if (key != null && screenName != null) {\n DdRum.startView(key, screenName);\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n const currentViewKey = currentRoute?.key;\n const currentViewName = currentRoute?.name;\n\n if (currentViewKey != null && currentViewName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(currentViewKey);\n } else if (appStateStatus === 'active') {\n // case when app goes into foreground, in that case navigation listener\n // won't be called\n DdRum.startView(currentViewKey, currentViewName);\n }\n }\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","AppState","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","addEventListener"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,KAAT,QAAsB,8BAAtB;AACA,SAASC,QAAT,QAAyC,cAAzC;;AAcA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAUtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACjBC,aADiB,EAGb;AAAA,QADJC,iBACI,uEADmC,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,aAAOA,WAAP;AAAqB,KACjI;;AAER,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,MAAAA,OAAO,CAACC,GAAR,CAAa,8CAAb;AACA;AACH;;AAED,QAAIP,4BAA4B,CAACQ,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BN,aAA7F,EAA4G;AACxGI,MAAAA,OAAO,CAACG,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,mBAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIsB,YAAY,IAAId,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDuB,YAAnD,EAAiEf,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACArB,MAAAA,QAAQ,CAACqC,gBAAT,CAA0B,QAA1B,EAAoCpC,4BAA4B,CAACkC,gBAAjE;AACH;AACJ;;AAlHqC;;gBAA7BlC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
@@ -5,8 +5,17 @@ import type { TrackingConsent } from "./TrackingConsent";
5
5
  */
6
6
  export declare class DdSdkReactNative {
7
7
  private static readonly DD_SOURCE_KEY;
8
+ private static readonly DD_SDK_VERSION;
9
+ private static readonly DD_SERVICE_NAME;
8
10
  private static readonly DD_SDK_VERBOSITY_KEY;
9
11
  private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
12
+ private static readonly DD_PROXY_TYPE_KEY;
13
+ private static readonly DD_PROXY_ADDRESS_KEY;
14
+ private static readonly DD_PROXY_PORT_KEY;
15
+ private static readonly DD_PROXY_USERNAME_KEY;
16
+ private static readonly DD_PROXY_PASSWORD_KEY;
17
+ private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY;
18
+ private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
10
19
  private static wasInitialized;
11
20
  /**
12
21
  * Initializes the Datadog SDK.
@@ -1,5 +1,6 @@
1
1
  import { TrackingConsent } from './TrackingConsent';
2
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
2
+ import type { SdkVerbosity } from './SdkVerbosity';
3
+ import type { ProxyConfiguration } from './ProxyConfiguration';
3
4
  /**
4
5
  * The SDK configuration class.
5
6
  * It will be used to configure the SDK functionality at initialization.
@@ -15,8 +16,10 @@ export declare class DdSdkReactNativeConfiguration {
15
16
  nativeCrashReportEnabled: boolean;
16
17
  sampleRate: number;
17
18
  site: string;
18
- verbosity: NativeSdkVerbosity | undefined;
19
+ verbosity: SdkVerbosity | undefined;
19
20
  nativeViewTracking: boolean;
21
+ proxyConfig?: ProxyConfiguration;
22
+ serviceName?: string;
20
23
  additionalConfig: {
21
24
  [k: string]: any;
22
25
  };
@@ -0,0 +1,6 @@
1
+ import { SdkVerbosity } from './SdkVerbosity';
2
+ export declare class InternalLog {
3
+ private static levelMap;
4
+ static verbosity: SdkVerbosity | undefined;
5
+ static log(message: string, verbosity: SdkVerbosity): void;
6
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Proxy server configuration.
3
+ */
4
+ declare class ProxyConfiguration {
5
+ /**
6
+ * Proxy type.
7
+ */
8
+ readonly type: ProxyType;
9
+ /**
10
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
11
+ */
12
+ readonly address: string;
13
+ /**
14
+ * Proxy port.
15
+ */
16
+ readonly port: number;
17
+ /**
18
+ * Username for Basic authentication scheme.
19
+ *
20
+ * Note: "SOCKS + authentication" scheme is not supported.
21
+ */
22
+ readonly username?: string | undefined;
23
+ /**
24
+ * Password for Basic authentication scheme.
25
+ */
26
+ readonly password?: string | undefined;
27
+ constructor(
28
+ /**
29
+ * Proxy type.
30
+ */
31
+ type: ProxyType,
32
+ /**
33
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
34
+ */
35
+ address: string,
36
+ /**
37
+ * Proxy port.
38
+ */
39
+ port: number,
40
+ /**
41
+ * Username for Basic authentication scheme.
42
+ *
43
+ * Note: "SOCKS + authentication" scheme is not supported.
44
+ */
45
+ username?: string | undefined,
46
+ /**
47
+ * Password for Basic authentication scheme.
48
+ */
49
+ password?: string | undefined);
50
+ }
51
+ declare enum ProxyType {
52
+ HTTP = "http",
53
+ HTTPS = "https",
54
+ SOCKS = "socks"
55
+ }
56
+ export { ProxyConfiguration, ProxyType };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Enum specifying possible log levels for DD SDK.
3
+ */
4
+ export declare enum SdkVerbosity {
5
+ DEBUG = "debug",
6
+ INFO = "info",
7
+ WARN = "warn",
8
+ ERROR = "error"
9
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Simple timer which records time ticks. Shouldn't be re-used once stopped.
3
+ * All timestamps/durations returned are in milliseconds.
4
+ */
5
+ export default class Timer {
6
+ private times;
7
+ get startTime(): number;
8
+ get stopTime(): number;
9
+ start(): void;
10
+ stop(): void;
11
+ recordTick(label: string): void;
12
+ hasTickFor(label: string): boolean;
13
+ durationBetween(startLabel: string, endLabel: string): number;
14
+ timeAt(label: string): number;
15
+ reset(): void;
16
+ private durationBetweenTicks;
17
+ private performanceNow;
18
+ private canUsePerformanceNow;
19
+ private checkLabelExists;
20
+ }
@@ -1,5 +1,7 @@
1
1
  import { DdLogs, DdTrace, DdRum } from './foundation';
2
2
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import { DdSdkReactNative } from './DdSdkReactNative';
4
+ import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
4
5
  import { TrackingConsent } from './TrackingConsent';
5
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, TrackingConsent };
6
+ import { SdkVerbosity } from './SdkVerbosity';
7
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export declare class DdRumErrorTracking {
5
5
  private static isTracking;
6
+ private static isInDefaultErrorHandler;
6
7
  private static defaultErrorHandler;
7
8
  private static defaultConsoleError;
8
9
  /**
@@ -11,5 +12,6 @@ export declare class DdRumErrorTracking {
11
12
  static startTracking(): void;
12
13
  static onGlobalError(error: any, isFatal?: boolean): void;
13
14
  static onConsoleError(...params: unknown[]): void;
15
+ private static getErrorMessage;
14
16
  private static getErrorStackTrace;
15
17
  }
@@ -1,7 +1,11 @@
1
+ /// <reference types="react-native" />
1
2
  export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
2
3
  export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
3
4
  export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
5
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
6
+ export declare const SAMPLED_HEADER_KEY = "x-datadog-sampled";
4
7
  export declare const ORIGIN_RUM = "rum";
8
+ export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
5
9
  /**
6
10
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
7
11
  */
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react-native" />
2
+ import type Timer from "../../Timer";
2
3
  export interface DdRumXhr extends XMLHttpRequest {
3
4
  _datadog_xhr: DdRumXhrContext;
4
5
  }
5
6
  export interface DdRumXhrContext {
6
7
  method: string;
7
8
  url: string;
8
- startTime: number;
9
- responseStartTime: number;
10
9
  reported: boolean;
10
+ timer: Timer;
11
11
  spanId: string;
12
12
  traceId: string;
13
13
  }
@@ -74,14 +74,14 @@ export declare type DdTraceType = {
74
74
  * Start a span, and returns a unique identifier for the span.
75
75
  * @param operation: The operation name of the span.
76
76
  * @param context: The additional context to send.
77
- * @param timestampMs: The timestamp when the operation started (in milliseconds).
77
+ * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
78
78
  */
79
79
  startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
80
80
  /**
81
81
  * Finish a started span.
82
82
  * @param spanId: The unique identifier of the span.
83
83
  * @param context: The additional context to send.
84
- * @param timestampMs: The timestamp when the operation stopped (in milliseconds).
84
+ * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
85
85
  */
86
86
  finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
87
87
  };
@@ -94,14 +94,14 @@ export declare type DdRumType = {
94
94
  * @param key: The view unique key identifier.
95
95
  * @param name: The view name.
96
96
  * @param context: The additional context to send.
97
- * @param timestampMs: The timestamp when the view started (in milliseconds).
97
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
98
98
  */
99
99
  startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
100
100
  /**
101
101
  * Stop tracking a RUM View.
102
102
  * @param key: The view unique key identifier.
103
103
  * @param context: The additional context to send.
104
- * @param timestampMs: The timestamp when the view stopped (in milliseconds).
104
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
105
105
  */
106
106
  stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
107
107
  /**
@@ -109,13 +109,13 @@ export declare type DdRumType = {
109
109
  * @param type: The action type (tap, scroll, swipe, click, custom).
110
110
  * @param name: The action name.
111
111
  * @param context: The additional context to send.
112
- * @param timestampMs: The timestamp when the action started (in milliseconds).
112
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
113
113
  */
114
114
  startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
115
115
  /**
116
116
  * Stop tracking the ongoing RUM Action.
117
117
  * @param context: The additional context to send.
118
- * @param timestampMs: The timestamp when the action stopped (in milliseconds).
118
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
119
119
  */
120
120
  stopAction(context?: object, timestampMs?: number): Promise<void>;
121
121
  /**
@@ -123,7 +123,7 @@ export declare type DdRumType = {
123
123
  * @param type: The action type (tap, scroll, swipe, click, custom).
124
124
  * @param name: The action name.
125
125
  * @param context: The additional context to send.
126
- * @param timestampMs: The timestamp when the action occurred (in milliseconds).
126
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
127
127
  */
128
128
  addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
129
129
  /**
@@ -132,7 +132,7 @@ export declare type DdRumType = {
132
132
  * @param method: The resource method (GET, POST, …).
133
133
  * @param url: The resource url.
134
134
  * @param context: The additional context to send.
135
- * @param timestampMs: The timestamp when the resource started (in milliseconds).
135
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
136
136
  */
137
137
  startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
138
138
  /**
@@ -140,17 +140,18 @@ export declare type DdRumType = {
140
140
  * @param key: The resource unique key identifier.
141
141
  * @param statusCode: The resource status code.
142
142
  * @param kind: The resource's kind (xhr, document, image, css, font, …).
143
+ * @param size: The resource size in bytes. If size is unknown, use -1.
143
144
  * @param context: The additional context to send.
144
- * @param timestampMs: The timestamp when the resource stopped (in milliseconds).
145
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
145
146
  */
146
- stopResource(key: string, statusCode: number, kind: string, context?: object, timestampMs?: number): Promise<void>;
147
+ stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;
147
148
  /**
148
149
  * Add a RUM Error.
149
150
  * @param message: The error message.
150
151
  * @param source: The error source (network, source, console, logger, …).
151
152
  * @param stacktrace: The error stacktrace.
152
153
  * @param context: The additional context to send.
153
- * @param timestampMs: The timestamp when the error occurred (in milliseconds).
154
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
154
155
  */
155
156
  addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
156
157
  /**
@@ -0,0 +1 @@
1
+ export declare const version = "1.0.0-rc5";
@@ -1,2 +1,2 @@
1
- import DdRumReactNavigationTracking from './rum/instrumentation/DdRumReactNavigationTracking';
2
- export { DdRumReactNavigationTracking };
1
+ import { DdRumReactNavigationTracking, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';
2
+ export { DdRumReactNavigationTracking, ViewNamePredicate };
@@ -1,16 +1,18 @@
1
- import type { NavigationContainerRef } from "@react-navigation/native";
1
+ import type { NavigationContainerRef, Route } from "@react-navigation/native";
2
+ export declare type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string;
2
3
  /**
3
4
  * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
4
5
  */
5
- export default class DdRumReactNavigationTracking {
6
+ export declare class DdRumReactNavigationTracking {
6
7
  private static registeredContainer;
7
8
  private static navigationStateChangeListener;
8
9
  private static appStateListener;
10
+ private static viewNamePredicate;
9
11
  /**
10
12
  * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
11
13
  * @param navigationRef the reference to the real NavigationContainer.
12
14
  */
13
- static startTrackingViews(navigationRef: NavigationContainerRef | null): void;
15
+ static startTrackingViews(navigationRef: NavigationContainerRef | null, viewNamePredicate?: ViewNamePredicate): void;
14
16
  /**
15
17
  * Stops tracking the NavigationContainer.
16
18
  * @param navigationRef the reference to the real NavigationContainer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.0.0-rc2",
3
+ "version": "1.0.0-rc5",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -36,7 +36,7 @@
36
36
  "prepare": "bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.0.0-rc2",
39
+ "@datadog/mobile-react-native": "^1.0.0-rc5",
40
40
  "@react-navigation/native": "5.9.2",
41
41
  "@react-navigation/stack": "5.14.2",
42
42
  "react-native-gesture-handler": "1.10.3",
@@ -46,7 +46,7 @@
46
46
  "@datadog/mobile-react-native": "^1.0.0-beta4",
47
47
  "@react-navigation/native": "^5.6.0",
48
48
  "react": ">=16.13.1",
49
- "react-native": "^0.63.4"
49
+ "react-native": ">=0.63.4 <1.0"
50
50
  },
51
51
  "jest": {
52
52
  "preset": "react-native",
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  ]
74
74
  },
75
- "gitHead": "ed6e0566e2096406ba393ecd03ba8ac964ba8b9b"
75
+ "gitHead": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
76
76
  }
@@ -6,9 +6,9 @@
6
6
 
7
7
  import React from 'react';
8
8
  import { View, Text, Button, AppState } from 'react-native';
9
- import { NavigationContainer, NavigationContainerRef } from '@react-navigation/native';
9
+ import { NavigationContainer, NavigationContainerRef, Route } from '@react-navigation/native';
10
10
  import { DdRum } from '@datadog/mobile-react-native';
11
- import DdRumReactNavigationTracking from '../../../rum/instrumentation/DdRumReactNavigationTracking';
11
+ import { DdRumReactNavigationTracking, ViewNamePredicate} from '../../../rum/instrumentation/DdRumReactNavigationTracking';
12
12
  import { render, fireEvent } from '@testing-library/react-native';
13
13
  import { createStackNavigator } from '@react-navigation/stack';
14
14
 
@@ -42,20 +42,32 @@ const navigationRef3: React.RefObject<NavigationContainerRef> = React.createRef(
42
42
  jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
43
43
  jest.useFakeTimers();
44
44
 
45
+ let baseConsoleErrorCalled = false;
46
+ let baseConsoleError = (...params: unknown) => {
47
+ baseConsoleErrorCalled = true
48
+ }
49
+ let originalConsoleError = undefined
45
50
 
46
51
  beforeEach(() => {
47
-
52
+
48
53
  jest.setTimeout(20000);
49
54
  DdRum.startView.mockClear();
50
55
  DdRum.stopView.mockClear();
51
56
  AppState.addEventListener.mockClear();
52
57
  AppState.removeEventListener.mockClear();
58
+ baseConsoleErrorCalled = false;
59
+ originalConsoleError = console.error;
60
+ console.error = baseConsoleError;
53
61
 
54
62
  DdRumReactNavigationTracking.registeredContainer = null;
55
63
  DdRumReactNavigationTracking.navigationStateChangeListener = null;
56
64
  DdRumReactNavigationTracking.appStateListener = null;
57
65
  })
58
66
 
67
+ afterEach(() => {
68
+ console.error = originalConsoleError
69
+ })
70
+
59
71
  // Unit tests
60
72
 
61
73
  it('M send a RUM ViewEvent W startTrackingViews', async () => {
@@ -91,6 +103,27 @@ it('M send a related RUM ViewEvent W switching screens { navigationContainer lis
91
103
  expect(DdRum.startView.mock.calls[1][2]).toBeUndefined();
92
104
  })
93
105
 
106
+ it('M send a related RUM ViewEvent W switching screens { viewPredicate provided }', async () => {
107
+ // GIVEN
108
+ const { getByText } = render(<FakeNavigator1 />);
109
+ const goToAboutButton = getByText('Go to About');
110
+ const customViewName = "custom_view_name"
111
+ const predicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, _trackedName: string) {
112
+ return customViewName
113
+ };
114
+ DdRumReactNavigationTracking.startTrackingViews(navigationRef1.current, predicate);
115
+
116
+ // WHEN
117
+ expect(goToAboutButton).toBeTruthy();
118
+ fireEvent(goToAboutButton, "press");
119
+
120
+ // THEN
121
+ expect(DdRum.startView.mock.calls.length).toBe(2);
122
+ expect(DdRum.startView.mock.calls[1][0]).toBe(navigationRef1.current?.getCurrentRoute()?.key);
123
+ expect(DdRum.startView.mock.calls[1][1]).toBe(customViewName);
124
+ expect(DdRum.startView.mock.calls[1][2]).toBeUndefined();
125
+ })
126
+
94
127
  it('M only register once W startTrackingViews{ multiple times }', async () => {
95
128
 
96
129
  // GIVEN
@@ -157,6 +190,7 @@ it('M send a RUM ViewEvent for each W startTrackingViews { multiple navigation c
157
190
  expect(DdRum.startView.mock.calls[1][0]).toBe(navigationRef1.current?.getCurrentRoute()?.key);
158
191
  expect(DdRum.startView.mock.calls[1][1]).toBe(navigationRef1.current?.getCurrentRoute()?.name);
159
192
  expect(DdRum.startView.mock.calls[1][2]).toBeUndefined();
193
+ expect(baseConsoleErrorCalled).toBe(true);
160
194
  })
161
195
 
162
196
  it('M send a RUM ViewEvent for each W startTrackingViews { multiple navigation containers w first is detached }', async () => {
@@ -206,6 +240,7 @@ it('M send a RUM ViewEvent for each W switching screens { multiple navigation co
206
240
  expect(DdRum.startView.mock.calls[0][0]).toBe(navigationRef1.current?.getCurrentRoute()?.key);
207
241
  expect(DdRum.startView.mock.calls[0][1]).toBe(navigationRef1.current?.getCurrentRoute()?.name);
208
242
  expect(DdRum.startView.mock.calls[0][2]).toBeUndefined();
243
+ expect(baseConsoleErrorCalled).toBe(true);
209
244
  })
210
245
 
211
246
  it('M register AppState listener only once', async () => {
package/src/index.tsx CHANGED
@@ -4,6 +4,6 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import DdRumReactNavigationTracking from './rum/instrumentation/DdRumReactNavigationTracking';
7
+ import { DdRumReactNavigationTracking, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';
8
8
 
9
- export { DdRumReactNavigationTracking };
9
+ export { DdRumReactNavigationTracking, ViewNamePredicate };
@@ -10,12 +10,20 @@ import { AppState, AppStateStatus } from 'react-native';
10
10
 
11
11
  declare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null
12
12
 
13
+ // AppStateStatus can have values:
14
+ // 'active' - The app is running in the foreground
15
+ // 'background' - The app is running in the background. The user is either in another app or on the home screen
16
+ // 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.
17
+ // 'unknown' [iOS] - Initial value until the current app state is determined
18
+ // 'extension' [iOS] - The app is running as an app extension
13
19
  declare type AppStateListener = (appStateStatus: AppStateStatus) => void | null
14
20
 
21
+ export type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string
22
+
15
23
  /**
16
24
  * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
17
25
  */
18
- export default class DdRumReactNavigationTracking {
26
+ export class DdRumReactNavigationTracking {
19
27
 
20
28
  private static registeredContainer: NavigationContainerRef | null;
21
29
 
@@ -23,24 +31,33 @@ export default class DdRumReactNavigationTracking {
23
31
 
24
32
  private static appStateListener: AppStateListener;
25
33
 
34
+ private static viewNamePredicate: ViewNamePredicate;
35
+
26
36
  /**
27
37
  * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
28
38
  * @param navigationRef the reference to the real NavigationContainer.
29
39
  */
30
- static startTrackingViews(navigationRef: NavigationContainerRef | null): void {
40
+ static startTrackingViews(
41
+ navigationRef: NavigationContainerRef | null,
42
+ viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }
43
+ ): void {
44
+
31
45
  if (navigationRef == null) {
46
+ console.log ("Cannot track views with a null navigationRef");
32
47
  return;
33
48
  }
34
49
 
35
50
  if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
36
51
  console.error('Cannot track new navigation container while another one is still tracked');
37
52
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
53
+ DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
38
54
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
39
55
  DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
40
56
  navigationRef.addListener("state", listener);
41
57
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
42
58
  }
43
59
 
60
+
44
61
  DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
45
62
  }
46
63
 
@@ -52,14 +69,31 @@ export default class DdRumReactNavigationTracking {
52
69
  if (navigationRef != null) {
53
70
  navigationRef.removeListener("state", DdRumReactNavigationTracking.navigationStateChangeListener);
54
71
  DdRumReactNavigationTracking.registeredContainer = null;
72
+ DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }
55
73
  }
56
74
  }
57
75
 
58
- private static handleRouteNavigation(route: Route<string, any | undefined> | undefined) {
59
- const key = route?.key;
60
- const screenName = route?.name;
76
+ private static handleRouteNavigation(
77
+ route: Route<string, any | undefined> | undefined,
78
+ appStateStatus: AppStateStatus | undefined = undefined
79
+ ) {
80
+ if (route == undefined || route == null) {
81
+ // RUMM-1400 in some cases the route seem to be undefined
82
+ return
83
+ }
84
+ const key = route.key;
85
+
86
+ const predicate = DdRumReactNavigationTracking.viewNamePredicate;
87
+ const screenName = predicate(route, route.name) ?? route.name;
88
+
61
89
  if (key != null && screenName != null) {
62
- DdRum.startView(key, screenName);
90
+ if (appStateStatus === 'background') {
91
+ DdRum.stopView(key);
92
+ } else if (appStateStatus === 'active' || appStateStatus == undefined) {
93
+ // case when app goes into foreground,
94
+ // in that case navigation listener won't be called
95
+ DdRum.startView(key, screenName);
96
+ }
63
97
  }
64
98
  }
65
99
 
@@ -93,18 +127,11 @@ export default class DdRumReactNavigationTracking {
93
127
  DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {
94
128
 
95
129
  const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();
96
- const currentViewKey = currentRoute?.key;
97
- const currentViewName = currentRoute?.name;
98
-
99
- if (currentViewKey != null && currentViewName != null) {
100
- if (appStateStatus === 'background') {
101
- DdRum.stopView(currentViewKey);
102
- } else if (appStateStatus === 'active') {
103
- // case when app goes into foreground, in that case navigation listener
104
- // won't be called
105
- DdRum.startView(currentViewKey, currentViewName);
106
- }
130
+ if (currentRoute == undefined) {
131
+ return;
107
132
  }
133
+
134
+ DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
108
135
  };
109
136
 
110
137
  // AppState is singleton, so we should add a listener only once in the app lifetime
@@ -1,9 +0,0 @@
1
- /**
2
- * Enum specifying possible consent options for DD SDK.
3
- */
4
- export declare enum NativeSdkVerbosity {
5
- DEBUG = "debug",
6
- INFO = "info",
7
- WARN = "warn",
8
- ERROR = "error"
9
- }