@datadog/mobile-react-navigation 1.5.2 → 1.7.0

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 (25) hide show
  1. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +18 -7
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  3. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +18 -7
  4. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  5. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +47 -0
  6. package/lib/typescript/core/src/InternalLog.d.ts +1 -0
  7. package/lib/typescript/core/src/errorUtils.d.ts +2 -0
  8. package/lib/typescript/core/src/index.d.ts +2 -2
  9. package/lib/typescript/core/src/logs/DdLogs.d.ts +13 -5
  10. package/lib/typescript/core/src/logs/eventMapper.d.ts +5 -5
  11. package/lib/typescript/core/src/logs/types.d.ts +34 -8
  12. package/lib/typescript/core/src/nativeModulesTypes.d.ts +51 -4
  13. package/lib/typescript/core/src/rum/DdRum.d.ts +2 -0
  14. package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
  15. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +1 -1
  16. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.d.ts +5 -2
  17. package/lib/typescript/core/src/rum/types.d.ts +4 -0
  18. package/lib/typescript/core/src/types.d.ts +8 -1
  19. package/lib/typescript/core/src/version.d.ts +1 -1
  20. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +1 -0
  21. package/package.json +3 -3
  22. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +39 -1
  23. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +3 -0
  24. package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +3 -0
  25. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +30 -10
@@ -33,7 +33,7 @@ class DdRumReactNavigationTracking {
33
33
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
34
34
  DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
35
35
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
36
- DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
36
+ DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute(), _reactNative.AppState.currentState);
37
37
  navigationRef.addListener('state', listener);
38
38
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
39
39
  DdRumReactNavigationTracking.backHandler = _reactNative.BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
@@ -74,7 +74,7 @@ class DdRumReactNavigationTracking {
74
74
  }
75
75
  }
76
76
 
77
- static handleRouteNavigation(route, appStateStatus = undefined) {
77
+ static handleRouteNavigation(route, appStateStatus) {
78
78
  if (route === undefined || route === null) {
79
79
  _mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
80
80
 
@@ -83,13 +83,24 @@ class DdRumReactNavigationTracking {
83
83
  }
84
84
 
85
85
  const key = route.key;
86
- const predicate = DdRumReactNavigationTracking.viewNamePredicate;
87
- const screenName = predicate(route, route.name);
86
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(route, route.name);
87
+
88
+ if (key != null && screenName != null) {
89
+ // On iOS, the app can start in either "active", "background" or "unknown" state
90
+ if (appStateStatus !== 'background') {
91
+ _mobileReactNative.DdRum.startView(key, screenName);
92
+ }
93
+ }
94
+ }
95
+
96
+ static handleAppStateChanged(route, appStateStatus) {
97
+ const key = route.key;
98
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(route, route.name);
88
99
 
89
100
  if (key != null && screenName != null) {
90
101
  if (appStateStatus === 'background') {
91
102
  _mobileReactNative.DdRum.stopView(key);
92
- } else if (appStateStatus === 'active' || appStateStatus === undefined) {
103
+ } else if (appStateStatus === 'active') {
93
104
  // case when app goes into foreground,
94
105
  // in that case navigation listener won't be called
95
106
  _mobileReactNative.DdRum.startView(key, screenName);
@@ -110,7 +121,7 @@ class DdRumReactNavigationTracking {
110
121
  return;
111
122
  }
112
123
 
113
- DdRumReactNavigationTracking.handleRouteNavigation(route);
124
+ DdRumReactNavigationTracking.handleRouteNavigation(route, _reactNative.AppState.currentState);
114
125
  };
115
126
  }
116
127
 
@@ -170,6 +181,6 @@ _defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus
170
181
  return;
171
182
  }
172
183
 
173
- DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
184
+ DdRumReactNavigationTracking.handleAppStateChanged(currentRoute, appStateStatus);
174
185
  });
