@datadog/mobile-react-navigation 1.0.0-rc4 → 1.0.0-rc8

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 (36) hide show
  1. package/lib/commonjs/index.js.map +1 -1
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +67 -44
  3. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  4. package/lib/commonjs/rum/instrumentation/react-navigation.js +2 -0
  5. package/lib/commonjs/rum/instrumentation/react-navigation.js.map +1 -0
  6. package/lib/module/index.js.map +1 -1
  7. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +63 -45
  8. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  9. package/lib/module/rum/instrumentation/react-navigation.js +2 -0
  10. package/lib/module/rum/instrumentation/react-navigation.js.map +1 -0
  11. package/lib/typescript/core/src/DdSdkReactNative.d.ts +6 -6
  12. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +16 -4
  13. package/lib/typescript/core/src/InternalLog.d.ts +11 -0
  14. package/lib/typescript/core/src/SdkVerbosity.d.ts +9 -0
  15. package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
  16. package/lib/typescript/core/src/Timer.d.ts +3 -2
  17. package/lib/typescript/core/src/index.d.ts +4 -2
  18. package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  19. package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  20. package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +19 -9
  21. package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  22. package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +13 -3
  23. package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  24. package/lib/typescript/core/src/rum/instrumentation/URLHostParser.d.ts +6 -0
  25. package/lib/typescript/core/src/version.d.ts +1 -1
  26. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +8 -3
  27. package/lib/typescript/react-navigation/src/rum/instrumentation/react-navigation.d.ts +116 -0
  28. package/package.json +11 -6
  29. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +467 -370
  30. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +56 -0
  31. package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV5.tsx +105 -0
  32. package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV6.tsx +105 -0
  33. package/src/index.tsx +4 -1
  34. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +136 -64
  35. package/src/rum/instrumentation/react-navigation.ts +158 -0
  36. package/lib/typescript/core/src/NativeSdkVerbosity.d.ts +0 -9
@@ -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, ViewNamePredicate } from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\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 {\n DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
@@ -23,21 +23,23 @@ class DdRumReactNavigationTracking {
23
23
  return trackedName;
24
24
  }) {
25
25
  if (navigationRef == null) {
26
- console.log("Cannot track views with a null navigationRef");
26
+ _mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
27
+
27
28
  return;
28
29
  }
29
30
 
30
31
  if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
31
- console.error('Cannot track new navigation container while another one is still tracked');
32
+ _mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
32
33
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
33
34
  DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
34
35
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
35
36
  DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
36
- navigationRef.addListener("state", listener);
37
+ navigationRef.addListener('state', listener);
37
38
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
38
- }
39
+ DdRumReactNavigationTracking.backHandler = _reactNative.BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
39
40
 
40
- DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
41
+ _reactNative.AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
42
+ }
41
43
  }
