@datadog/mobile-react-navigation 2.3.6 → 2.4.1

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,7 +19,8 @@ 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) {
22
+ static startTrackingViews(navigationRef, // eslint-disable-next-line func-names
23
+ viewNamePredicate = function (_route, trackedName) {
23
24
  return trackedName;
24
25
  }) {
25
26
  if (navigationRef == null) {
@@ -53,7 +54,7 @@ class DdRumReactNavigationTracking {
53
54
  navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
54
55
  (_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
55
56
  DdRumReactNavigationTracking.backHandler = null;
56
- DdRumReactNavigationTracking.registeredContainer = null;
57
+ DdRumReactNavigationTracking.registeredContainer = null; // eslint-disable-next-line func-names
57
58
 
58
59
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
59
60
  return trackedName;
@@ -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","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","trackingState","DdRum","startView","handle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mD,c;;gBAXnDA,4B,gDAcL,gG;;gBAdKA,4B,uCAgBL,+C;;gBAhBKA,4B,yCAkBL,6K;;gBAlBKA,4B,6BAoBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACW,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIX,4BAA4B,CAACW,mBAA7B,CAAiDiC,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA5BQ5C,4B,iBA8BY,MAAM;AACvB,MAAIA,4BAA4B,CAAC6C,uBAA7B,EAAJ,EAA4D;AACxD7C,IAAAA,4BAA4B,CAAC0B,iBAA7B,CACI1B,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAvCQX,4B,sBAkNLgC,cADgD,IAE/C;AAAA;;AACD,QAAMc,YAAY,6BAAG9C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI8B,YAAY,KAAKb,SAAjB,IAA8Ba,YAAY,KAAK,IAAnD,EAAyD;AACrDxC,mCAAYC,GAAZ,CACK,4EAA2EyB,cAAe,gDAD/F,EAEIvB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAAC0C,qBAA7B,CACII,YADJ,EAEId,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 private static trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' &&\n DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING'\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRumReactNavigationTracking.trackingState = 'TRACKING';\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"]}
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","trackingState","DdRum","startView","handleAppStateChanged","stopView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAyCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAGrB;AACAC,EAAAA,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAToB,EAUjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACQ,iCAD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,MAAIA,4BAA4B,CAAC6C,uBAA7B,EAAJ,EAA4D;AACxD7C,IAAAA,4BAA4B,CAAC0B,iBAA7B,CACI1B,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAvCQX,4B,sBAsNLgC,cADgD,IAE/C;AAAA;;AACD,QAAMc,YAAY,6BAAG9C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI8B,YAAY,KAAKb,SAAjB,IAA8Ba,YAAY,KAAK,IAAnD,EAAyD;AACrDxC,mCAAYC,GAAZ,CACK,4EAA2EyB,cAAe,gDAD/F,EAEIvB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAAC0C,qBAA7B,CACII,YADJ,EAEId,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 private static trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';\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\n // eslint-disable-next-line func-names\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\n // eslint-disable-next-line func-names\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 DdRumReactNavigationTracking.trackingState = 'TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' &&\n DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING'\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRumReactNavigationTracking.trackingState = 'TRACKING';\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"]}
@@ -16,7 +16,8 @@ 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) {
19
+ static startTrackingViews(navigationRef, // eslint-disable-next-line func-names
20
+ viewNamePredicate = function (_route, trackedName) {
20
21
  return trackedName;
21
22
  }) {
22
23
  if (navigationRef == null) {
@@ -49,7 +50,7 @@ export class DdRumReactNavigationTracking {
49
50
  navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
50
51
  (_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
51
52
  DdRumReactNavigationTracking.backHandler = null;
52
- DdRumReactNavigationTracking.registeredContainer = null;
53
+ DdRumReactNavigationTracking.registeredContainer = null; // eslint-disable-next-line func-names
53
54
 
54
55
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
55
56
  return trackedName;
@@ -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","currentState","addListener","backHandler","addEventListener","onBackPress","appStateSubscription","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","screenName","name","trackingState","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;AAyCtC;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,CACIN,4BAA4B,CAACU,mCADjC,EAEId,YAAY,CAACY,KAFjB;AAIH,KARD,MAQO,IAAIR,4BAA4B,CAACS,mBAA7B,IAAoD,IAAxD,EAA8D;AACjET,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMQ,QAAQ,GAAGX,4BAA4B,CAACY,oCAA7B,EAAjB;AACAZ,MAAAA,4BAA4B,CAACa,qBAA7B,CACIX,aAAa,CAACY,eAAd,EADJ,EAEIhB,QAAQ,CAACiB,YAFb;AAIAb,MAAAA,aAAa,CAACc,WAAd,CAA0B,OAA1B,EAAmCL,QAAnC;AACAX,MAAAA,4BAA4B,CAACS,mBAA7B,GAAmDP,aAAnD;AACAF,MAAAA,4BAA4B,CAACiB,WAA7B,GAA2ClB,WAAW,CAACmB,gBAAZ,CACvC,mBADuC,EAEvClB,4BAA4B,CAACmB,WAFU,CAA3C;AAIA,WAAKC,o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Y,CAACmC,IAFjB;AAIA;AACH;;AAED/B,QAAAA,4BAA4B,CAACa,qBAA7B,CACIc,KADJ,EAEI7B,QAAQ,CAACiB,YAFb;AAIH,OAfD;AAgBH;;AACD,WAAOf,4BAA4B,CAACwB,6BAApC;AACH;;AA/MqC;;gBAA7BxB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,mBAWmD,c;;gBAXnDA,4B,gDAcL,gG;;gBAdKA,4B,uCAgBL,+C;;gBAhBKA,4B,yCAkBL,6K;;gBAlBKA,4B,6BAoBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD8B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA5BQvC,4B,iBA8BY,MAAM;AACvB,MAAIA,4BAA4B,CAACwC,uBAA7B,EAAJ,EAA4D;AACxDxC,IAAAA,4BAA4B,CAACsB,iBAA7B,CACItB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAvCQT,4B,sBAkNL4B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAGzC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI2B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrD5C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EsB,cAAe,gDAD/F,EAEIhC,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACqC,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 private static trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' &&\n DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING'\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRumReactNavigationTracking.trackingState = 'TRACKING';\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"]}
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","trackingState","startView","handleAppStateChanged","stopView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgB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,EAEI7B,QAAQ,CAACiB,YAFb;AAIH,OAfD;AAgBH;;AACD,WAAOf,4BAA4B,CAACwB,6BAApC;AACH;;AAnNqC;;gBAA7BxB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,mBAWmD,c;;gBAXnDA,4B,gDAcL,gG;;gBAdKA,4B,uCAgBL,+C;;gBAhBKA,4B,yCAkBL,6K;;gBAlBKA,4B,6BAoBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD8B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA5BQvC,4B,iBA8BY,MAAM;AACvB,MAAIA,4BAA4B,CAACwC,uBAA7B,EAAJ,EAA4D;AACxDxC,IAAAA,4BAA4B,CAACsB,iBAA7B,CACItB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAvCQT,4B,sBAsNL4B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAGzC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI2B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrD5C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EsB,cAAe,gDAD/F,EAEIhC,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACqC,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 private static trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';\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\n // eslint-disable-next-line func-names\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\n // eslint-disable-next-line func-names\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 DdRumReactNavigationTracking.trackingState = 'TRACKING';\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 DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' &&\n DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING'\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRumReactNavigationTracking.trackingState = 'TRACKING';\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"]}
@@ -13,7 +13,6 @@ export declare class DdSdkReactNative {
13
13
  private static readonly DD_VERSION_SUFFIX;
14
14
  private static wasAutoInstrumented;
15
15
  private static features?;
16
- private static _isInitialized;
17
16
  /**
18
17
  * Initializes the Datadog SDK.
19
18
  * @param configuration the configuration for the SDK library
@@ -57,10 +56,6 @@ export declare class DdSdkReactNative {
57
56
  * @returns a Promise
58
57
  */
59
58
  static clearAllData: () => Promise<void>;
60
- /**
61
- * Returns `true` if the SDK was initialized, `false` otherwise.
62
- */
63
- static isInitialized(): boolean;
64
59
  private static buildConfiguration;
65
60
  private static enableFeatures;
66
61
  }
@@ -77,6 +77,7 @@ export declare const DEFAULTS: {
77
77
  getCustomEndpoints: () => {};
78
78
  bundleLogsWithRum: boolean;
79
79
  bundleLogsWithTraces: boolean;
80
+ useAccessibilityLabel: boolean;
80
81
  };
81
82
  /**
82
83
  * The SDK configuration class.
@@ -90,6 +91,7 @@ export declare class DdSdkReactNativeConfiguration {
90
91
  readonly trackResources: boolean;
91
92
  readonly trackErrors: boolean;
92
93
  readonly trackingConsent: TrackingConsent;
94
+ readonly useAccessibilityLabel: boolean;
93
95
  /**
94
96
  * Enables crash reporting for native platforms (iOS, Android). Default `false`.
95
97
  */
@@ -237,7 +239,7 @@ export declare class DdSdkReactNativeConfiguration {
237
239
  [k: string]: any;
238
240
  };
239
241
  customEndpoints: CustomEndpoints;
240
- constructor(clientToken: string, env: string, applicationId: string, trackInteractions?: boolean, trackResources?: boolean, trackErrors?: boolean, trackingConsent?: TrackingConsent);
242
+ constructor(clientToken: string, env: string, applicationId: string, trackInteractions?: boolean, trackResources?: boolean, trackErrors?: boolean, trackingConsent?: TrackingConsent, useAccessibilityLabel?: boolean);
241
243
  }
242
244
  /**
243
245
  * Auto Instrumentation configuration passed to DatadogProvider.
@@ -253,6 +255,7 @@ export type AutoInstrumentationConfiguration = {
253
255
  readonly errorEventMapper?: ErrorEventMapper | null;
254
256
  readonly resourceEventMapper?: ResourceEventMapper | null;
255
257
  readonly actionEventMapper?: ActionEventMapper | null;
258
+ readonly useAccessibilityLabel?: boolean;
256
259
  readonly actionNameAttribute?: string;
257
260
  };
258
261
  /**
@@ -268,6 +271,7 @@ export type AutoInstrumentationParameters = {
268
271
  readonly errorEventMapper: ErrorEventMapper | null;
269
272
  readonly resourceEventMapper: ResourceEventMapper | null;
270
273
  readonly actionEventMapper: ActionEventMapper | null;
274
+ readonly useAccessibilityLabel: boolean;
271
275
  readonly actionNameAttribute?: string;
272
276
  };
273
277
  /**
@@ -1,3 +1,4 @@
1
+ import './polyfills';
1
2
  import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode, VitalsUpdateFrequency, UploadFrequency, BatchSize } from './DdSdkReactNativeConfiguration';
2
3
  import { DdSdkReactNative } from './DdSdkReactNative';
3
4
  import { InternalLog } from './InternalLog';
@@ -1,12 +1,21 @@
1
1
  import type EventsInterceptor from './EventsInterceptor';
2
2
  export declare const UNKNOWN_TARGET_NAME = "unknown_target";
3
+ export type DdEventsInterceptorOptions = {
4
+ /**
5
+ * Specifies a custom prop to name RUM actions on elements having an `onPress` prop
6
+ * */
7
+ actionNameAttribute?: string;
8
+ /**
9
+ * Determines whether the accessibility label can be used to resolve the action name.
10
+ * */
11
+ useAccessibilityLabel?: boolean;
12
+ };
3
13
  export declare class DdEventsInterceptor implements EventsInterceptor {
4
14
  static ACTION_EVENT_DROPPED_DEBUG_MESSAGE: string;
5
15
  private debouncingStartedTimestamp;
6
16
  private actionNameAttribute?;
7
- constructor({ actionNameAttribute }?: {
8
- actionNameAttribute?: string;
9
- });
17
+ private useAccessibilityLabel;
18
+ constructor(options?: DdEventsInterceptorOptions);
10
19
  interceptOnPress(...args: any[]): void;
11
20
  private handleTargetEvent;
12
21
  private resolveTargetName;
@@ -1,3 +1,4 @@
1
+ import type { DdEventsInterceptorOptions } from './DdEventsInterceptor';
1
2
  /**
2
3
  * Provides RUM auto-instrumentation feature to track user interaction as RUM events.
3
4
  * For now we are only covering the "onPress" events.
@@ -14,8 +15,6 @@ export declare class DdRumUserInteractionTracking {
14
15
  * Please note that we are only considering as valid - for - tracking only the user interactions that have
15
16
  * a visible output (either an UI state change or a Resource request)
16
17
  */
17
- static startTracking({ actionNameAttribute }?: {
18
- actionNameAttribute?: string;
19
- }): void;
18
+ static startTracking(options: DdEventsInterceptorOptions): void;
20
19
  static stopTracking(): void;
21
20
  }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Available formats for representing the {@link TracingIdentifier} as a string.
3
+ */
4
+ export declare enum TracingIdFormat {
5
+ /**
6
+ * Decimal string representation of the full tracing id.
7
+ */
8
+ decimal = 0,
9
+ /**
10
+ * The low bits of the tracing id as a decimal.
11
+ */
12
+ lowDecimal = 1,
13
+ /**
14
+ * The high bits of the tracing id as a decimal.
15
+ */
16
+ highDecimal = 2,
17
+ /**
18
+ * Hexadecimal string representation of the full tracing id.
19
+ */
20
+ hex = 3,
21
+ /**
22
+ * Hexadecimal string representation of the low bits of the tracing id.
23
+ */
24
+ lowHex = 4,
25
+ /**
26
+ * Hexadecimal string representation of the high bits of the tracing id.
27
+ */
28
+ highHex = 5,
29
+ /**
30
+ * Padded hexadecimal string representation of the full tracing id.
31
+ */
32
+ paddedHex = 6,
33
+ /**
34
+ * Padded hexadecimal string representation of the low bits of the tracing id.
35
+ */
36
+ paddedLowHex = 7,
37
+ /**
38
+ * Padded hexadecimal string representation of the high bits of the tracing id.
39
+ */
40
+ paddedHighHex = 8
41
+ }
42
+ /**
43
+ * A {@link TracingIdentifier} used for Traces (128 bit).
44
+ */
45
+ export type TraceId = TracingIdentifier & {
46
+ _brand: 'traceId';
47
+ };
48
+ /**
49
+ * A {@link TracingIdentifier} used for Spans (64 bit).
50
+ */
51
+ export type SpanId = TracingIdentifier & {
52
+ _brand: 'spanId';
53
+ };
54
+ /**
55
+ * The tracing identifier type.
56
+ */
57
+ export declare enum TracingIdType {
58
+ /**
59
+ * 128-bit UUID.
60
+ */
61
+ trace = 0,
62
+ /**
63
+ * 64-bit UUID.
64
+ */
65
+ span = 1
66
+ }
67
+ /**
68
+ * A {@link TracingIdentifier} is a unique UUID that can be 64bit or 128bit, and provides
69
+ * convenient methods to represent it as a HEX or DECIMAL string, and it allows the masking
70
+ * of its low or high bits.
71
+ *
72
+ * Create a new identifier by calling {@link TracingIdentifier.createTraceId()} or
73
+ * {@link TracingIdentifier.createSpanId()}.
74
+ */
75
+ export declare class TracingIdentifier {
76
+ /**
77
+ * Read-only generated ID as a {@link bigint}.
78
+ */
79
+ readonly id: bigint;
80
+ /**
81
+ * Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.
82
+ */
83
+ readonly type: TracingIdType;
84
+ /**
85
+ * Creates a new unique Trace ID.
86
+ * @returns the generated {@link TraceId}.
87
+ */
88
+ static createTraceId(): TraceId;
89
+ /**
90
+ * Creates a new unique Span ID.
91
+ * @returns the generated {@link SpanId}.
92
+ */
93
+ static createSpanId(): SpanId;
94
+ /**
95
+ * Private constructor to initialize the {@link TracingIdentifier} based on the given
96
+ * {@link TracingIdType}.
97
+ */
98
+ private constructor();
99
+ /**
100
+ * Generates a unique ID with the given format.
101
+ * @param format - the desired format (64bit or 128bit).
102
+ * @returns the generated UUID as a {@link bigint}.
103
+ */
104
+ private generateUUID;
105
+ /**
106
+ * Returns a string representation of the Tracing ID.
107
+ * @param format - The type of representation to use.
108
+ * @returns The ID as a string in the specified representation type.
109
+ */
110
+ toString(format: TracingIdFormat): string;
111
+ }
@@ -1,5 +1,6 @@
1
1
  import type { PropagatorType } from '../../../types';
2
2
  import type { RegexMap } from '../requestProxy/interfaces/RequestProxy';
3
+ import type { SpanId, TraceId } from './TracingIdentifier';
3
4
  import type { Hostname } from './firstPartyHosts';
4
5
  export type DdRumResourceTracingAttributes = {
5
6
  tracingStrategy: 'KEEP';
@@ -19,27 +20,3 @@ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegexMap,
19
20
  firstPartyHostsRegexMap: RegexMap;
20
21
  tracingSamplingRate: number;
21
22
  }) => DdRumResourceTracingAttributes;
22
- /**
23
- * Using branded types will ensure we don't accidentally use
24
- * traceId for spanId when generating headers.
25
- */
26
- export type TraceId = TraceIdentifier & {
27
- _brand: 'traceId';
28
- };
29
- export type SpanId = TraceIdentifier & {
30
- _brand: 'spanId';
31
- };
32
- export declare class TraceIdentifier {
33
- private low;
34
- private high;
35
- constructor();
36
- toString: (radix: number) => string;
37
- /**
38
- * This function pads the trace with `0`.
39
- * It should not be used with a `length` lower than the trace, as we return the full trace in this case.
40
- * @param radix radix for the trace
41
- * @param length minimum length
42
- * @returns padded string
43
- */
44
- toPaddedString: (radix: number, length: number) => string;
45
- }
@@ -7,6 +7,8 @@ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
7
7
  export declare const ORIGIN_RUM = "rum";
8
8
  export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
9
9
  export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
10
+ export declare const TAGS_HEADER_KEY = "x-datadog-tags";
11
+ export declare const DD_TRACE_ID_TAG = "_dd.p.tid";
10
12
  /**
11
13
  * OTel headers
12
14
  */
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A singleton container for attributes that are shared internally across all
3
+ * the SDK classes.
4
+ */
5
+ export declare class GlobalState {
6
+ /**
7
+ * `true` if the SDK is initialized, `false` otherwise.
8
+ */
9
+ isInitialized: boolean;
10
+ private static _instance;
11
+ static get instance(): GlobalState;
12
+ }
@@ -1 +1 @@
1
- export declare const version = "2.3.6";
1
+ export declare const version = "2.4.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "2.3.6",
3
+ "version": "2.4.1",
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": "^2.3.6",
39
+ "@datadog/mobile-react-native": "^2.4.1",
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",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  ]
85
85
  },
86
- "gitHead": "79c58ebfe7957fc97241d2455ddc0e75276683ff"
86
+ "gitHead": "f527de2facb85c3e5bdfcc7e46e2931c1f9e8039"
87
87
  }
@@ -154,6 +154,8 @@ describe.each([
154
154
  );
155
155
  const goToAboutButton = getByText('Go to About');
156
156
  const customViewName = 'custom_view_name';
157
+
158
+ // eslint-disable-next-line func-names
157
159
  const predicate: ViewNamePredicate = function (
158
160
  _route: Route<string, any | undefined>,
159
161
  _trackedName: string
@@ -183,12 +185,15 @@ describe.each([
183
185
  <FakeNavigator1 navigationRef={navigationRef} />
184
186
  );
185
187
  const goToAboutButton = getByText('Go to About');
188
+
189
+ // eslint-disable-next-line func-names
186
190
  const predicate: ViewNamePredicate = function (
187
191
  _route: Route<string, any | undefined>,
188
192
  _trackedName: string
189
193
  ) {
190
194
  return null;
191
195
  };
196
+
192
197
  DdRumReactNavigationTracking.startTrackingViews(
193
198
  navigationRef.current,
194
199
  predicate
@@ -77,6 +77,8 @@ export class DdRumReactNavigationTracking {
77
77
  */
78
78
  static startTrackingViews(
79
79
  navigationRef: NavigationContainerRef | null,
80
+
81
+ // eslint-disable-next-line func-names
80
82
  viewNamePredicate: ViewNamePredicate = function (
81
83
  _route: Route<string, any | undefined>,
82
84
  trackedName: string
@@ -135,6 +137,8 @@ export class DdRumReactNavigationTracking {
135
137
  DdRumReactNavigationTracking.backHandler?.remove();
136
138
  DdRumReactNavigationTracking.backHandler = null;
137
139
  DdRumReactNavigationTracking.registeredContainer = null;
140
+
141
+ // eslint-disable-next-line func-names
138
142
  DdRumReactNavigationTracking.viewNamePredicate = function (
139
143
  _route: Route<string, any | undefined>,
140
144
  trackedName: string