175
186
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
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","appStateSubscription","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;AAuCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB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e,gDAD/F,EAEItB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI6B,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 | null;\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 private static appStateSubscription?: NativeEventSubscription;\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 this.appStateSubscription = 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\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n\n // The next if check is important as users can call `stopTrackingViews` before `startTrackingViews`\n // see https://github.com/DataDog/dd-sdk-reactnative/issues/422\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } else if (AppState.removeEventListener) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\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);\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"]}
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","AppState","currentState","addListener","backHandler","BackHandler","addEventListener","onBackPress","appStateSubscription","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","screenName","name","DdRum","startView","handleAppStateChanged","stopView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAuCtC;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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,QAAMa,YAAY,6BAAG7C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI6B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDvC,mCAAYC,GAAZ,CACK,4EAA2EyB,cAAe,gDAD/F,EAEIvB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACyC,qBAA7B,CACII,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 | null;\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 private static appStateSubscription?: NativeEventSubscription;\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 AppState.currentState\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = 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\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n\n // The next if check is important as users can call `stopTrackingViews` before `startTrackingViews`\n // see https://github.com/DataDog/dd-sdk-reactnative/issues/422\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } else if (AppState.removeEventListener) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus\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 const screenName = DdRumReactNavigationTracking.viewNamePredicate(\n route,\n route.name\n );\n\n if (key != null && screenName != null) {\n // On iOS, the app can start in either \"active\", \"background\" or \"unknown\" state\n if (appStateStatus !== 'background') {\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static handleAppStateChanged(\n route: Route<string, any | undefined>,\n appStateStatus: AppStateStatus\n ) {\n const key = route.key;\n const screenName = DdRumReactNavigationTracking.viewNamePredicate(\n route,\n route.name\n );\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active') {\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(\n route,\n AppState.currentState\n );\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.handleAppStateChanged(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -29,7 +29,7 @@ export class DdRumReactNavigationTracking {
29
29
  } else if (DdRumReactNavigationTracking.registeredContainer == null) {
30
30
  DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
31
31
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
32
- DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
32
+ DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute(), AppState.currentState);
33
33
  navigationRef.addListener('state', listener);
34
34
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
35
35
  DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
@@ -70,7 +70,7 @@ export class DdRumReactNavigationTracking {
70
70
  }
71
71
  }
72
72
 
73
- static handleRouteNavigation(route, appStateStatus = undefined) {
73
+ static handleRouteNavigation(route, appStateStatus) {
74
74
  if (route === undefined || route === null) {
75
75
  InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
76
76
 
@@ -78,13 +78,24 @@ export class DdRumReactNavigationTracking {
78
78
  }
79
79
 
80
80
  const key = route.key;
81
- const predicate = DdRumReactNavigationTracking.viewNamePredicate;
82
- const screenName = predicate(route, route.name);
81
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(route, route.name);
82
+
83
+ if (key != null && screenName != null) {
84
+ // On iOS, the app can start in either "active", "background" or "unknown" state
85
+ if (appStateStatus !== 'background') {
86
+ DdRum.startView(key, screenName);
87
+ }
88
+ }
89
+ }
90
+
91
+ static handleAppStateChanged(route, appStateStatus) {
92
+ const key = route.key;
93
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(route, route.name);
83
94
 
84
95
  if (key != null && screenName != null) {
85
96
  if (appStateStatus === 'background') {
86
97
  DdRum.stopView(key);
87
- } else if (appStateStatus === 'active' || appStateStatus === undefined) {
98
+ } else if (appStateStatus === 'active') {
88
99
  // case when app goes into foreground,
89
100
  // in that case navigation listener won't be called
90
101
  DdRum.startView(key, screenName);
@@ -104,7 +115,7 @@ export class DdRumReactNavigationTracking {
104
115
  return;
105
116
  }
106
117
 
107
- DdRumReactNavigationTracking.handleRouteNavigation(route);
118
+ DdRumReactNavigationTracking.handleRouteNavigation(route, AppState.currentState);
108
119
  };
109
120
  }
110
121
 
@@ -161,6 +172,6 @@ _defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus
161
172
  return;
162
173
  }
163
174
 
164
- DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
175
+ DdRumReactNavigationTracking.handleAppStateChanged(currentRoute, appStateStatus);
165
176
  });
166
177
  //# sourceMappingURL=DdRumReactNavigationTracking.js.map