42
44
  /**
43
45
  * Stops tracking the NavigationContainer.
@@ -47,20 +49,28 @@ class DdRumReactNavigationTracking {
47
49
 
48
50
  static stopTrackingViews(navigationRef) {
49
51
  if (navigationRef != null) {
50
- navigationRef.removeListener("state", DdRumReactNavigationTracking.navigationStateChangeListener);
52
+ var _DdRumReactNavigation;
53
+
54
+ navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
55
+ (_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
56
+ DdRumReactNavigationTracking.backHandler = null;
51
57
  DdRumReactNavigationTracking.registeredContainer = null;
52
58
 
53
59
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
54
60
  return trackedName;
55
61
  };
56
62
  }
63
+
64
+ _reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
57
65
  }
58
66
 
59
67
  static handleRouteNavigation(route, appStateStatus = undefined) {
60
68
  var _predicate;
61
69
 
62
- if (route == undefined || route == null) {
63
- // RUMM-1400 in some cases the route seem to be undefined
70
+ if (route === undefined || route === null) {
71
+ _mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
72
+
73
+
64
74
  return;
65
75
  }
66
76
 
@@ -71,8 +81,8 @@ class DdRumReactNavigationTracking {
71
81
  if (key != null && screenName != null) {
72
82
  if (appStateStatus === 'background') {
73
83
  _mobileReactNative.DdRum.stopView(key);
74
- } else if (appStateStatus === 'active' || appStateStatus == undefined) {
75
- // case when app goes into foreground,
84
+ } else if (appStateStatus === 'active' || appStateStatus === undefined) {
85
+ // case when app goes into foreground,
76
86
  // in that case navigation listener won't be called
77
87
  _mobileReactNative.DdRum.startView(key, screenName);
78
88
  }
@@ -81,25 +91,15 @@ class DdRumReactNavigationTracking {
81
91
 
82
92
  static resolveNavigationStateChangeListener() {
83
93
  if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
84
- DdRumReactNavigationTracking.navigationStateChangeListener = event => {
85
- var _event$data, _event$data$state, _event$data2, _event$data2$state;
86
-
87
- let route = (_event$data = event.data) === null || _event$data === void 0 ? void 0 : (_event$data$state = _event$data.state) === null || _event$data$state === void 0 ? void 0 : _event$data$state.routes[(_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : (_event$data2$state = _event$data2.state) === null || _event$data2$state === void 0 ? void 0 : _event$data2$state.index];
94
+ DdRumReactNavigationTracking.navigationStateChangeListener = () => {
95
+ var _DdRumReactNavigation2;
88
96
 
89
- if (route == undefined) {
90
- // RUMM-1400 in some cases the route seem to be undefined
91
- return;
92
- }
97
+ const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
93
98
 
94
- while (route.state != undefined) {
95
- const nestedRoute = route.state.routes[route.state.index];
99
+ if (route === undefined) {
100
+ _mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN);
96
101
 
97
- if (nestedRoute == undefined) {
98
- // RUMM-1400 in some cases the route seem to be undefined
99
- break;
100
- }
101
-
102
- route = nestedRoute;
102
+ return;
103
103
  }
104
104
 
105
105
  DdRumReactNavigationTracking.handleRouteNavigation(route);
@@ -109,34 +109,57 @@ class DdRumReactNavigationTracking {
109
109
  return DdRumReactNavigationTracking.navigationStateChangeListener;
110
110
  }
111
111
 
112
- static registerAppStateListenerIfNeeded() {
113
- if (DdRumReactNavigationTracking.appStateListener == null) {
114
- DdRumReactNavigationTracking.appStateListener = appStateStatus => {
115
- var _DdRumReactNavigation;
112
+ }
116
113
 
117
- const currentRoute = (_DdRumReactNavigation = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.getCurrentRoute();
114
+ exports.DdRumReactNavigationTracking = DdRumReactNavigationTracking;
118
115
 
119
- if (currentRoute == undefined) {
120
- return;
121
- }
116
+ _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
117
+
118
+ _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
122
119
 
123
- DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
124
- }; // AppState is singleton, so we should add a listener only once in the app lifetime
120
+ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
125
121
 
122
+ _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
126
123
 
127
- _reactNative.AppState.addEventListener("change", DdRumReactNavigationTracking.appStateListener);
128
- }
124
+ _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
125
+
126
+ _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
127
+
128
+ _defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
129
+
130
+ _defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
131
+ if (DdRumReactNavigationTracking.registeredContainer === null) {
132
+ return false;
129
133
  }
130
134
 
131
- }
135
+ if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
136
+ return false;
137
+ }
132
138
 
133
- exports.DdRumReactNavigationTracking = DdRumReactNavigationTracking;
139
+ return true;
140
+ });
134
141
 
135
- _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
142
+ _defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
143
+ if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
144
+ DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
145
+ } // We always return false so we make sure the react-navigation callback is called.
146
+ // See https://reactnative.dev/docs/backhandler
136
147
 
137
- _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
138
148
 
139
- _defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
149
+ return false;
150
+ });
140
151
 
141
- _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
152
+ _defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
153
+ var _DdRumReactNavigation3;
154
+
155
+ const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
156
+
157
+ if (currentRoute === undefined || currentRoute === null) {
158
+ _mobileReactNative.InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, _mobileReactNative.SdkVerbosity.ERROR);
159
+
160
+ return;
161
+ }
162
+
163
+ DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
164
+ });
142
165
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
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,EAEjBC,iBAAoC,GAAG,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,WAAOA,WAAP;AAAqB,GAFpH,EAGb;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,MAAA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wB,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"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","InternalLog","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","SdkVerbosity","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","BackHandler","addEventListener","onBackPress","AppState","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","DdRum","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAqCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CA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AACH,OAZD;AAaH;;AACD,WAAO7B,4BAA4B,CAAC0B,6BAApC;AACH;;AAnKqC;;;;gBAA7B1B,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAUL,gG;;gBAVKA,4B,uCAYL,+C;;gBAZKA,4B,yCAcL,6K;;gBAdKA,4B,6BAgBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACW,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIX,4BAA4B,CAACW,mBAA7B,CAAiD8B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBAxBQzC,4B,iBA0BY,MAAM;AACvB,MAAIA,4BAA4B,CAAC0C,uBAA7B,EAAJ,EAA4D;AACxD1C,IAAAA,4BAA4B,CAACwB,iBAA7B,CACIxB,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQX,4B,sBAsKL8B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAG3C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI2B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDrC,mCAAYC,GAAZ,CACK,4EAA2EuB,cAAe,gDAD/F,EAEIrB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI4B,YADJ,EAEIb,cAFJ;AAIH,C","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 { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\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 = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\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 (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\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 InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\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 (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\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 (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=react-navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1 +1 @@
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"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SACIA,4BADJ,EAEIC,iBAFJ,QAGO,oDAHP;AAKA,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 {\n DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
@@ -5,8 +5,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
5
5
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
- import { DdRum } from '@datadog/mobile-react-native';
9
- import { AppState } from 'react-native';
8
+ import { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';
9
+ import { AppState, BackHandler } from 'react-native';
10
10
 
11
11
  /**
12
12
  * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
@@ -20,21 +20,21 @@ export class DdRumReactNavigationTracking {
20
20
  return trackedName;
21
21
  }) {
22
22
  if (navigationRef == null) {
23
- console.log("Cannot track views with a null navigationRef");
23
+ InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, SdkVerbosity.ERROR);
24
24
  return;
25
25
  }
26
26
 
27
27
  if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
28
- console.error('Cannot track new navigation container while another one is still tracked');
28
+ InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, SdkVerbosity.ERROR);
29
29
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
30
30
  DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
31
31
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
32
32
  DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
33
- navigationRef.addListener("state", listener);
33
+ navigationRef.addListener('state', listener);
34
34
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
35
+ DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
36
+ AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
35
37
  }
36
-
37
- DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
38
38
  }
39
39
  /**
40
40
  * Stops tracking the NavigationContainer.
@@ -44,20 +44,27 @@ export class DdRumReactNavigationTracking {
44
44
 
45
45
  static stopTrackingViews(navigationRef) {
46
46
  if (navigationRef != null) {
47
- navigationRef.removeListener("state", DdRumReactNavigationTracking.navigationStateChangeListener);
47
+ var _DdRumReactNavigation;
48
+
49
+ navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
50
+ (_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
51
+ DdRumReactNavigationTracking.backHandler = null;
48
52
  DdRumReactNavigationTracking.registeredContainer = null;
49
53
 
50
54
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
51
55
  return trackedName;
52
56
  };
53
57
  }
58
+
59
+ AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
54
60
  }
55
61
 
56
62
  static handleRouteNavigation(route, appStateStatus = undefined) {
57
63
  var _predicate;
58
64
 
59
- if (route == undefined || route == null) {
60
- // RUMM-1400 in some cases the route seem to be undefined
65
+ if (route === undefined || route === null) {
66
+ InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
67
+
61
68
  return;
62
69
  }
63
70
 
@@ -68,8 +75,8 @@ export class DdRumReactNavigationTracking {
68
75
  if (key != null && screenName != null) {
69
76
  if (appStateStatus === 'background') {
70
77
  DdRum.stopView(key);
71
- } else if (appStateStatus === 'active' || appStateStatus == undefined) {
72
- // case when app goes into foreground,
78
+ } else if (appStateStatus === 'active' || appStateStatus === undefined) {
79
+ // case when app goes into foreground,
73
80
  // in that case navigation listener won't be called
74
81
  DdRum.startView(key, screenName);
75
82
  }
@@ -78,27 +85,16 @@ export class DdRumReactNavigationTracking {
78
85
 
79
86
  static resolveNavigationStateChangeListener() {
80
87
  if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
81
- DdRumReactNavigationTracking.navigationStateChangeListener = event => {
82
- var _event$data, _event$data$state, _event$data2, _event$data2$state;
88
+ DdRumReactNavigationTracking.navigationStateChangeListener = () => {
89
+ var _DdRumReactNavigation2;
83
90
 
84
- let route = (_event$data = event.data) === null || _event$data === void 0 ? void 0 : (_event$data$state = _event$data.state) === null || _event$data$state === void 0 ? void 0 : _event$data$state.routes[(_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : (_event$data2$state = _event$data2.state) === null || _event$data2$state === void 0 ? void 0 : _event$data2$state.index];
91
+ const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
85
92
 
86
- if (route == undefined) {
87
- // RUMM-1400 in some cases the route seem to be undefined
93
+ if (route === undefined) {
94
+ InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN);
88
95
  return;
89
96
  }
90
97
 
91
- while (route.state != undefined) {
92
- const nestedRoute = route.state.routes[route.state.index];
93
-
94
- if (nestedRoute == undefined) {
95
- // RUMM-1400 in some cases the route seem to be undefined
96
- break;
97
- }
98
-
99
- route = nestedRoute;
100
- }
101
-
102
98
  DdRumReactNavigationTracking.handleRouteNavigation(route);
103
99
  };
104
100
  }
@@ -106,32 +102,54 @@ export class DdRumReactNavigationTracking {
106
102
  return DdRumReactNavigationTracking.navigationStateChangeListener;
107
103
  }
108
104
 
109
- static registerAppStateListenerIfNeeded() {
110
- if (DdRumReactNavigationTracking.appStateListener == null) {
111
- DdRumReactNavigationTracking.appStateListener = appStateStatus => {
112
- var _DdRumReactNavigation;
105
+ }
113
106
 
114
- const currentRoute = (_DdRumReactNavigation = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.getCurrentRoute();
107
+ _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
115
108
 
116
- if (currentRoute == undefined) {
117
- return;
118
- }
109
+ _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
110
+
111
+ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
119
112
 
120
- DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
121
- }; // AppState is singleton, so we should add a listener only once in the app lifetime
113
+ _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
122
114
 
115
+ _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
123
116
 
124
- AppState.addEventListener("change", DdRumReactNavigationTracking.appStateListener);
125
- }
117
+ _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
118
+
119
+ _defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
120
+
121
+ _defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
122
+ if (DdRumReactNavigationTracking.registeredContainer === null) {
123
+ return false;
126
124
  }
127
125
 
128
- }
126
+ if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
127
+ return false;
128
+ }
129
129
 
130
- _defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
130
+ return true;
131
+ });
131
132
 
132
- _defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
133
+ _defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
134
+ if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
135
+ DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
136
+ } // We always return false so we make sure the react-navigation callback is called.
137
+ // See https://reactnative.dev/docs/backhandler
133
138
 
134
- _defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
135
139
 
136
- _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
140
+ return false;
141
+ });
142
+
143
+ _defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
144
+ var _DdRumReactNavigation3;
145
+
146
+ const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
147
+
148
+ if (currentRoute === undefined || currentRoute === null) {
149
+ InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, SdkVerbosity.ERROR);
150
+ return;
151
+ }
152
+
153
+ DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
154
+ });
137
155
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
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,EAEjBC,iBAAoC,GAAG,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,WAAOA,WAAP;AAAqB,GAFpH,EAGb;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,aA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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"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","SdkVerbosity","InternalLog","AppState","BackHandler","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","addEventListener","onBackPress","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,YAAhB,EAA8BC,WAA9B,QAAiD,8BAAjD;AAEA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,cAAtC;;AAqBA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAqCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBL,MAAAA,WAAW,CAACS,GAAZ,CACIN,4BAA4B,CAACO,iCADjC,EAEIX,YAAY,CAACY,KAFjB;AAIA;AACH;;AAED,QACIR,4BAA4B,CAACS,mBAA7B,IAAoD,IAApD,IACA,KA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nD;AACH,OAZD;AAaH;;AACD,WAAOzB,4BAA4B,CAACsB,6BAApC;AACH;;AAnKqC;;gBAA7BtB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAUL,gG;;gBAVKA,4B,uCAYL,+C;;gBAZKA,4B,yCAcL,6K;;gBAdKA,4B,6BAgBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD2B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBAxBQpC,4B,iBA0BY,MAAM;AACvB,MAAIA,4BAA4B,CAACqC,uBAA7B,EAAJ,EAA4D;AACxDrC,IAAAA,4BAA4B,CAACoB,iBAA7B,CACIpB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQT,4B,sBAsKL0B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGtC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIwB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrDzC,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EoB,cAAe,gDAD/F,EAEI9B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACIyB,YADJ,EAEIZ,cAFJ;AAIH,C","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 { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\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 = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\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 (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\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 InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\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 (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\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 (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=react-navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,5 +1,5 @@
1
- import type { DdSdkReactNativeConfiguration } from "./DdSdkReactNativeConfiguration";
2
- import type { TrackingConsent } from "./TrackingConsent";
1
+ import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
2
+ import type { TrackingConsent } from './TrackingConsent';
3
3
  /**
4
4
  * This class initializes the Datadog SDK, and sets up communication with the server.
5
5
  */
