@datadog/mobile-react-navigation 1.0.0-rc4 → 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.
@@ -19,9 +19,11 @@ class DdRumReactNavigationTracking {
19
19
  * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
20
20
  * @param navigationRef the reference to the real NavigationContainer.
21
21
  */
22
- static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
23
- return trackedName;
24
- }) {
22
+ static startTrackingViews(navigationRef) {
23
+ let viewNamePredicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_route, trackedName) {
24
+ return trackedName;
25
+ };
26
+
25
27
  if (navigationRef == null) {
26
28
  console.log("Cannot track views with a null navigationRef");
27
29
  return;
@@ -56,9 +58,11 @@ class DdRumReactNavigationTracking {
56
58
  }
57
59
  }
58
60
 
59
- static handleRouteNavigation(route, appStateStatus = undefined) {
61
+ static handleRouteNavigation(route) {
60
62
  var _predicate;
61
63
 
64
+ let appStateStatus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
65
+
62
66
  if (route == undefined || route == null) {
63
67
  // RUMM-1400 in some cases the route seem to be undefined
64
68
  return;
@@ -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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;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"]}
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,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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"]}
@@ -16,9 +16,11 @@ export class DdRumReactNavigationTracking {
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
- static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
20
- return trackedName;
21
- }) {
19
+ static startTrackingViews(navigationRef) {
20
+ let viewNamePredicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_route, trackedName) {
21
+ return trackedName;
22
+ };
23
+
22
24
  if (navigationRef == null) {
23
25
  console.log("Cannot track views with a null navigationRef");
24
26
  return;
@@ -53,9 +55,11 @@ export class DdRumReactNavigationTracking {
53
55
  }
54
56
  }
55
57
 
56
- static handleRouteNavigation(route, appStateStatus = undefined) {
58
+ static handleRouteNavigation(route) {
57
59
  var _predicate;
58
60
 
61
+ let appStateStatus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
62
+
59
63
  if (route == undefined || route == null) {
60
64
  // RUMM-1400 in some cases the route seem to be undefined
61
65
  return;
@@ -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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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"]}
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,QAAI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H;;AAE8C,SAAhCH,gCAAgC,GAAG;AAC9C,QAAIf,4BAA4B,CAACkC,gBAA7B,IAAiD,IAArD,EAA2D;AACvDlC,MAAAA,4BAA4B,CAACkC,gBAA7B,GAAiDd,cAAD,IAAoC;AAAA;;AAEhF,cAAMe,YAAY,4BAAGnC,4BAA4B,CAACQ,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"]}
@@ -1,5 +1,5 @@
1
1
  import { TrackingConsent } from './TrackingConsent';
2
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
2
+ import type { SdkVerbosity } from './SdkVerbosity';
3
3
  import type { ProxyConfiguration } from './ProxyConfiguration';
4
4
  /**
5
5
  * The SDK configuration class.
@@ -16,7 +16,7 @@ export declare class DdSdkReactNativeConfiguration {
16
16
  nativeCrashReportEnabled: boolean;
17
17
  sampleRate: number;
18
18
  site: string;
19
- verbosity: NativeSdkVerbosity | undefined;
19
+ verbosity: SdkVerbosity | undefined;
20
20
  nativeViewTracking: boolean;
21
21
  proxyConfig?: ProxyConfiguration;
22
22
  serviceName?: string;
@@ -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,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
+ }
@@ -3,4 +3,5 @@ import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import { DdSdkReactNative } from './DdSdkReactNative';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
5
5
  import { TrackingConsent } from './TrackingConsent';
6
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent };
6
+ import { SdkVerbosity } from './SdkVerbosity';
7
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc4";
1
+ export declare const version = "1.0.0-rc5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.0.0-rc4",
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-rc4",
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",
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  ]
74
74
  },
75
- "gitHead": "c1bd4e6ded0b84298ca011eba679027ae7fe7841"
75
+ "gitHead": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
76
76
  }
@@ -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 () => {
@@ -96,8 +108,8 @@ it('M send a related RUM ViewEvent W switching screens { viewPredicate provided
96
108
  const { getByText } = render(<FakeNavigator1 />);
97
109
  const goToAboutButton = getByText('Go to About');
98
110
  const customViewName = "custom_view_name"
99
- const predicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, _trackedName: string) {
100
- return customViewName
111
+ const predicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, _trackedName: string) {
112
+ return customViewName
101
113
  };
102
114
  DdRumReactNavigationTracking.startTrackingViews(navigationRef1.current, predicate);
103
115
 
@@ -178,6 +190,7 @@ it('M send a RUM ViewEvent for each W startTrackingViews { multiple navigation c
178
190
  expect(DdRum.startView.mock.calls[1][0]).toBe(navigationRef1.current?.getCurrentRoute()?.key);
179
191
  expect(DdRum.startView.mock.calls[1][1]).toBe(navigationRef1.current?.getCurrentRoute()?.name);
180
192
  expect(DdRum.startView.mock.calls[1][2]).toBeUndefined();
193
+ expect(baseConsoleErrorCalled).toBe(true);
181
194
  })
182
195
 
183
196
  it('M send a RUM ViewEvent for each W startTrackingViews { multiple navigation containers w first is detached }', async () => {
@@ -227,6 +240,7 @@ it('M send a RUM ViewEvent for each W switching screens { multiple navigation co
227
240
  expect(DdRum.startView.mock.calls[0][0]).toBe(navigationRef1.current?.getCurrentRoute()?.key);
228
241
  expect(DdRum.startView.mock.calls[0][1]).toBe(navigationRef1.current?.getCurrentRoute()?.name);
229
242
  expect(DdRum.startView.mock.calls[0][2]).toBeUndefined();
243
+ expect(baseConsoleErrorCalled).toBe(true);
230
244
  })
231
245
 
232
246
  it('M register AppState listener only once', async () => {
@@ -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
- }