@@ -1 +1 @@
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","appStateSubscription","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;AAuCtC;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,KAAKA,mBAAL,KAA6BP,aAFjC,EAGE;AACEL,MAAAA,WAAW,CAACS,GAAZ,CAC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,CAAC6B,0CADjC,EAEIjC,YAAY,CAACkC,IAFjB;AAIA;AACH;;AAED9B,QAAAA,4BAA4B,CAACa,qBAA7B,CAAmDa,KAAnD;AACH,OAZD;AAaH;;AACD,WAAO1B,4BAA4B,CAACuB,6BAApC;AACH;;AAnLqC;;gBAA7BvB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAYL,gG;;gBAZKA,4B,uCAcL,+C;;gBAdKA,4B,yCAgBL,6K;;gBAhBKA,4B,6BAkBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD4B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA1BQrC,4B,iBA4BY,MAAM;AACvB,MAAIA,4BAA4B,CAACsC,uBAA7B,EAAJ,EAA4D;AACxDtC,IAAAA,4BAA4B,CAACqB,iBAA7B,CACIrB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQT,4B,sBAsLL2B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGvC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIyB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrD1C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EqB,cAAe,gDAD/F,EAEI/B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACI0B,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 | null;\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 private static appStateSubscription?: NativeEventSubscription;\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 this.appStateSubscription = 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\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n\n // The next if check is important as users can call `stopTrackingViews` before `startTrackingViews`\n // see https://github.com/DataDog/dd-sdk-reactnative/issues/422\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } else if (AppState.removeEventListener) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\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);\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"]}
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","currentState","addListener","backHandler","addEventListener","onBackPress","appStateSubscription","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","screenName","name","startView","handleAppStateChanged","stopView","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;AAuCtC;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,mBAA7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ML4B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGxC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI0B,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrD3C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EsB,cAAe,gDAD/F,EAEIhC,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACoC,qBAA7B,CACII,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 | null;\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 private static appStateSubscription?: NativeEventSubscription;\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 AppState.currentState\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = 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\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n\n // The next if check is important as users can call `stopTrackingViews` before `startTrackingViews`\n // see https://github.com/DataDog/dd-sdk-reactnative/issues/422\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n } else if (AppState.removeEventListener) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus\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 const screenName = DdRumReactNavigationTracking.viewNamePredicate(\n route,\n route.name\n );\n\n if (key != null && screenName != null) {\n // On iOS, the app can start in either \"active\", \"background\" or \"unknown\" state\n if (appStateStatus !== 'background') {\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static handleAppStateChanged(\n route: Route<string, any | undefined>,\n appStateStatus: AppStateStatus\n ) {\n const key = route.key;\n const screenName = DdRumReactNavigationTracking.viewNamePredicate(\n route,\n route.name\n );\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active') {\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(\n route,\n AppState.currentState\n );\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.handleAppStateChanged(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -12,6 +12,34 @@ export declare enum VitalsUpdateFrequency {
12
12
  RARE = "RARE",
13
13
  NEVER = "NEVER"
14
14
  }
15
+ export declare enum UploadFrequency {
16
+ /**
17
+ * Upload data every 1000ms.
18
+ */
19
+ FREQUENT = "FREQUENT",
20
+ /**
21
+ * Upload data every 5000ms.
22
+ */
23
+ AVERAGE = "AVERAGE",
24
+ /**
25
+ * Upload data every 10000ms.
26
+ */
27
+ RARE = "RARE"
28
+ }
29
+ export declare enum BatchSize {
30
+ /**
31
+ * Upload less frequent, larger batches of data
32
+ */
33
+ LARGE = "LARGE",
34
+ /**
35
+ * Use default size for batches of data
36
+ */
37
+ MEDIUM = "MEDIUM",
38
+ /**
39
+ * Upload more frequent, smaller batches of data
40
+ */
41
+ SMALL = "SMALL"
42
+ }
15
43
  export declare type FirstPartyHostsConfiguration = (FirstPartyHost | LegacyFirstPartyHost)[];
16
44
  export declare type LegacyFirstPartyHost = string;
17
45
  /**
@@ -130,6 +158,22 @@ export declare class DdSdkReactNativeConfiguration {
130
158
  * Enables tracking of frustration signals (error taps). Defaults to `true`.
131
159
  */
132
160
  trackFrustrations: boolean;
161
+ /**
162
+ * Sets the preferred frequency for uploading batches of data.
163
+ */
164
+ uploadFrequency: UploadFrequency;
165
+ /**
166
+ * Defines the Datadog SDK policy when batching data together before uploading it to Datadog servers.
167
+ * Smaller batches mean smaller but more network requests, whereas larger batches mean fewer but larger network requests.
168
+ */
169
+ batchSize: BatchSize;
170
+ /**
171
+ * Enables tracking of RUM event when no RUM View is active.
172
+ *
173
+ * By default, background events are not tracked. Enabling this feature might increase the
174
+ * number of sessions tracked and impact your billing.
175
+ */
176
+ trackBackgroundEvents: boolean;
133
177
  logEventMapper: LogEventMapper | null;
134
178
  errorEventMapper: ErrorEventMapper | null;
135
179
  resourceEventMapper: ResourceEventMapper | null;
@@ -196,6 +240,9 @@ export declare type PartialInitializationConfiguration = {
196
240
  readonly telemetrySampleRate?: number;
197
241
  readonly vitalsUpdateFrequency?: VitalsUpdateFrequency;
198
242
  readonly trackFrustrations?: boolean;
243
+ readonly uploadFrequency?: UploadFrequency;
244
+ readonly batchSize?: BatchSize;
245
+ readonly trackBackgroundEvents?: boolean;
199
246
  };
200
247
  export declare const buildConfigurationFromPartialConfiguration: (features: AutoInstrumentationConfiguration, configuration: PartialInitializationConfiguration) => DdSdkReactNativeConfiguration;