@@ -18,10 +18,10 @@ export declare class DdSdkReactNative {
18
18
  private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
19
19
  private static wasInitialized;
20
20
  /**
21
- * Initializes the Datadog SDK.
22
- * @param configuration the configuration for the SDK library
23
- * @returns a Promise.
24
- */
21
+ * Initializes the Datadog SDK.
22
+ * @param configuration the configuration for the SDK library
23
+ * @returns a Promise.
24
+ */
25
25
  static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
26
26
  /**
27
27
  * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
@@ -1,6 +1,6 @@
1
- import { TrackingConsent } from './TrackingConsent';
2
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
3
1
  import type { ProxyConfiguration } from './ProxyConfiguration';
2
+ import type { SdkVerbosity } from './SdkVerbosity';
3
+ import { TrackingConsent } from './TrackingConsent';
4
4
  /**
5
5
  * The SDK configuration class.
6
6
  * It will be used to configure the SDK functionality at initialization.
@@ -14,12 +14,24 @@ export declare class DdSdkReactNativeConfiguration {
14
14
  readonly trackErrors: boolean;
15
15
  readonly trackingConsent: TrackingConsent;
16
16
  nativeCrashReportEnabled: boolean;
17
- sampleRate: number;
17
+ /**
18
+ * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
19
+ */
20
+ sampleRate?: number;
21
+ /**
22
+ * Percentage of sampled RUM sessions. Range `0`-`100`.
23
+ */
24
+ sessionSamplingRate: number;
25
+ /**
26
+ * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
27
+ */
28
+ resourceTracingSamplingRate: number;
18
29
  site: string;
19
- verbosity: NativeSdkVerbosity | undefined;
30
+ verbosity: SdkVerbosity | undefined;
20
31
  nativeViewTracking: boolean;
21
32
  proxyConfig?: ProxyConfiguration;
22
33
  serviceName?: string;
34
+ firstPartyHosts: string[];
23
35
  additionalConfig: {
24
36
  [k: string]: any;
25
37
  };
@@ -0,0 +1,11 @@
1
+ import { SdkVerbosity } from './SdkVerbosity';
2
+ /**
3
+ * /!\ DO NOT USE THIS IN YOUR APP /!\\
4
+ *
5
+ * This logger is only for debugging the Datadog SDK.
6
+ */
7
+ export declare class InternalLog {
8
+ private static levelMap;
9
+ static verbosity: SdkVerbosity | undefined;
10
+ static log(message: string, verbosity: SdkVerbosity): void;
11
+ }
@@ -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
+ * A Timestamp structure holding the
3
+ */
4
+ export declare type Timestamp = {
5
+ unix: number;
6
+ react_native: number | null;
7
+ };
8
+ /**
9
+ * Simple class providing timestamps in milliseconds.
10
+ * If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
11
+ */
12
+ export declare class TimeProvider {
13
+ private canUsePerformanceNow;
14
+ /** Keeps an average offset between the unix time and the provided timestamp. */
15
+ private baseOffset;
16
+ constructor();
17
+ getTimestamp(): Timestamp;
18
+ now(): number;
19
+ private performanceNow;
20
+ }