@datadog/mobile-react-navigation 1.7.1 → 1.8.0-rc0

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 (21) hide show
  1. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +9 -1
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  3. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +6 -1
  4. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  5. package/lib/typescript/core/src/DdSdkReactNative.d.ts +4 -4
  6. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +14 -0
  7. package/lib/typescript/core/src/logs/DdLogs.d.ts +4 -4
  8. package/lib/typescript/core/src/nativeModulesTypes.d.ts +28 -168
  9. package/lib/typescript/core/src/rum/DdRum.d.ts +12 -12
  10. package/lib/typescript/core/src/rum/eventMappers/errorEventMapper.d.ts +4 -4
  11. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +4 -0
  12. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +3 -1
  13. package/lib/typescript/core/src/specs/NativeDdLogs.d.ts +69 -0
  14. package/lib/typescript/core/src/specs/NativeDdRum.d.ts +92 -0
  15. package/lib/typescript/core/src/specs/NativeDdSdk.d.ts +46 -0
  16. package/lib/typescript/core/src/specs/NativeDdTrace.d.ts +23 -0
  17. package/lib/typescript/core/src/version.d.ts +1 -1
  18. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +1 -0
  19. package/package.json +3 -3
  20. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +62 -2
  21. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +9 -1
@@ -88,6 +88,8 @@ class DdRumReactNavigationTracking {
88
88
  if (key != null && screenName != null) {
89
89
  // On iOS, the app can start in either "active", "background" or "unknown" state
90
90
  if (appStateStatus !== 'background') {
91
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
92
+
91
93
  _mobileReactNative.DdRum.startView(key, screenName);
92
94
  }
93
95
  }
@@ -99,10 +101,14 @@ class DdRumReactNavigationTracking {
99
101
 
100
102
  if (key != null && screenName != null) {
101
103
  if (appStateStatus === 'background') {
104
+ DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';
105
+
102
106
  _mobileReactNative.DdRum.stopView(key);
103
- } else if (appStateStatus === 'active') {
107
+ } else if (appStateStatus === 'active' && DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING') {
104
108
  // case when app goes into foreground,
105
109
  // in that case navigation listener won't be called
110
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
111
+
106
112
  _mobileReactNative.DdRum.startView(key, screenName);
107
113
  }
108
114
  }
@@ -142,6 +148,8 @@ _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
142
148
 
143
149
  _defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
144
150
 
151
+ _defineProperty(DdRumReactNavigationTracking, "trackingState", 'NOT_TRACKING');
152
+
145
153
  _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
146
154
 
147
155
  _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
@@ -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","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,4BAA4B,CAACQ,iCADjC,EAEIC,gCAAaC,KAFjB;;AAIA;AACH;;AAED,QACIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BT,aAFjC,EAGE;AACEI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACY,mCADjC,EAEIH,gCAAaC,KAFjB;AAIH,KARD,MAQO,IAAIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAAxD,EAA8D;AACjEX,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMU,QAAQ,GAAGb,4BAA4B,CAACc,oCAA7B,EAAjB;AACAd,MAAAA,4BAA4B,CAACe,qBAA7B,CACIb,aAAa,CAACc,eAAd,EADJ,EAEIC,sBAASC,YAFb;AAIAhB,MAAAA,aAAa,CAACiB,WAAd,CAA0B,OAA1B,EAAmCN,QAAnC;AACAb,MAAAA,4BAA4B,CAACW,mBAA7B,GAAmDT,aAAnD;AACAF,MAAAA,4BAA4B,CAACoB,WAA7B,GAA2CC,yBAAYC,gBAAZ,CACvC,mBADuC,EAEvCtB,4BAA4B,CAACuB,WAFU,CAA3C;AAIA,WAAKC,oBAAL,GAA4BP,sBAASK,gBAAT,CAC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B,6BAkBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACW,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIX,4BAA4B,CAACW,mBAA7B,CAAiDgC,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA1BQ3C,4B,iBA4BY,MAAM;AACvB,MAAIA,4BAA4B,CAAC4C,uBAA7B,EAAJ,EAA4D;AACxD5C,IAAAA,4BAA4B,CAAC0B,iBAA7B,CACI1B,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQX,4B,sBA0MLgC,cADgD,IAE/C;AAAA;;AACD,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"]}
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,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACQ,iCADjC,EAEIC,gCAAaC,KAFjB;;AAIA;AACH;;AAED,QACIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BT,aAFjC,EAGE;AACEI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACY,mCADjC,EAEIH,gCAAaC,KAFjB;AAIH,KARD,MAQO,IAAIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAAxD,EAA8D;AACjEX,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD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ba,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"]}
@@ -83,6 +83,7 @@ export class DdRumReactNavigationTracking {
83
83
  if (key != null && screenName != null) {
84
84
  // On iOS, the app can start in either "active", "background" or "unknown" state
85
85
  if (appStateStatus !== 'background') {
86
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
86
87
  DdRum.startView(key, screenName);
87
88
  }
88
89
  }
@@ -94,10 +95,12 @@ export class DdRumReactNavigationTracking {
94
95
 
95
96
  if (key != null && screenName != null) {
96
97
  if (appStateStatus === 'background') {
98
+ DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';
97
99
  DdRum.stopView(key);
98
- } else if (appStateStatus === 'active') {
100
+ } else if (appStateStatus === 'active' && DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING') {
99
101
  // case when app goes into foreground,
100
102
  // in that case navigation listener won't be called
103
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
101
104
  DdRum.startView(key, screenName);
102
105
  }
103
106
  }
@@ -134,6 +137,8 @@ _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
134
137
 
135
138
  _defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
136
139
 
140
+ _defineProperty(DdRumReactNavigationTracking, "trackingState", 'NOT_TRACKING');
141
+
137
142
  _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
138
143
 
139
144
  _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
@@ -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","startView","handleAppStateChanged","stopView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,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,+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,CAAiD6B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA1BQtC,4B,iBA4BY,MAAM;AACvB,MAAIA,4BAA4B,CAACuC,uBAA7B,EAAJ,EAA4D;AACxDvC,IAAAA,4BAA4B,CAACsB,iBAA7B,CACItB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQT,4B,sBA0ML4B,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"]}
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,MA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C,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"]}
@@ -28,7 +28,7 @@ export declare class DdSdkReactNative {
28
28
  * @param configuration the configuration for the SDK library
29
29
  * @returns a Promise.
30
30
  */
31
- static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
31
+ static initialize: (configuration: DdSdkReactNativeConfiguration) => Promise<void>;
32
32
  private static initializeNativeSDK;
33
33
  /**
34
34
  * FOR INTERNAL USE ONLY.
@@ -48,19 +48,19 @@ export declare class DdSdkReactNative {
48
48
  * @param attributes: The global context attributes.
49
49
  * @returns a Promise.
50
50
  */
51
- static setAttributes(attributes: Attributes): Promise<void>;
51
+ static setAttributes: (attributes: Attributes) => Promise<void>;
52
52
  /**
53
53
  * Set the user information.
54
54
  * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
55
55
  * @returns a Promise.
56
56
  */
57
- static setUser(user: UserInfo): Promise<void>;
57
+ static setUser: (user: UserInfo) => Promise<void>;
58
58
  /**
59
59
  * Set the tracking consent regarding the data collection.
60
60
  * @param trackingConsent: One of TrackingConsent values.
61
61
  * @returns a Promise.
62
62
  */
63
- static setTrackingConsent(consent: TrackingConsent): Promise<void>;
63
+ static setTrackingConsent: (consent: TrackingConsent) => Promise<void>;
64
64
  private static buildConfiguration;
65
65
  private static enableFeatures;
66
66
  }
@@ -174,6 +174,18 @@ export declare class DdSdkReactNativeConfiguration {
174
174
  * number of sessions tracked and impact your billing.
175
175
  */
176
176
  trackBackgroundEvents: boolean;
177
+ /**
178
+ * Specifies a custom prop to name RUM actions on elements having an `onPress` prop.
179
+ *
180
+ * For example if you set it to `testID`, the value of the `testID` prop is used as a custom action name:
181
+ *
182
+ * ```js
183
+ * <TouchableOpacity testID="Dismiss notification" onPress={() => dismiss()}>
184
+ * ```
185
+ *
186
+ * `dd-action-name` is favored when both attributes are present on an element.
187
+ */
188
+ actionNameAttribute?: string;
177
189
  logEventMapper: LogEventMapper | null;
178
190
  errorEventMapper: ErrorEventMapper | null;
179
191
  resourceEventMapper: ResourceEventMapper | null;
@@ -197,6 +209,7 @@ export declare type AutoInstrumentationConfiguration = {
197
209
  readonly errorEventMapper?: ErrorEventMapper | null;
198
210
  readonly resourceEventMapper?: ResourceEventMapper | null;
199
211
  readonly actionEventMapper?: ActionEventMapper | null;
212
+ readonly actionNameAttribute?: string;
200
213
  };
201
214
  /**
202
215
  * Parameters needed to start auto instrumentation. Includes default values.
@@ -211,6 +224,7 @@ export declare type AutoInstrumentationParameters = {
211
224
  readonly errorEventMapper: ErrorEventMapper | null;
212
225
  readonly resourceEventMapper: ResourceEventMapper | null;
213
226
  readonly actionEventMapper: ActionEventMapper | null;
227
+ readonly actionNameAttribute?: string;
214
228
  };
215
229
  /**
216
230
  * We could use `Proxy` instead of this function, but `Proxy` is not available on
@@ -2,10 +2,10 @@ import type { DdLogsType, LogArguments, LogEventMapper, LogWithErrorArguments }
2
2
  declare class DdLogsWrapper implements DdLogsType {
3
3
  private nativeLogs;
4
4
  private logEventMapper;
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>;
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
9
  /**
10
10
  * Since the InternalLog does not have a verbosity set yet in this case,
11
11
  * we use console.warn to warn the user in dev mode.
@@ -1,3 +1,19 @@
1
+ import type { Spec as NativeDdLogs } from './specs/NativeDdLogs';
2
+ import type { Spec as NativeDdRum } from './specs/NativeDdRum';
3
+ import type { Spec as NativeDdSdk } from './specs/NativeDdSdk';
4
+ import type { Spec as NativeDdTrace } from './specs/NativeDdTrace';
5
+ /**
6
+ * In this file, native modules types extend the specs for TurboModules.
7
+ * As we cannot use enums or classes in the specs, we override methods using them here.
8
+ */
9
+ /**
10
+ * The entry point to use Datadog's Logs feature.
11
+ */
12
+ export declare type DdNativeLogsType = NativeDdLogs;
13
+ /**
14
+ * The entry point to use Datadog's Trace feature.
15
+ */
16
+ export declare type DdNativeTraceType = NativeDdTrace;
1
17
  /**
2
18
  * A configuration object to initialize Datadog's features.
3
19
  */
@@ -15,148 +31,20 @@ export declare class DdNativeSdkConfiguration {
15
31
  /**
16
32
  * The entry point to initialize Datadog's features.
17
33
  */
18
- export declare type DdNativeSdkType = {
34
+ export interface DdNativeSdkType extends NativeDdSdk {
19
35
  /**
20
36
  * Initializes Datadog's features.
21
37
  * @param configuration: The configuration to use.
22
38
  */
23
39
  initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
24
- /**
25
- * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
26
- * @param attributes: The global context attributes.
27
- */
28
- setAttributes(attributes: object): Promise<void>;
29
- /**
30
- * Set the user information.
31
- * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
32
- */
33
- setUser(user: object): Promise<object>;
34
- /**
35
- * Set the tracking consent regarding the data collection.
36
- * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
37
- */
38
- setTrackingConsent(trackingConsent: string): Promise<void>;
39
- /**
40
- * Sends internal telemetry debug message
41
- * @param message debug message
42
- */
43
- telemetryDebug(message: string): Promise<void>;
44
- /**
45
- * Sends internal telemetry error
46
- * @param message error message
47
- * @param stack error stack
48
- * @param kind error kind
49
- */
50
- telemetryError(message: string, stack: string, kind: string): Promise<void>;
51
- /**
52
- * Send webview telemetry logs
53
- * @param message event description
54
- */
55
- consumeWebviewEvent(message: string): Promise<void>;
56
- };
57
- /**
58
- * The entry point to use Datadog's Logs feature.
59
- */
60
- export declare type DdNativeLogsType = {
61
- /**
62
- * Send a log with DEBUG level.
63
- * @param message: The message to send.
64
- * @param context: The additional context to send.
65
- */
66
- debug(message: string, context?: object): Promise<void>;
67
- /**
68
- * Send a log with INFO level.
69
- * @param message: The message to send.
70
- * @param context: The additional context to send.
71
- */
72
- info(message: string, context?: object): Promise<void>;
73
- /**
74
- * Send a log with WARN level.
75
- * @param message: The message to send.
76
- * @param context: The additional context to send.
77
- */
78
- warn(message: string, context?: object): Promise<void>;
79
- /**
80
- * Send a log with ERROR level.
81
- * @param message: The message to send.
82
- * @param context: The additional context to send.
83
- */
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>;
121
- };
122
- /**
123
- * The entry point to use Datadog's Trace feature.
124
- */
125
- export declare type DdNativeTraceType = {
126
- /**
127
- * Start a span, and returns a unique identifier for the span.
128
- * @param operation: The operation name of the span.
129
- * @param context: The additional context to send.
130
- * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
131
- */
132
- startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
133
- /**
134
- * Finish a started span.
135
- * @param spanId: The unique identifier of the span.
136
- * @param context: The additional context to send.
137
- * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
138
- */
139
- finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
140
- };
40
+ }
41
+ declare type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
42
+ declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
43
+ declare type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
141
44
  /**
142
45
  * The entry point to use Datadog's RUM feature.
143
46
  */
144
- export declare type DdNativeRumType = {
145
- /**
146
- * Start tracking a RUM View.
147
- * @param key: The view unique key identifier.
148
- * @param name: The view name.
149
- * @param context: The additional context to send.
150
- * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
151
- */
152
- startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
153
- /**
154
- * Stop tracking a RUM View.
155
- * @param key: The view unique key identifier.
156
- * @param context: The additional context to send.
157
- * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
158
- */
159
- stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
47
+ export interface DdNativeRumType extends NativeDdRum {
160
48
  /**
161
49
  * Start tracking a RUM Action.
162
50
  * @param type: The action type (tap, scroll, swipe, back, custom).
@@ -164,7 +52,7 @@ export declare type DdNativeRumType = {
164
52
  * @param context: The additional context to send.
165
53
  * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
166
54
  */
167
- startAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
55
+ startAction(type: ActionType, name: string, context: object, timestampMs: number): Promise<void>;
168
56
  /**
169
57
  * Stop tracking the ongoing RUM Action.
170
58
  * @param type: The action type (tap, scroll, swipe, back, custom).
@@ -172,7 +60,7 @@ export declare type DdNativeRumType = {
172
60
  * @param context: The additional context to send.
173
61
  * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
174
62
  */
175
- stopAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
63
+ stopAction(type: ActionType, name: string, context: object, timestampMs: number): Promise<void>;
176
64
  /**
177
65
  * Add a RUM Action.
178
66
  * @param type: The action type (tap, scroll, swipe, back, custom).
@@ -180,16 +68,7 @@ export declare type DdNativeRumType = {
180
68
  * @param context: The additional context to send.
181
69
  * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
182
70
  */
183
- addAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
184
- /**
185
- * Start tracking a RUM Resource.
186
- * @param key: The resource unique key identifier.
187
- * @param method: The resource method (GET, POST, …).
188
- * @param url: The resource url.
189
- * @param context: The additional context to send.
190
- * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
191
- */
192
- startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
71
+ addAction(type: ActionType, name: string, context: object, timestampMs: number): Promise<void>;
193
72
  /**
194
73
  * Stop tracking a RUM Resource.
195
74
  * @param key: The resource unique key identifier.
@@ -199,7 +78,7 @@ export declare type DdNativeRumType = {
199
78
  * @param context: The additional context to send.
200
79
  * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
201
80
  */
202
- stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number): Promise<void>;
81
+ stopResource(key: string, statusCode: number, kind: ResourceKind, size: number, context: object, timestampMs: number): Promise<void>;
203
82
  /**
204
83
  * Add a RUM Error.
205
84
  * @param message: The error message.
@@ -208,25 +87,6 @@ export declare type DdNativeRumType = {
208
87
  * @param context: The additional context to send.
209
88
  * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
210
89
  */
211
- addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
212
- /**
213
- * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
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.
215
- */
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>;
228
- };
229
- declare type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
230
- declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
231
- declare type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
90
+ addError(message: string, source: ErrorSource, stacktrace: string, context: object, timestampMs: number): Promise<void>;
91
+ }
232
92
  export {};
@@ -9,24 +9,24 @@ declare class DdRumWrapper implements DdRumType {
9
9
  private errorEventMapper;
10
10
  private resourceEventMapper;
11
11
  private actionEventMapper;
12
- startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
13
- stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
14
- startAction(type: RumActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
15
- stopAction(...args: [
12
+ startView: (key: string, name: string, context?: object, timestampMs?: number) => Promise<void>;
13
+ stopView: (key: string, context?: object, timestampMs?: number) => Promise<void>;
14
+ startAction: (type: RumActionType, name: string, context?: object, timestampMs?: number) => Promise<void>;
15
+ stopAction: (...args: [
16
16
  type: RumActionType,
17
17
  name: string,
18
18
  context?: object,
19
19
  timestampMs?: number
20
- ] | [context?: object, timestampMs?: number]): Promise<void>;
20
+ ] | [context?: object, timestampMs?: number]) => Promise<void>;
21
21
  private callNativeStopAction;
22
22
  private getStopActionNativeCallArgs;
23
- addAction(type: RumActionType, name: string, context?: object, timestampMs?: number, actionContext?: GestureResponderEvent): Promise<void>;
24
- startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
25
- stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number, resourceContext?: XMLHttpRequest): Promise<void>;
26
- addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
27
- addTiming(name: string): Promise<void>;
28
- stopSession(): Promise<void>;
29
- addFeatureFlagEvaluation(name: string, value: unknown): Promise<void>;
23
+ addAction: (type: RumActionType, name: string, context?: object, timestampMs?: number, actionContext?: GestureResponderEvent) => Promise<void>;
24
+ startResource: (key: string, method: string, url: string, context?: object, timestampMs?: number) => Promise<void>;
25
+ stopResource: (key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number, resourceContext?: XMLHttpRequest) => Promise<void>;
26
+ addError: (message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number) => Promise<void>;
27
+ addTiming: (name: string) => Promise<void>;
28
+ stopSession: () => Promise<void>;
29
+ addFeatureFlagEvaluation: (name: string, value: unknown) => Promise<void>;
30
30
  registerErrorEventMapper(errorEventMapper: ErrorEventMapper): void;
31
31
  unregisterErrorEventMapper(): void;
32
32
  registerResourceEventMapper(resourceEventMapper: ResourceEventMapper): void;
@@ -5,16 +5,16 @@ declare type RawError = {
5
5
  message: string;
6
6
  source: ErrorSource;
7
7
  stacktrace: string;
8
- context?: object;
9
- timestampMs?: number;
8
+ context: object;
9
+ timestampMs: number;
10
10
  };
11
11
  declare type ErrorEvent = RawError & AdditionalEventDataForMapper;
12
12
  declare type NativeError = {
13
13
  message: string;
14
14
  source: ErrorSource;
15
15
  stacktrace: string;
16
- context?: object;
17
- timestampMs?: number;
16
+ context: object;
17
+ timestampMs: number;
18
18
  };
19
19
  export declare type ErrorEventMapper = (event: ErrorEvent) => ErrorEvent | null;
20
20
  export declare const generateErrorEventMapper: (eventMapper: ErrorEventMapper | undefined) => EventMapper<RawError, ErrorEvent, NativeError>;
@@ -3,6 +3,10 @@ export declare const UNKNOWN_TARGET_NAME = "unknown_target";
3
3
  export declare class DdEventsInterceptor implements EventsInterceptor {
4
4
  static ACTION_EVENT_DROPPED_DEBUG_MESSAGE: string;
5
5
  private debouncingStartedTimestamp;
6
+ private actionNameAttribute?;
7
+ constructor({ actionNameAttribute }?: {
8
+ actionNameAttribute?: string;
9
+ });
6
10
  interceptOnPress(...args: any[]): void;
7
11
  private handleTargetEvent;
8
12
  private resolveTargetName;
@@ -14,6 +14,8 @@ export declare class DdRumUserInteractionTracking {
14
14
  * Please note that we are only considering as valid - for - tracking only the user interactions that have
15
15
  * a visible output (either an UI state change or a Resource request)
16
16
  */
17
- static startTracking(): void;
17
+ static startTracking({ actionNameAttribute }?: {
18
+ actionNameAttribute?: string;
19
+ }): void;
18
20
  static stopTracking(): void;
19
21
  }
@@ -0,0 +1,69 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * Do not import this Spec directly, use DdNativeLogsType instead.
4
+ */
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+ /**
8
+ * Send a log with DEBUG level.
9
+ * @param message: The message to send.
10
+ * @param context: The additional context to send.
11
+ */
12
+ readonly debug: (message: string, context?: Object) => Promise<void>;
13
+ /**
14
+ * Send a log with INFO level.
15
+ * @param message: The message to send.
16
+ * @param context: The additional context to send.
17
+ */
18
+ readonly info: (message: string, context?: Object) => Promise<void>;
19
+ /**
20
+ * Send a log with WARN level.
21
+ * @param message: The message to send.
22
+ * @param context: The additional context to send.
23
+ */
24
+ readonly warn: (message: string, context?: Object) => Promise<void>;
25
+ /**
26
+ * Send a log with ERROR level.
27
+ * @param message: The message to send.
28
+ * @param context: The additional context to send.
29
+ */
30
+ readonly error: (message: string, context?: Object) => Promise<void>;
31
+ /**
32
+ * Send a log containing an error with DEBUG level.
33
+ * @param message: The message to send.
34
+ * @param errorKind: The error kind to send.
35
+ * @param errorMessage: The error message to send.
36
+ * @param stacktrace: The stack trace to send.
37
+ * @param context: The additional context to send.
38
+ */
39
+ readonly debugWithError: (message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: Object) => Promise<void>;
40
+ /**
41
+ * Send a log containing an error with INDO level.
42
+ * @param message: The message to send.
43
+ * @param errorKind: The error kind to send.
44
+ * @param errorMessage: The error message to send.
45
+ * @param stacktrace: The stack trace to send.
46
+ * @param context: The additional context to send.
47
+ */
48
+ readonly infoWithError: (message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: Object) => Promise<void>;
49
+ /**
50
+ * Send a log containing an error with WARN level.
51
+ * @param message: The message to send.
52
+ * @param errorKind: The error kind to send.
53
+ * @param errorMessage: The error message to send.
54
+ * @param stacktrace: The stack trace to send.
55
+ * @param context: The additional context to send.
56
+ */
57
+ readonly warnWithError: (message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: Object) => Promise<void>;
58
+ /**
59
+ * Send a log containing an error with ERROR level.
60
+ * @param message: The message to send.
61
+ * @param errorKind: The error kind to send.
62
+ * @param errorMessage: The error message to send.
63
+ * @param stacktrace: The stack trace to send.
64
+ * @param context: The additional context to send.
65
+ */
66
+ readonly errorWithError: (message: string, errorKind?: string, errorMessage?: string, stacktrace?: string, context?: Object) => Promise<void>;
67
+ }
68
+ declare const _default: Spec | null;
69
+ export default _default;
@@ -0,0 +1,92 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * Do not import this Spec directly, use DdNativeRumType instead.
4
+ */
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+ /**
8
+ * Start tracking a RUM View.
9
+ * @param key: The view unique key identifier.
10
+ * @param name: The view name.
11
+ * @param context: The additional context to send.
12
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
13
+ */
14
+ startView(key: string, name: string, context: Object, timestampMs: number): Promise<void>;
15
+ /**
16
+ * Stop tracking a RUM View.
17
+ * @param key: The view unique key identifier.
18
+ * @param context: The additional context to send.
19
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
20
+ */
21
+ stopView(key: string, context: Object, timestampMs: number): Promise<void>;
22
+ /**
23
+ * Start tracking a RUM Action.
24
+ * @param type: The action type (tap, scroll, swipe, back, custom).
25
+ * @param name: The action name.
26
+ * @param context: The additional context to send.
27
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
28
+ */
29
+ startAction(type: string, name: string, context: Object, timestampMs: number): Promise<void>;
30
+ /**
31
+ * Stop tracking the ongoing RUM Action.
32
+ * @param type: The action type (tap, scroll, swipe, back, custom).
33
+ * @param name: The action name.
34
+ * @param context: The additional context to send.
35
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
36
+ */
37
+ stopAction(type: string, name: string, context: Object, timestampMs: number): Promise<void>;
38
+ /**
39
+ * Add a RUM Action.
40
+ * @param type: The action type (tap, scroll, swipe, back, custom).
41
+ * @param name: The action name.
42
+ * @param context: The additional context to send.
43
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
44
+ */
45
+ addAction(type: string, name: string, context: Object, timestampMs: number): Promise<void>;
46
+ /**
47
+ * Start tracking a RUM Resource.
48
+ * @param key: The resource unique key identifier.
49
+ * @param method: The resource method (GET, POST, …).
50
+ * @param url: The resource url.
51
+ * @param context: The additional context to send.
52
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
53
+ */
54
+ startResource(key: string, method: string, url: string, context: Object, timestampMs: number): Promise<void>;
55
+ /**
56
+ * Stop tracking a RUM Resource.
57
+ * @param key: The resource unique key identifier.
58
+ * @param statusCode: The resource status code.
59
+ * @param kind: The resource's kind (xhr, document, image, css, font, …).
60
+ * @param size: The resource size in bytes. If size is unknown, use -1.
61
+ * @param context: The additional context to send.
62
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
63
+ */
64
+ stopResource(key: string, statusCode: number, kind: string, size: number, context: Object, timestampMs: number): Promise<void>;
65
+ /**
66
+ * Add a RUM Error.
67
+ * @param message: The error message.
68
+ * @param source: The error source (network, source, console, webview, custom).
69
+ * @param stacktrace: The error stacktrace.
70
+ * @param context: The additional context to send.
71
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
72
+ */
73
+ addError(message: string, source: string, stacktrace: string, context: Object, timestampMs: number): Promise<void>;
74
+ /**
75
+ * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
76
+ * @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.
77
+ */
78
+ addTiming(name: string): Promise<void>;
79
+ /**
80
+ * Stops the current RUM Session.
81
+ */
82
+ stopSession(): Promise<void>;
83
+ /**
84
+ * Adds the result of evaluating a feature flag with a given name and value to the view.
85
+ * Feature flag evaluations are local to the active view and are cleared when the view is stopped.
86
+ * @param name: The name of the feature flag
87
+ * @param value: The value of the feature flag, encapsulated in an Object to accept all types
88
+ */
89
+ addFeatureFlagEvaluation(name: string, value: Object): Promise<void>;
90
+ }
91
+ declare const _default: Spec | null;
92
+ export default _default;
@@ -0,0 +1,46 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * Do not import this Spec directly, use DdNativeSdkType instead.
4
+ */
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+ /**
8
+ * Initializes Datadog's features.
9
+ * @param configuration: The configuration to use.
10
+ */
11
+ initialize(configuration: Object): Promise<void>;
12
+ /**
13
+ * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
14
+ * @param attributes: The global context attributes.
15
+ */
16
+ setAttributes(attributes: Object): Promise<void>;
17
+ /**
18
+ * Set the user information.
19
+ * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
20
+ */
21
+ setUser(user: Object): Promise<Object>;
22
+ /**
23
+ * Set the tracking consent regarding the data collection.
24
+ * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
25
+ */
26
+ setTrackingConsent(trackingConsent: string): Promise<void>;
27
+ /**
28
+ * Sends internal telemetry debug message
29
+ * @param message debug message
30
+ */
31
+ telemetryDebug(message: string): Promise<void>;
32
+ /**
33
+ * Sends internal telemetry error
34
+ * @param message error message
35
+ * @param stack error stack
36
+ * @param kind error kind
37
+ */
38
+ telemetryError(message: string, stack: string, kind: string): Promise<void>;
39
+ /**
40
+ * Send webview telemetry logs
41
+ * @param message event description
42
+ */
43
+ consumeWebviewEvent(message: string): Promise<void>;
44
+ }
45
+ declare const _default: Spec | null;
46
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * Do not import this Spec directly, use DdNativeTraceType instead.
4
+ */
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+ /**
8
+ * Start a span, and returns a unique identifier for the span.
9
+ * @param operation: The operation name of the span.
10
+ * @param context: The additional context to send.
11
+ * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
12
+ */
13
+ startSpan(operation: string, context: Object, timestampMs: number): Promise<string>;
14
+ /**
15
+ * Finish a started span.
16
+ * @param spanId: The unique identifier of the span.
17
+ * @param context: The additional context to send.
18
+ * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
19
+ */
20
+ finishSpan(spanId: string, context: Object, timestampMs: number): Promise<void>;
21
+ }
22
+ declare const _default: Spec | null;
23
+ export default _default;
@@ -1 +1 @@
1
- export declare const version = "1.7.1";
1
+ export declare const version = "1.8.0-rc0";
@@ -9,6 +9,7 @@ export declare class DdRumReactNavigationTracking {
9
9
  private static viewNamePredicate;
10
10
  private static backHandler;
11
11
  private static appStateSubscription?;
12
+ private static trackingState;
12
13
  static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE: string;
13
14
  static NULL_NAVIGATION_REF_ERROR_MESSAGE: string;
14
15
  static NAVIGATION_REF_IN_USE_ERROR_MESSAGE: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.7.1",
3
+ "version": "1.8.0-rc0",
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.7.1",
39
+ "@datadog/mobile-react-native": "^1.8.0-rc0",
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": "fc56f843fcd9d218be684ac52a1be8d2c31e455c"
80
+ "gitHead": "ddc6223ac9ac6b2d03884db91d1ce22e8c68f756"
81
81
  }
@@ -495,6 +495,66 @@ describe.each([
495
495
  expect(DdRum.startView).toHaveBeenCalledTimes(2);
496
496
  });
497
497
 
498
+ /**
499
+ * This is a typical scenario when apps go inactive: a call prompt is displayed which
500
+ * makes the app inactive.
501
+ * Taking the call makes the app go into background, then it comes back in the foreground
502
+ * when the call has ended.
503
+ */
504
+ it('restarts last view when app goes inactive, then background then active', async () => {
505
+ // GIVEN
506
+ const navigationRef = createRef<any>();
507
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
508
+
509
+ DdRumReactNavigationTracking.startTrackingViews(
510
+ navigationRef.current
511
+ );
512
+ expect(DdRum.startView).toHaveBeenCalledTimes(1);
513
+
514
+ // WHEN
515
+ appStateMock.changeValue('inactive');
516
+ appStateMock.changeValue('background');
517
+ appStateMock.changeValue('inactive');
518
+ appStateMock.changeValue('active');
519
+
520
+ // THEN
521
+ expect(DdRum.stopView).toHaveBeenCalledTimes(1);
522
+ expect(DdRum.startView).toHaveBeenCalledTimes(2);
523
+ });
524
+
525
+ it('does not create a new view if the appState transitions to active after registration of route', async () => {
526
+ // GIVEN
527
+ const navigationRef = createRef<any>();
528
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
529
+
530
+ DdRumReactNavigationTracking.startTrackingViews(
531
+ navigationRef.current
532
+ );
533
+
534
+ // WHEN
535
+ appStateMock.changeValue('active');
536
+
537
+ // THEN
538
+ expect(DdRum.startView).toHaveBeenCalledTimes(1);
539
+ });
540
+
541
+ it('does not create a new view if the appState transitions to active after inactive', async () => {
542
+ // GIVEN
543
+ const navigationRef = createRef<any>();
544
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
545
+
546
+ DdRumReactNavigationTracking.startTrackingViews(
547
+ navigationRef.current
548
+ );
549
+
550
+ // WHEN
551
+ appStateMock.changeValue('inactive');
552
+ appStateMock.changeValue('active');
553
+
554
+ // THEN
555
+ expect(DdRum.startView).toHaveBeenCalledTimes(1);
556
+ });
557
+
498
558
  it('does not stop view when no navigator attached', async () => {
499
559
  // GIVEN
500
560
  const navigationRef = createRef<any>();
@@ -549,7 +609,7 @@ describe.each([
549
609
 
550
610
  // Note: currently iOS apps start in "unknown" app state, but should default to "inactive"
551
611
  it.each(['unknown', 'inactive'])(
552
- 'creates 2 RUM Views when the app starts in %s then becomes active',
612
+ 'creates only 1 RUM View when the app starts in %s then becomes active',
553
613
  async initialAppState => {
554
614
  // GIVEN
555
615
  appStateMock.changeValue(initialAppState);
@@ -566,7 +626,7 @@ describe.each([
566
626
  appStateMock.changeValue('active');
567
627
 
568
628
  // THEN
569
- expect(DdRum.startView).toHaveBeenCalledTimes(2);
629
+ expect(DdRum.startView).toHaveBeenCalledTimes(1);
570
630
  }
571
631
  );
572
632
  }
@@ -41,6 +41,8 @@ export class DdRumReactNavigationTracking {
41
41
 
42
42
  private static appStateSubscription?: NativeEventSubscription;
43
43
 
44
+ private static trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';
45
+
44
46
  static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =
45
47
  'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';
46
48
  static NULL_NAVIGATION_REF_ERROR_MESSAGE =
@@ -181,6 +183,7 @@ export class DdRumReactNavigationTracking {
181
183
  if (key != null && screenName != null) {
182
184
  // On iOS, the app can start in either "active", "background" or "unknown" state
183
185
  if (appStateStatus !== 'background') {
186
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
184
187
  DdRum.startView(key, screenName);
185
188
  }
186
189
  }
@@ -198,10 +201,15 @@ export class DdRumReactNavigationTracking {
198
201
 
199
202
  if (key != null && screenName != null) {
200
203
  if (appStateStatus === 'background') {
204
+ DdRumReactNavigationTracking.trackingState = 'NOT_TRACKING';
201
205
  DdRum.stopView(key);
202
- } else if (appStateStatus === 'active') {
206
+ } else if (
207
+ appStateStatus === 'active' &&
208
+ DdRumReactNavigationTracking.trackingState === 'NOT_TRACKING'
209
+ ) {
203
210
  // case when app goes into foreground,
204
211
  // in that case navigation listener won't be called
212
+ DdRumReactNavigationTracking.trackingState = 'TRACKING';
205
213
  DdRum.startView(key, screenName);
206
214
  }
207
215
  }