201
248
  export declare class DatadogProviderConfiguration extends DdSdkReactNativeConfiguration {
@@ -1,4 +1,5 @@
1
1
  import { SdkVerbosity } from './SdkVerbosity';
2
+ export declare const DATADOG_MESSAGE_PREFIX = "DATADOG:";
2
3
  /**
3
4
  * /!\ DO NOT USE THIS IN YOUR APP /!\\
4
5
  *
@@ -1,5 +1,6 @@
1
1
  export declare const EMPTY_MESSAGE = "Unknown Error";
2
2
  export declare const EMPTY_STACK_TRACE = "";
3
+ export declare const DEFAULT_ERROR_NAME = "Error";
3
4
  export declare const getErrorMessage: (error: any | undefined) => string;
4
5
  /**
5
6
  * Will extract the stack from the error, taking the first key found among:
@@ -10,3 +11,4 @@ export declare const getErrorMessage: (error: any | undefined) => string;
10
11
  * generate a stack from this information.
11
12
  */
12
13
  export declare const getErrorStackTrace: (error: any | undefined) => string;
14
+ export declare const getErrorName: (error: unknown) => string;
@@ -1,4 +1,4 @@
1
- import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode, VitalsUpdateFrequency } from './DdSdkReactNativeConfiguration';
1
+ import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode, VitalsUpdateFrequency, UploadFrequency, BatchSize } from './DdSdkReactNativeConfiguration';
2
2
  import { DdSdkReactNative } from './DdSdkReactNative';
3
3
  import { InternalLog } from './InternalLog';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
@@ -9,4 +9,4 @@ import { DdRum } from './rum/DdRum';
9
9
  import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
10
10
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
11
11
  import { DdTrace } from './trace/DdTrace';
12
- export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity, VitalsUpdateFrequency, PropagatorType };
12
+ export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity, VitalsUpdateFrequency, PropagatorType, UploadFrequency, BatchSize };
@@ -1,12 +1,20 @@
1
- import type { DdLogsType, LogEventMapper } from './types';
1
+ import type { DdLogsType, LogArguments, LogEventMapper, LogWithErrorArguments } from './types';
2
2
  declare class DdLogsWrapper implements DdLogsType {
3
3
  private nativeLogs;
4
4
  private logEventMapper;
5
- debug(message: string, context?: object): Promise<void>;
6
- info(message: string, context?: object): Promise<void>;
7
- warn(message: string, context?: object): Promise<void>;
8
- error(message: string, context?: object): Promise<void>;
5
+ debug(...args: LogArguments | LogWithErrorArguments): Promise<void>;
6
+ info(...args: LogArguments | LogWithErrorArguments): Promise<void>;
7
+ warn(...args: LogArguments | LogWithErrorArguments): Promise<void>;
8
+ error(...args: LogArguments | LogWithErrorArguments): Promise<void>;
9
+ /**
10
+ * Since the InternalLog does not have a verbosity set yet in this case,
11
+ * we use console.warn to warn the user in dev mode.
12
+ */
13
+ private printLogDroppedSdkNotInitialized;
14
+ private printlogDroppedByMapper;
15
+ private printLogTracked;
9
16
  private log;
17
+ private logWithError;
10
18
  registerLogEventMapper(logEventMapper: LogEventMapper): void;
11
19
  unregisterLogEventMapper(): void;
12
20
  }
@@ -1,11 +1,11 @@
1
1
  import type { Attributes } from '../sdk/AttributesSingleton/types';
2
2
  import { EventMapper } from '../sdk/EventMappers/EventMapper';
3
3
  import type { UserInfo } from '../sdk/UserInfoSingleton/types';
4
- import type { LogEvent, LogEventMapper, NativeLog, RawLog } from './types';
5
- export declare const formatLogEventToNativeLog: (logEvent: LogEvent) => NativeLog;
6
- export declare const formatRawLogToNativeEvent: (rawLog: RawLog) => NativeLog;
7
- export declare const formatRawLogToLogEvent: (rawLog: RawLog, additionalInformation: {
4
+ import type { LogEvent, LogEventMapper, NativeLog, NativeLogWithError, RawLog, RawLogWithError } from './types';
5
+ export declare const formatLogEventToNativeLog: (logEvent: LogEvent) => NativeLog | NativeLogWithError;
6
+ export declare const formatRawLogToNativeEvent: (rawLog: RawLog | RawLogWithError) => NativeLog | NativeLogWithError;
7
+ export declare const formatRawLogToLogEvent: (rawLog: RawLog | RawLogWithError, additionalInformation: {
8
8
  userInfo: UserInfo;
9
9
  attributes: Attributes;
10
10
  }) => LogEvent;
11
- export declare const generateEventMapper: (logEventMapper: LogEventMapper | undefined) => EventMapper<RawLog, LogEvent, NativeLog>;
11
+ export declare const generateEventMapper: (logEventMapper: LogEventMapper | undefined) => EventMapper<RawLog | RawLogWithError, LogEvent, NativeLog | NativeLogWithError>;
@@ -4,29 +4,29 @@ import type { UserInfo } from '../sdk/UserInfoSingleton/types';
4
4
  */
5
5
  export declare type DdLogsType = {
6
6
  /**
7
- * Send a log with level debug.
7
+ * Send a log with debug level.
8
8
  * @param message: The message to send.
9
9
  * @param context: The additional context to send.
10
10
  */
11
- debug(message: string, context?: object): Promise<void>;
11
+ debug(...args: LogArguments | LogWithErrorArguments): Promise<void>;
12
12
  /**
13
- * Send a log with level info.
13
+ * Send a log with info level.
14
14
  * @param message: The message to send.
15
15
  * @param context: The additional context to send.
16
16
  */
17
- info(message: string, context?: object): Promise<void>;
17
+ info(...args: LogArguments | LogWithErrorArguments): Promise<void>;
18
18
  /**
19
- * Send a log with level warn.
19
+ * Send a log with warn level.
20
20
  * @param message: The message to send.
21
21
  * @param context: The additional context to send.
22
22
  */
23
- warn(message: string, context?: object): Promise<void>;
23
+ warn(...args: LogArguments | LogWithErrorArguments): Promise<void>;
24
24
  /**
25
- * Send a log with level error.
25
+ * Send a log with error level.
26
26
  * @param message: The message to send.
27
27
  * @param context: The additional context to send.
28
28
  */
29
- error(message: string, context?: object): Promise<void>;
29
+ error(...args: LogArguments | LogWithErrorArguments): Promise<void>;
30
30
  };
31
31
  /**
32
32
  * Log input from developers
@@ -36,6 +36,14 @@ export declare type RawLog = {
36
36
  context: object;
37
37
  status: LogStatus;
38
38
  };
39
+ export declare type RawLogWithError = {
40
+ message: string;
41
+ errorKind: string;
42
+ errorMessage: string;
43
+ stacktrace: string;
44
+ context: object;
45
+ status: LogStatus;
46
+ };
39
47
  /**
40
48
  * Log input for native SDKs
41
49
  */
@@ -43,12 +51,30 @@ export declare type NativeLog = {
43
51
  message: string;
44
52
  context: object;
45
53
  };
54
+ export declare type NativeLogWithError = {
55
+ message: string;
56
+ errorKind: string;
57
+ errorMessage: string;
58
+ stacktrace: string;
59
+ context: object;
60
+ };
46
61
  export declare type LogStatus = 'debug' | 'info' | 'warn' | 'error';
47
62
  export declare type LogEvent = {
48
63
  message: string;
49
64
  context: object;
65
+ errorKind?: string;
66
+ errorMessage?: string;
67
+ stacktrace?: string;
50
68
  readonly status: LogStatus;
51
69
  readonly userInfo: UserInfo;
52
70
  readonly attributes?: object;
53
71
  };
54
72
  export declare type LogEventMapper = (logEvent: LogEvent) => LogEvent | null;
73
+ export declare type LogArguments = [message: string, context?: object];
74
+ export declare type LogWithErrorArguments = [
75
+ message: string,
76
+ errorKind?: string,
77
+ errorMessage?: string,
78
+ stacktrace?: string,
79
+ context?: object
80
+ ];
@@ -59,29 +59,65 @@ export declare type DdNativeSdkType = {
59
59
  */
60
60
  export declare type DdNativeLogsType = {
61
61
  /**
62
- * Send a log with level debug.
62
+ * Send a log with DEBUG level.
63
63
  * @param message: The message to send.
64
64
  * @param context: The additional context to send.
65
65
  */
66
66
  debug(message: string, context?: object): Promise<void>;
67
67
  /**
68
- * Send a log with level info.
68
+ * Send a log with INFO level.
69
69
  * @param message: The message to send.
70
70
  * @param context: The additional context to send.
71
71
  */
72
72
  info(message: string, context?: object): Promise<void>;
73
73
  /**
74
- * Send a log with level warn.
74
+ * Send a log with WARN level.
75
75
  * @param message: The message to send.
76
76
  * @param context: The additional context to send.
77
77
  */
78
78
  warn(message: string, context?: object): Promise<void>;
79
79
  /**
80
- * Send a log with level error.
80
+ * Send a log with ERROR level.
81
81
  * @param message: The message to send.
82
82
  * @param context: The additional context to send.
83
83
  */
84
84
  error(message: string, context?: object): Promise<void>;
85
+ /**
86
+ * Send a log containing an error with DEBUG level.
87
+ * @param message: The message to send.
88
+ * @param errorKind: The error kind to send.
89
+ * @param errorMessage: The error message to send.
90
+ * @param stacktrace: The stack trace to send.
91
+ * @param context: The additional context to send.
92
+ */
93
+ debugWithError(message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: object): Promise<void>;
94
+ /**
95
+ * Send a log containing an error with INDO level.
96
+ * @param message: The message to send.
97
+ * @param errorKind: The error kind to send.
98
+ * @param errorMessage: The error message to send.
99
+ * @param stacktrace: The stack trace to send.
100
+ * @param context: The additional context to send.
101
+ */
102
+ infoWithError(message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: object): Promise<void>;
103
+ /**
104
+ * Send a log containing an error with WARN level.
105
+ * @param message: The message to send.
106
+ * @param errorKind: The error kind to send.
107
+ * @param errorMessage: The error message to send.
108
+ * @param stacktrace: The stack trace to send.
109
+ * @param context: The additional context to send.
110
+ */
111
+ warnWithError(message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: object): Promise<void>;
112
+ /**
113
+ * Send a log containing an error with ERROR level.
114
+ * @param message: The message to send.
115
+ * @param errorKind: The error kind to send.
116
+ * @param errorMessage: The error message to send.
117
+ * @param stacktrace: The stack trace to send.
118
+ * @param context: The additional context to send.
119
+ */
120
+ errorWithError(message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: object): Promise<void>;
85
121
  };
86
122
  /**
87
123
  * The entry point to use Datadog's Trace feature.
@@ -178,6 +214,17 @@ export declare type DdNativeRumType = {
178
214
  * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
179
215
  */
180
216
  addTiming(name: string): Promise<void>;
217
+ /**
218
+ * Stops the current RUM Session.
219
+ */
220
+ stopSession(): Promise<void>;
221
+ /**
222
+ * Adds the result of evaluating a feature flag with a given name and value to the view.
223
+ * Feature flag evaluations are local to the active view and are cleared when the view is stopped.
224
+ * @param name: The name of the feature flag
225
+ * @param value: The value of the feature flag, encapsulated in an object to accept all types
226
+ */
227
+ addFeatureFlagEvaluation(name: string, value: object): Promise<void>;
181
228
  };
182
229
  declare type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
183
230
  declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
@@ -25,6 +25,8 @@ declare class DdRumWrapper implements DdRumType {
25
25
  stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number, resourceContext?: XMLHttpRequest): Promise<void>;
26
26
  addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
27
27
  addTiming(name: string): Promise<void>;
28
+ stopSession(): Promise<void>;
29
+ addFeatureFlagEvaluation(name: string, value: unknown): Promise<void>;
28
30
  registerErrorEventMapper(errorEventMapper: ErrorEventMapper): void;
29
31
  unregisterErrorEventMapper(): void;
30
32
  registerResourceEventMapper(resourceEventMapper: ResourceEventMapper): void;
@@ -10,6 +10,7 @@ export declare class DdRumErrorTracking {
10
10
  * Starts tracking errors and sends a RUM Error event every time an error is detected.
11
11
  */
12
12
  static startTracking(): void;
13
- static onGlobalError(error: any, isFatal?: boolean): void;
14
- static onConsoleError(...params: unknown[]): void;
13
+ static onGlobalError: (error: any, isFatal?: boolean) => void;
14
+ static onConsoleError: (...params: unknown[]) => void;
15
+ private static reportError;
15
16
  }
@@ -1,7 +1,7 @@
1
1
  import type EventsInterceptor from './EventsInterceptor';
2
2
  export declare const UNKNOWN_TARGET_NAME = "unknown_target";
3
3
  export declare class DdEventsInterceptor implements EventsInterceptor {
4
- static ACTION_EVENT_DROPPED_WARN_MESSAGE: string;
4
+ static ACTION_EVENT_DROPPED_DEBUG_MESSAGE: string;
5
5
  private debouncingStartedTimestamp;
6
6
  interceptOnPress(...args: any[]): void;
7
7
  private handleTargetEvent;
@@ -1,4 +1,7 @@
1
1
  /**
2
- * Does a shallow comparison between 2 objects
2
+ * Does a shallow comparison between 2 objects.
3
+ *
4
+ * In some rare cases, one of the objects can be `undefined` or `null`.
5
+ * This is documented in https://github.com/DataDog/dd-sdk-reactnative/issues/419.
3
6
  */
4
- export declare const areObjectShallowEqual: (objectA: Record<string, unknown>, objectB: Record<string, unknown>) => boolean;
7
+ export declare const areObjectShallowEqual: (objectA: Record<string, unknown> | undefined | null, objectB: Record<string, unknown> | undefined | null) => boolean;
@@ -84,6 +84,10 @@ export declare type DdRumType = {
84
84
  * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
85
85
  */
86
86
  addTiming(name: string): Promise<void>;
87
+ /**
88
+ * Stops the current RUM Session.
89
+ */
90
+ stopSession(): Promise<void>;
87
91
  };
88
92
  /**
89
93
  * Describe the type of a RUM Action.
@@ -14,18 +14,25 @@ export declare class DdSdkConfiguration {
14
14
  readonly additionalConfig: object;
15
15
  readonly telemetrySampleRate: number;
16
16
  readonly vitalsUpdateFrequency: string;
17
+ readonly uploadFrequency: string;
18
+ readonly batchSize: string;
17
19
  readonly trackFrustrations: boolean;
20
+ readonly trackBackgroundEvents: boolean;
18
21
  readonly configurationForTelemetry: {
19
22
  initializationType: string;
20
23
  trackErrors: boolean;
21
24
  trackInteractions: boolean;
22
25
  trackNetworkRequests: boolean;
26
+ reactVersion: string;
27
+ reactNativeVersion: string;
23
28
  };
24
- constructor(clientToken: string, env: string, applicationId: string, nativeCrashReportEnabled: boolean, nativeLongTaskThresholdMs: number, longTaskThresholdMs: number, sampleRate: number, site: string, trackingConsent: string, additionalConfig: object, telemetrySampleRate: number, vitalsUpdateFrequency: string, trackFrustrations: boolean, configurationForTelemetry: {
29
+ constructor(clientToken: string, env: string, applicationId: string, nativeCrashReportEnabled: boolean, nativeLongTaskThresholdMs: number, longTaskThresholdMs: number, sampleRate: number, site: string, trackingConsent: string, additionalConfig: object, telemetrySampleRate: number, vitalsUpdateFrequency: string, uploadFrequency: string, batchSize: string, trackFrustrations: boolean, trackBackgroundEvents: boolean, configurationForTelemetry: {
25
30
  initializationType: string;
26
31
  trackErrors: boolean;
27
32
  trackInteractions: boolean;
28
33
  trackNetworkRequests: boolean;
34
+ reactVersion: string;
35
+ reactNativeVersion: string;
29
36
  });
30
37
  }
31
38
  /**
@@ -1 +1 @@
1
- export declare const version = "1.5.2";
1
+ export declare const version = "1.7.0";
@@ -25,6 +25,7 @@ export declare class DdRumReactNavigationTracking {
25
25
  */
26
26
  static stopTrackingViews(navigationRef: NavigationContainerRef | null): void;
27
27
  private static handleRouteNavigation;
28
+ private static handleAppStateChanged;
28
29
  private static resolveNavigationStateChangeListener;
29
30
  private static appStateListener;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.5.2",
3
+ "version": "1.7.0",
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": "rm -rf lib && yarn bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.5.2",
39
+ "@datadog/mobile-react-native": "^1.7.0",
40
40
  "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.8",
41
41
  "@react-navigation/native-v6": "npm:@react-navigation/native@6.1.2",
42
42
  "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "2987dffcc3f438771e7a33fab8d4609a17070a78"
80
+ "gitHead": "e7eb5ba2ac1eefbacf5c60695c7d761560c4f2cb"
81
81
  }
@@ -386,6 +386,7 @@ describe.each([
386
386
  (reactNativeVersion, AppStateMockVersion) => {
387
387
  let appStateMock;
388
388
  beforeEach(() => {
389
+ AppState.currentState = 'active';
389
390
  appStateMock = new AppStateMockVersion();
390
391
  mocked(AppState.addEventListener).mockImplementation(
391
392
  // @ts-ignore
@@ -476,7 +477,7 @@ describe.each([
476
477
  ).toBe('string');
477
478
  });
478
479
 
479
- it('starts last view when app goes into foreground', async () => {
480
+ it('restarts last view when app goes into foreground', async () => {
480
481
  // GIVEN
481
482
  const navigationRef = createRef<any>();
482
483
  render(<FakeNavigator1 navigationRef={navigationRef} />);
@@ -531,6 +532,43 @@ describe.each([
531
532
  // THEN
532
533
  expect(DdRum.stopView).toHaveBeenCalled();
533
534
  });
535
+
536
+ it('does not create a RUM view when the app starts in background', async () => {
537
+ // GIVEN
538
+ appStateMock.changeValue('background');
539
+ const navigationRef = createRef<any>();
540
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
541
+
542
+ DdRumReactNavigationTracking.startTrackingViews(
543
+ navigationRef.current
544
+ );
545
+
546
+ // THEN
547
+ expect(DdRum.startView).not.toHaveBeenCalled();
548
+ });
549
+
550
+ // Note: currently iOS apps start in "unknown" app state, but should default to "inactive"
551
+ it.each(['unknown', 'inactive'])(
552
+ 'creates 2 RUM Views when the app starts in %s then becomes active',
553
+ async initialAppState => {
554
+ // GIVEN
555
+ appStateMock.changeValue(initialAppState);
556
+ const navigationRef = createRef<any>();
557
+ render(
558
+ <FakeNavigator1 navigationRef={navigationRef} />
559
+ );
560
+
561
+ DdRumReactNavigationTracking.startTrackingViews(
562
+ navigationRef.current
563
+ );
564
+
565
+ // WHEN
566
+ appStateMock.changeValue('active');
567
+
568
+ // THEN
569
+ expect(DdRum.startView).toHaveBeenCalledTimes(2);
570
+ }
571
+ );
534
572
  }
535
573
  );
536
574
 
@@ -9,6 +9,7 @@ import type {
9
9
  AppStateStatus,
10
10
  NativeEventSubscription
11
11
  } from 'react-native';
12
+ import { AppState } from 'react-native';
12
13
 
13
14
  type handler = (type: AppStateStatus) => void;
14
15
 
@@ -55,6 +56,8 @@ export class AppStateMock {
55
56
  };
56
57
 
57
58
  changeValue = (value: AppStateStatus) => {
59
+ // Currently jest does not let us mock getters
60
+ AppState.currentState = value;
58
61
  if (!this.listeners.change) {
59
62
  return;
60
63
  }
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { AppStateEvent, AppStateStatus } from 'react-native';
8
+ import { AppState } from 'react-native';
8
9
 
9
10
  type handler = (type: AppStateStatus) => void;
10
11
 
@@ -41,6 +42,8 @@ export class AppStateMockLegacy {
41
42
  };
42
43
 
43
44
  changeValue = (value: AppStateStatus) => {
45
+ // Currently jest does not let us mock getters
46
+ AppState.currentState = value;
44
47
  if (!this.listeners.change) {
45
48
  return;
46
49
  }
@@ -102,7 +102,8 @@ export class DdRumReactNavigationTracking {
102
102
  DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
103
103
  const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
104
104
  DdRumReactNavigationTracking.handleRouteNavigation(
105
- navigationRef.getCurrentRoute()
105
+ navigationRef.getCurrentRoute(),
106
+ AppState.currentState
106
107
  );
107
108
  navigationRef.addListener('state', listener);
108
109
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
@@ -161,7 +162,7 @@ export class DdRumReactNavigationTracking {
161
162
 
162
163
  private static handleRouteNavigation(
163
164
  route: Route<string, any | undefined> | undefined,
164
- appStateStatus: AppStateStatus | undefined = undefined
165
+ appStateStatus: AppStateStatus
165
166
  ) {
166
167
  if (route === undefined || route === null) {
167
168
  InternalLog.log(
@@ -172,17 +173,33 @@ export class DdRumReactNavigationTracking {
172
173
  return;
173
174
  }
174
175
  const key = route.key;
176
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(
177
+ route,
178
+ route.name
179
+ );
175
180
 
176
- const predicate = DdRumReactNavigationTracking.viewNamePredicate;
177
- const screenName = predicate(route, route.name);
181
+ if (key != null && screenName != null) {
182
+ // On iOS, the app can start in either "active", "background" or "unknown" state
183
+ if (appStateStatus !== 'background') {
184
+ DdRum.startView(key, screenName);
185
+ }
186
+ }
187
+ }
188
+
189
+ private static handleAppStateChanged(
190
+ route: Route<string, any | undefined>,
191
+ appStateStatus: AppStateStatus
192
+ ) {
193
+ const key = route.key;
194
+ const screenName = DdRumReactNavigationTracking.viewNamePredicate(
195
+ route,
196
+ route.name
197
+ );
178
198
 
179
199
  if (key != null && screenName != null) {
180
200
  if (appStateStatus === 'background') {
181
201
  DdRum.stopView(key);
182
- } else if (
183
- appStateStatus === 'active' ||
184
- appStateStatus === undefined
185
- ) {
202
+ } else if (appStateStatus === 'active') {
186
203
  // case when app goes into foreground,
187
204
  // in that case navigation listener won't be called
188
205
  DdRum.startView(key, screenName);
@@ -205,7 +222,10 @@ export class DdRumReactNavigationTracking {
205
222
  return;
206
223
  }
207
224
 
208
- DdRumReactNavigationTracking.handleRouteNavigation(route);
225
+ DdRumReactNavigationTracking.handleRouteNavigation(
226
+ route,
227
+ AppState.currentState
228
+ );
209
229
  };
210
230
  }
211
231
  return DdRumReactNavigationTracking.navigationStateChangeListener;
@@ -223,7 +243,7 @@ export class DdRumReactNavigationTracking {
223
243
  return;
224
244
  }
225
245
 
226
- DdRumReactNavigationTracking.handleRouteNavigation(
246
+ DdRumReactNavigationTracking.handleAppStateChanged(
227
247
  currentRoute,
228
248
  appStateStatus
229
249
  );