@datadog/mobile-react-navigation 2.14.1 → 3.0.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.
- package/README.md +40 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +128 -65
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/utils.js +31 -0
- package/lib/commonjs/rum/instrumentation/utils.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +127 -64
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/utils.js +25 -0
- package/lib/module/rum/instrumentation/utils.js.map +1 -0
- package/lib/typescript/core/src/DdAttributes.d.ts.map +1 -0
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +49 -12
- package/lib/typescript/core/src/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/core/src/InternalLog.d.ts +1 -1
- package/lib/typescript/core/src/InternalLog.d.ts.map +1 -1
- package/lib/typescript/core/src/config/DatadogProviderConfiguration.d.ts +12 -0
- package/lib/typescript/core/src/config/DatadogProviderConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.d.ts +17 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts +52 -0
- package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts.map +1 -0
- package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts +60 -0
- package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts +47 -0
- package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/async/asyncInitializationHelper.d.ts +5 -0
- package/lib/typescript/core/src/config/async/asyncInitializationHelper.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/CoreConfiguration.d.ts +52 -0
- package/lib/typescript/core/src/config/features/CoreConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/CoreConfiguration.type.d.ts +90 -0
- package/lib/typescript/core/src/config/features/CoreConfiguration.type.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/CoreConfigurationNative.d.ts +54 -0
- package/lib/typescript/core/src/config/features/CoreConfigurationNative.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/LogsConfiguration.d.ts +17 -0
- package/lib/typescript/core/src/config/features/LogsConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/LogsConfiguration.type.d.ts +24 -0
- package/lib/typescript/core/src/config/features/LogsConfiguration.type.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/LogsConfigurationNative.d.ts +6 -0
- package/lib/typescript/core/src/config/features/LogsConfigurationNative.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.d.ts +66 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts +131 -0
- package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts +25 -0
- package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/TraceConfiguration.d.ts +10 -0
- package/lib/typescript/core/src/config/features/TraceConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/TraceConfiguration.type.d.ts +11 -0
- package/lib/typescript/core/src/config/features/TraceConfiguration.type.d.ts.map +1 -0
- package/lib/typescript/core/src/config/features/TraceConfigurationNative.d.ts +4 -0
- package/lib/typescript/core/src/config/features/TraceConfigurationNative.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/BatchProcessingLevel.d.ts +18 -0
- package/lib/typescript/core/src/config/types/BatchProcessingLevel.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/BatchSize.d.ts +19 -0
- package/lib/typescript/core/src/config/types/BatchSize.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/InitializationMode.d.ts +5 -0
- package/lib/typescript/core/src/config/types/InitializationMode.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/InitializationModeForTelemetry.d.ts +2 -0
- package/lib/typescript/core/src/config/types/InitializationModeForTelemetry.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/ProxyConfiguration.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/SdkVerbosity.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/TrackingConsent.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/UploadFrequency.d.ts +18 -0
- package/lib/typescript/core/src/config/types/UploadFrequency.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/VitalsUpdateFrequency.d.ts +7 -0
- package/lib/typescript/core/src/config/types/VitalsUpdateFrequency.d.ts.map +1 -0
- package/lib/typescript/core/src/config/types/index.d.ts +10 -0
- package/lib/typescript/core/src/config/types/index.d.ts.map +1 -0
- package/lib/typescript/core/src/index.d.ts +20 -9
- package/lib/typescript/core/src/index.d.ts.map +1 -1
- package/lib/typescript/core/src/logs/DdLogs.d.ts +2 -1
- package/lib/typescript/core/src/logs/DdLogs.d.ts.map +1 -1
- package/lib/typescript/core/src/logs/eventMapper.d.ts +3 -2
- package/lib/typescript/core/src/logs/eventMapper.d.ts.map +1 -1
- package/lib/typescript/core/src/logs/types.d.ts +1 -16
- package/lib/typescript/core/src/logs/types.d.ts.map +1 -1
- package/lib/typescript/core/src/nativeModulesTypes.d.ts +2 -15
- package/lib/typescript/core/src/nativeModulesTypes.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/DdRum.d.ts +10 -1
- package/lib/typescript/core/src/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/eventMappers/errorEventMapper.d.ts +1 -1
- package/lib/typescript/core/src/rum/eventMappers/errorEventMapper.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/helper.d.ts +10 -0
- package/lib/typescript/core/src/rum/helper.d.ts.map +1 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts +6 -6
- package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +7 -0
- package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +12 -6
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts +1 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +5 -17
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingAttributes.d.ts +20 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingAttributes.d.ts.map +1 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +3 -24
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingSampling.d.ts +12 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingSampling.d.ts.map +1 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/headers.d.ts +24 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/distributedTracing/headers.d.ts.map +1 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +2 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
- package/lib/typescript/core/src/rum/types.d.ts +47 -7
- package/lib/typescript/core/src/rum/types.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts +15 -0
- package/lib/typescript/core/src/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AccountInfoSingleton/types.d.ts +6 -0
- package/lib/typescript/core/src/sdk/AccountInfoSingleton/types.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/attributesEncoding.d.ts +13 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/attributesEncoding.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/defaultEncoders.d.ts +33 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/defaultEncoders.d.ts.map +1 -0
- package/lib/typescript/core/src/{utils → sdk/AttributesEncoding}/errorUtils.d.ts +4 -4
- package/lib/typescript/core/src/sdk/AttributesEncoding/errorUtils.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/helpers.d.ts +17 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/helpers.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/types.d.ts +21 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/types.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/utils.d.ts +7 -0
- package/lib/typescript/core/src/sdk/AttributesEncoding/utils.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/AttributesSingleton/AttributesSingleton.d.ts +5 -1
- package/lib/typescript/core/src/sdk/AttributesSingleton/AttributesSingleton.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/DatadogProvider/DatadogProvider.d.ts +4 -3
- package/lib/typescript/core/src/sdk/DatadogProvider/DatadogProvider.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/DatadogProvider/DatadogProviderState.d.ts +9 -0
- package/lib/typescript/core/src/sdk/DatadogProvider/DatadogProviderState.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/DdSdk.d.ts +2 -3
- package/lib/typescript/core/src/sdk/DdSdk.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/DdSdkInternal.d.ts +39 -0
- package/lib/typescript/core/src/sdk/DdSdkInternal.d.ts.map +1 -0
- package/lib/typescript/core/src/sdk/EventMappers/EventMapper.d.ts +3 -1
- package/lib/typescript/core/src/sdk/EventMappers/EventMapper.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/GlobalState/GlobalState.d.ts +3 -3
- package/lib/typescript/core/src/sdk/GlobalState/GlobalState.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +2 -1
- package/lib/typescript/core/src/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
- package/lib/typescript/core/src/sdk/UserInfoSingleton/types.d.ts +1 -2
- package/lib/typescript/core/src/sdk/UserInfoSingleton/types.d.ts.map +1 -1
- package/lib/typescript/core/src/specs/NativeDdRum.d.ts +45 -0
- package/lib/typescript/core/src/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/core/src/specs/NativeDdSdk.d.ts +34 -6
- package/lib/typescript/core/src/specs/NativeDdSdk.d.ts.map +1 -1
- package/lib/typescript/core/src/trace/DdTrace.d.ts +1 -2
- package/lib/typescript/core/src/trace/DdTrace.d.ts.map +1 -1
- package/lib/typescript/core/src/types.d.ts +74 -92
- package/lib/typescript/core/src/types.d.ts.map +1 -1
- package/lib/typescript/core/src/utils/longTasksUtils.d.ts +1 -1
- package/lib/typescript/core/src/utils/longTasksUtils.d.ts.map +1 -1
- package/lib/typescript/core/src/utils/singletonUtils.d.ts +2 -0
- package/lib/typescript/core/src/utils/singletonUtils.d.ts.map +1 -0
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/core/src/version.d.ts.map +1 -1
- package/lib/typescript/react-navigation/src/index.d.ts +2 -2
- package/lib/typescript/react-navigation/src/index.d.ts.map +1 -1
- package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +41 -24
- package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts.map +1 -1
- package/lib/typescript/react-navigation/src/rum/instrumentation/utils.d.ts +13 -0
- package/lib/typescript/react-navigation/src/rum/instrumentation/utils.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +147 -14
- package/src/index.tsx +12 -2
- package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +168 -101
- package/src/rum/instrumentation/utils.ts +28 -0
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +0 -376
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts.map +0 -1
- package/lib/typescript/core/src/ProxyConfiguration.d.ts.map +0 -1
- package/lib/typescript/core/src/SdkVerbosity.d.ts.map +0 -1
- package/lib/typescript/core/src/TrackingConsent.d.ts.map +0 -1
- package/lib/typescript/core/src/rum/DdAttributes.d.ts.map +0 -1
- package/lib/typescript/core/src/rum/sessionId/sessionIdHelper.d.ts +0 -4
- package/lib/typescript/core/src/rum/sessionId/sessionIdHelper.d.ts.map +0 -1
- package/lib/typescript/core/src/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +0 -34
- package/lib/typescript/core/src/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts.map +0 -1
- package/lib/typescript/core/src/utils/argsUtils.d.ts +0 -8
- package/lib/typescript/core/src/utils/argsUtils.d.ts.map +0 -1
- package/lib/typescript/core/src/utils/errorUtils.d.ts.map +0 -1
- /package/lib/typescript/core/src/{rum/DdAttributes.d.ts → DdAttributes.d.ts} +0 -0
- /package/lib/typescript/core/src/{ProxyConfiguration.d.ts → config/types/ProxyConfiguration.d.ts} +0 -0
- /package/lib/typescript/core/src/{SdkVerbosity.d.ts → config/types/SdkVerbosity.d.ts} +0 -0
- /package/lib/typescript/core/src/{TrackingConsent.d.ts → config/types/TrackingConsent.d.ts} +0 -0
|
@@ -15,6 +15,20 @@ import type {
|
|
|
15
15
|
Route,
|
|
16
16
|
NavigationListener
|
|
17
17
|
} from './react-navigation';
|
|
18
|
+
import { transformViewKey } from './utils';
|
|
19
|
+
|
|
20
|
+
const REACT_NAVIGATION_TRACKING_MODULE =
|
|
21
|
+
'com.datadog.reactnative.rum.react_navigation_tracking';
|
|
22
|
+
|
|
23
|
+
function getGlobalInstance<T>(key: string, objectConstructor: () => T): T {
|
|
24
|
+
const symbol = Symbol.for(key);
|
|
25
|
+
const g = (globalThis as unknown) as Record<PropertyKey, unknown>;
|
|
26
|
+
|
|
27
|
+
if (!(symbol in g)) {
|
|
28
|
+
g[symbol] = objectConstructor();
|
|
29
|
+
}
|
|
30
|
+
return g[symbol] as T;
|
|
31
|
+
}
|
|
18
32
|
|
|
19
33
|
// AppStateStatus can have values:
|
|
20
34
|
// 'active' - The app is running in the foreground
|
|
@@ -24,17 +38,53 @@ import type {
|
|
|
24
38
|
// 'extension' [iOS] - The app is running as an app extension
|
|
25
39
|
declare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;
|
|
26
40
|
|
|
41
|
+
export type NavigationTrackingOptions = {
|
|
42
|
+
viewNamePredicate?: ViewNamePredicate;
|
|
43
|
+
viewTrackingPredicate?: ViewTrackingPredicate;
|
|
44
|
+
paramsTrackingPredicate?: ParamsTrackingPredicate;
|
|
45
|
+
};
|
|
46
|
+
|
|
27
47
|
export type ViewNamePredicate = (
|
|
28
48
|
route: Route<string, any | undefined>,
|
|
29
49
|
trackedName: string
|
|
30
50
|
) => string | null;
|
|
31
51
|
|
|
52
|
+
export type ViewTrackingPredicate = (
|
|
53
|
+
route: Route<string, any | undefined>
|
|
54
|
+
) => boolean;
|
|
55
|
+
|
|
56
|
+
export type ParamsTrackingPredicate = (
|
|
57
|
+
route: Route<string, any | undefined>
|
|
58
|
+
) => object | undefined;
|
|
59
|
+
|
|
60
|
+
function defaultViewNamePredicate(
|
|
61
|
+
_route: Route<string, any | undefined>,
|
|
62
|
+
trackedName: string
|
|
63
|
+
) {
|
|
64
|
+
return trackedName;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function defaultParamsPredicate(_route: Route<string, any | undefined>) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function defaultViewTrackingPredicate(_route: Route<string, any | undefined>) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
32
75
|
/**
|
|
33
76
|
* Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
|
|
34
77
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
78
|
+
class RumReactNavigationTracking {
|
|
79
|
+
readonly ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =
|
|
80
|
+
'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';
|
|
81
|
+
readonly NULL_NAVIGATION_REF_ERROR_MESSAGE =
|
|
82
|
+
'Cannot track views with a null navigationRef.';
|
|
83
|
+
readonly NAVIGATION_REF_IN_USE_ERROR_MESSAGE =
|
|
84
|
+
'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';
|
|
85
|
+
|
|
86
|
+
private _navigationTimeline?: NavigationTimeline;
|
|
87
|
+
private get navigationTimeline(): NavigationTimeline | undefined {
|
|
38
88
|
if (!this.__INTERNAL._enableNavigationTimeline) {
|
|
39
89
|
return undefined;
|
|
40
90
|
}
|
|
@@ -44,36 +94,31 @@ export class DdRumReactNavigationTracking {
|
|
|
44
94
|
return this._navigationTimeline;
|
|
45
95
|
}
|
|
46
96
|
|
|
47
|
-
private
|
|
97
|
+
private registeredContainer: NavigationContainerRef | null = null;
|
|
48
98
|
|
|
49
|
-
private
|
|
99
|
+
private navigationStateChangeListener: NavigationListener | null = null;
|
|
50
100
|
|
|
51
|
-
private
|
|
101
|
+
private previousRoute: string | object | undefined = undefined;
|
|
52
102
|
|
|
53
|
-
private
|
|
103
|
+
private viewNamePredicate: ViewNamePredicate = defaultViewNamePredicate;
|
|
104
|
+
private viewTrackingPredicate: ViewTrackingPredicate = defaultViewTrackingPredicate;
|
|
105
|
+
private paramsTrackingPredicate: ParamsTrackingPredicate = defaultParamsPredicate;
|
|
54
106
|
|
|
55
|
-
private
|
|
107
|
+
private backHandler: NativeEventSubscription | null = null;
|
|
56
108
|
|
|
57
|
-
private
|
|
109
|
+
private appStateSubscription?: NativeEventSubscription;
|
|
58
110
|
|
|
59
|
-
private
|
|
111
|
+
private previousAppState: AppStateStatus | undefined;
|
|
60
112
|
|
|
61
|
-
private
|
|
113
|
+
private previousRouteKey: string | undefined;
|
|
62
114
|
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =
|
|
66
|
-
'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';
|
|
67
|
-
static NULL_NAVIGATION_REF_ERROR_MESSAGE =
|
|
68
|
-
'Cannot track views with a null navigationRef.';
|
|
69
|
-
static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =
|
|
70
|
-
'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';
|
|
115
|
+
private trackingState: 'TRACKING' | 'NOT_TRACKING' = 'NOT_TRACKING';
|
|
71
116
|
|
|
72
117
|
/**
|
|
73
118
|
* @internal
|
|
74
119
|
* DO NOT USE: This API is for internal testing only.
|
|
75
120
|
*/
|
|
76
|
-
|
|
121
|
+
__INTERNAL = {
|
|
77
122
|
/**
|
|
78
123
|
* @internal
|
|
79
124
|
* DO NOT USE: This API is for internal testing only.
|
|
@@ -88,21 +133,19 @@ export class DdRumReactNavigationTracking {
|
|
|
88
133
|
}
|
|
89
134
|
};
|
|
90
135
|
|
|
91
|
-
|
|
92
|
-
if (
|
|
136
|
+
isAppExitingOnBackPress = (): boolean => {
|
|
137
|
+
if (this.registeredContainer === null) {
|
|
93
138
|
return false;
|
|
94
139
|
}
|
|
95
|
-
if (
|
|
140
|
+
if (this.registeredContainer.canGoBack()) {
|
|
96
141
|
return false;
|
|
97
142
|
}
|
|
98
143
|
return true;
|
|
99
144
|
};
|
|
100
145
|
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
DdRumReactNavigationTracking.registeredContainer
|
|
105
|
-
);
|
|
146
|
+
onBackPress = () => {
|
|
147
|
+
if (this.isAppExitingOnBackPress()) {
|
|
148
|
+
this.stopTrackingViews(this.registeredContainer);
|
|
106
149
|
}
|
|
107
150
|
// We always return false so we make sure the react-navigation callback is called.
|
|
108
151
|
// See https://reactnative.dev/docs/backhandler
|
|
@@ -112,50 +155,63 @@ export class DdRumReactNavigationTracking {
|
|
|
112
155
|
/**
|
|
113
156
|
* Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
|
|
114
157
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
158
|
+
* @param trackingOptions the options object defining how views will be tracked. It contains:
|
|
159
|
+
* viewNamePredicate: the predicate to rename views.
|
|
160
|
+
* viewTrackingPredicate: the predicate to determine if a view should be tracked or not.
|
|
161
|
+
* paramsTrackingPredicate: the predicate to determine which parameters should be tracked for a given view.
|
|
115
162
|
*/
|
|
116
|
-
|
|
163
|
+
startTrackingViews(
|
|
117
164
|
navigationRef: NavigationContainerRef | null,
|
|
118
|
-
|
|
119
|
-
// eslint-disable-next-line func-names
|
|
120
|
-
viewNamePredicate: ViewNamePredicate = function (
|
|
121
|
-
_route: Route<string, any | undefined>,
|
|
122
|
-
trackedName: string
|
|
123
|
-
) {
|
|
124
|
-
return trackedName;
|
|
125
|
-
}
|
|
165
|
+
trackingOptions?: NavigationTrackingOptions
|
|
126
166
|
): void {
|
|
127
167
|
this.navigationTimeline?.addStartTrackingEvent();
|
|
128
168
|
|
|
169
|
+
const {
|
|
170
|
+
viewNamePredicate = defaultViewNamePredicate,
|
|
171
|
+
viewTrackingPredicate = defaultViewTrackingPredicate,
|
|
172
|
+
paramsTrackingPredicate = defaultParamsPredicate
|
|
173
|
+
} = trackingOptions ?? {};
|
|
174
|
+
|
|
129
175
|
if (navigationRef == null) {
|
|
130
176
|
InternalLog.log(
|
|
131
|
-
|
|
177
|
+
this.NULL_NAVIGATION_REF_ERROR_MESSAGE,
|
|
132
178
|
SdkVerbosity.ERROR
|
|
133
179
|
);
|
|
134
180
|
return;
|
|
135
181
|
}
|
|
136
182
|
|
|
137
183
|
if (
|
|
138
|
-
|
|
184
|
+
this.registeredContainer != null &&
|
|
139
185
|
this.registeredContainer !== navigationRef
|
|
140
186
|
) {
|
|
141
187
|
InternalLog.log(
|
|
142
|
-
|
|
188
|
+
this.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,
|
|
143
189
|
SdkVerbosity.ERROR
|
|
144
190
|
);
|
|
145
|
-
} else if (
|
|
146
|
-
|
|
147
|
-
|
|
191
|
+
} else if (this.registeredContainer == null) {
|
|
192
|
+
if (viewNamePredicate) {
|
|
193
|
+
this.viewNamePredicate = viewNamePredicate;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (viewTrackingPredicate) {
|
|
197
|
+
this.viewTrackingPredicate = viewTrackingPredicate;
|
|
198
|
+
}
|
|
148
199
|
|
|
149
|
-
|
|
200
|
+
if (paramsTrackingPredicate) {
|
|
201
|
+
this.paramsTrackingPredicate = paramsTrackingPredicate;
|
|
202
|
+
}
|
|
203
|
+
this.registeredContainer = navigationRef;
|
|
204
|
+
|
|
205
|
+
const listener = this.resolveNavigationStateChangeListener();
|
|
150
206
|
navigationRef.addListener('state', listener);
|
|
151
207
|
|
|
152
|
-
|
|
208
|
+
this.backHandler = BackHandler.addEventListener(
|
|
153
209
|
'hardwareBackPress',
|
|
154
|
-
|
|
210
|
+
this.onBackPress
|
|
155
211
|
);
|
|
156
212
|
this.appStateSubscription = AppState.addEventListener(
|
|
157
213
|
'change',
|
|
158
|
-
|
|
214
|
+
this.appStateListener
|
|
159
215
|
);
|
|
160
216
|
}
|
|
161
217
|
}
|
|
@@ -164,30 +220,22 @@ export class DdRumReactNavigationTracking {
|
|
|
164
220
|
* Stops tracking the NavigationContainer.
|
|
165
221
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
166
222
|
*/
|
|
167
|
-
|
|
168
|
-
navigationRef: NavigationContainerRef | null
|
|
169
|
-
): void {
|
|
223
|
+
stopTrackingViews(navigationRef: NavigationContainerRef | null): void {
|
|
170
224
|
this.navigationTimeline?.addStopTrackingEvent();
|
|
171
225
|
this.previousRoute = undefined;
|
|
172
226
|
if (navigationRef != null) {
|
|
173
|
-
if (
|
|
227
|
+
if (this.navigationStateChangeListener) {
|
|
174
228
|
navigationRef.removeListener(
|
|
175
229
|
'state',
|
|
176
|
-
|
|
230
|
+
this.navigationStateChangeListener
|
|
177
231
|
);
|
|
178
232
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
DdRumReactNavigationTracking.viewNamePredicate = function (
|
|
186
|
-
_route: Route<string, any | undefined>,
|
|
187
|
-
trackedName: string
|
|
188
|
-
) {
|
|
189
|
-
return trackedName;
|
|
190
|
-
};
|
|
233
|
+
this.backHandler?.remove();
|
|
234
|
+
this.backHandler = null;
|
|
235
|
+
this.registeredContainer = null;
|
|
236
|
+
this.navigationStateChangeListener = null;
|
|
237
|
+
|
|
238
|
+
this.resetPredicates();
|
|
191
239
|
}
|
|
192
240
|
|
|
193
241
|
// For versions of React Native below 0.65, addEventListener does not return a subscription.
|
|
@@ -202,37 +250,51 @@ export class DdRumReactNavigationTracking {
|
|
|
202
250
|
} else if (AppState.removeEventListener) {
|
|
203
251
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
204
252
|
// @ts-ignore
|
|
205
|
-
AppState.removeEventListener(
|
|
206
|
-
'change',
|
|
207
|
-
DdRumReactNavigationTracking.appStateListener
|
|
208
|
-
);
|
|
253
|
+
AppState.removeEventListener('change', this.appStateListener);
|
|
209
254
|
}
|
|
210
255
|
}
|
|
211
256
|
|
|
212
|
-
|
|
257
|
+
_resetInternalStateForTesting(): void {
|
|
258
|
+
this._navigationTimeline = undefined;
|
|
259
|
+
this.registeredContainer = null;
|
|
260
|
+
this.navigationStateChangeListener = null;
|
|
261
|
+
this.previousRoute = undefined;
|
|
262
|
+
this.backHandler = null;
|
|
263
|
+
this.appStateSubscription = undefined;
|
|
264
|
+
this.previousAppState = undefined;
|
|
265
|
+
this.previousRouteKey = undefined;
|
|
266
|
+
this.trackingState = 'NOT_TRACKING';
|
|
267
|
+
this.resetPredicates();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private resetPredicates() {
|
|
271
|
+
this.paramsTrackingPredicate = defaultParamsPredicate;
|
|
272
|
+
this.viewNamePredicate = defaultViewNamePredicate;
|
|
273
|
+
this.viewTrackingPredicate = defaultViewTrackingPredicate;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private handleRouteNavigation(
|
|
213
277
|
route: Route<string, any | undefined> | undefined,
|
|
214
278
|
appStateStatus: AppStateStatus,
|
|
215
279
|
stateEvent: StateEvent | undefined
|
|
216
280
|
) {
|
|
217
281
|
if (route === undefined || route === null) {
|
|
218
282
|
InternalLog.log(
|
|
219
|
-
|
|
283
|
+
this.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,
|
|
220
284
|
SdkVerbosity.WARN
|
|
221
285
|
);
|
|
222
286
|
// RUMM-1400 in some cases the route seem to be undefined
|
|
223
287
|
return;
|
|
224
288
|
}
|
|
225
289
|
const key = route.key;
|
|
226
|
-
const screenName =
|
|
227
|
-
|
|
228
|
-
route.name
|
|
229
|
-
);
|
|
290
|
+
const screenName = this.viewNamePredicate(route, route.name);
|
|
291
|
+
const customKey = transformViewKey(key, screenName);
|
|
230
292
|
|
|
231
293
|
if (key != null && screenName != null) {
|
|
232
294
|
// On iOS, the app can start in either "active", "background" or "unknown" state
|
|
233
295
|
if (appStateStatus !== 'background') {
|
|
234
296
|
this.previousRoute = route;
|
|
235
|
-
|
|
297
|
+
this.trackingState = 'TRACKING';
|
|
236
298
|
this.navigationTimeline?.addNavigationStateEvent(
|
|
237
299
|
'START_VIEW',
|
|
238
300
|
key,
|
|
@@ -242,14 +304,21 @@ export class DdRumReactNavigationTracking {
|
|
|
242
304
|
trackingState: this.trackingState
|
|
243
305
|
}
|
|
244
306
|
);
|
|
245
|
-
|
|
307
|
+
if (this.viewTrackingPredicate(route)) {
|
|
308
|
+
const params = this.paramsTrackingPredicate(route);
|
|
309
|
+
if (params) {
|
|
310
|
+
DdRum.startView(customKey, screenName, { params });
|
|
311
|
+
} else {
|
|
312
|
+
DdRum.startView(customKey, screenName);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
246
315
|
}
|
|
247
316
|
}
|
|
248
317
|
|
|
249
318
|
this.previousRouteKey = route.key;
|
|
250
319
|
}
|
|
251
320
|
|
|
252
|
-
private
|
|
321
|
+
private handleAppStateChanged(
|
|
253
322
|
route: Route<string, any | undefined>,
|
|
254
323
|
appStateStatus: AppStateStatus
|
|
255
324
|
) {
|
|
@@ -258,14 +327,12 @@ export class DdRumReactNavigationTracking {
|
|
|
258
327
|
appStateStatus
|
|
259
328
|
);
|
|
260
329
|
const key = route.key;
|
|
261
|
-
const screenName =
|
|
262
|
-
|
|
263
|
-
route.name
|
|
264
|
-
);
|
|
330
|
+
const screenName = this.viewNamePredicate(route, route.name);
|
|
331
|
+
const customKey = transformViewKey(key, screenName);
|
|
265
332
|
|
|
266
333
|
if (key != null && screenName != null) {
|
|
267
334
|
if (appStateStatus === 'background') {
|
|
268
|
-
|
|
335
|
+
this.trackingState = 'NOT_TRACKING';
|
|
269
336
|
this.navigationTimeline?.addNavigationStateEvent(
|
|
270
337
|
'STOP_VIEW',
|
|
271
338
|
key,
|
|
@@ -275,15 +342,15 @@ export class DdRumReactNavigationTracking {
|
|
|
275
342
|
trackingState: this.trackingState
|
|
276
343
|
}
|
|
277
344
|
);
|
|
278
|
-
DdRum.stopView(
|
|
345
|
+
DdRum.stopView(customKey);
|
|
279
346
|
this.previousRoute = undefined;
|
|
280
347
|
} else if (
|
|
281
348
|
appStateStatus === 'active' &&
|
|
282
|
-
|
|
349
|
+
this.trackingState === 'NOT_TRACKING'
|
|
283
350
|
) {
|
|
284
351
|
// case when app goes into foreground,
|
|
285
352
|
// in that case navigation listener won't be called
|
|
286
|
-
|
|
353
|
+
this.handleRouteNavigation(
|
|
287
354
|
route,
|
|
288
355
|
AppState.currentState,
|
|
289
356
|
appStateChangeEvent
|
|
@@ -295,12 +362,10 @@ export class DdRumReactNavigationTracking {
|
|
|
295
362
|
this.previousAppState = appStateStatus;
|
|
296
363
|
}
|
|
297
364
|
|
|
298
|
-
private
|
|
299
|
-
if (
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
DdRumReactNavigationTracking.navigationStateChangeListener = () => {
|
|
303
|
-
const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();
|
|
365
|
+
private resolveNavigationStateChangeListener(): NavigationListener {
|
|
366
|
+
if (this.navigationStateChangeListener == null) {
|
|
367
|
+
this.navigationStateChangeListener = () => {
|
|
368
|
+
const route = this.registeredContainer?.getCurrentRoute();
|
|
304
369
|
|
|
305
370
|
const newRouteStateEvent = this.navigationTimeline?.addNewRouteEvent(
|
|
306
371
|
this.previousRouteKey,
|
|
@@ -309,7 +374,7 @@ export class DdRumReactNavigationTracking {
|
|
|
309
374
|
|
|
310
375
|
if (route === undefined) {
|
|
311
376
|
InternalLog.log(
|
|
312
|
-
|
|
377
|
+
this.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,
|
|
313
378
|
SdkVerbosity.WARN
|
|
314
379
|
);
|
|
315
380
|
return;
|
|
@@ -329,22 +394,22 @@ export class DdRumReactNavigationTracking {
|
|
|
329
394
|
return;
|
|
330
395
|
}
|
|
331
396
|
|
|
332
|
-
|
|
397
|
+
this.handleRouteNavigation(
|
|
333
398
|
route,
|
|
334
399
|
AppState.currentState,
|
|
335
400
|
newRouteStateEvent
|
|
336
401
|
);
|
|
337
402
|
};
|
|
338
403
|
|
|
339
|
-
|
|
404
|
+
this.navigationStateChangeListener({});
|
|
340
405
|
}
|
|
341
|
-
return
|
|
406
|
+
return this.navigationStateChangeListener;
|
|
342
407
|
}
|
|
343
408
|
|
|
344
|
-
private
|
|
409
|
+
private appStateListener: AppStateListener = (
|
|
345
410
|
appStateStatus: AppStateStatus
|
|
346
411
|
) => {
|
|
347
|
-
const currentRoute =
|
|
412
|
+
const currentRoute = this.registeredContainer?.getCurrentRoute();
|
|
348
413
|
if (currentRoute === undefined || currentRoute === null) {
|
|
349
414
|
InternalLog.log(
|
|
350
415
|
`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,
|
|
@@ -353,9 +418,11 @@ export class DdRumReactNavigationTracking {
|
|
|
353
418
|
return;
|
|
354
419
|
}
|
|
355
420
|
|
|
356
|
-
|
|
357
|
-
currentRoute,
|
|
358
|
-
appStateStatus
|
|
359
|
-
);
|
|
421
|
+
this.handleAppStateChanged(currentRoute, appStateStatus);
|
|
360
422
|
};
|
|
361
423
|
}
|
|
424
|
+
|
|
425
|
+
export const DdRumReactNavigationTracking = getGlobalInstance(
|
|
426
|
+
REACT_NAVIGATION_TRACKING_MODULE,
|
|
427
|
+
() => new RumReactNavigationTracking()
|
|
428
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms the view key format from 'ScreenName-uniqueId' to 'ScreenName/uniqueId'.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // Input: key='Elements-lUQ9cId5lwk1o94euVh2B', screenName='Elements'
|
|
6
|
+
* // Output: 'Elements/lUQ9cId5lwk1o94euVh2B'
|
|
7
|
+
*
|
|
8
|
+
* @param key - The route key (e.g., 'Elements-lUQ9cId5lwk1o94euVh2B')
|
|
9
|
+
* @param screenName - The screen name (e.g., 'Elements')
|
|
10
|
+
* @returns The transformed key, or the original key if not in expected format
|
|
11
|
+
*/
|
|
12
|
+
export function transformViewKey(
|
|
13
|
+
key: string,
|
|
14
|
+
screenName: string | null
|
|
15
|
+
): string {
|
|
16
|
+
if (!screenName || !key) {
|
|
17
|
+
return key;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const expectedPrefix = `${screenName}-`;
|
|
21
|
+
if (key.startsWith(expectedPrefix)) {
|
|
22
|
+
const uniqueId = key.slice(expectedPrefix.length);
|
|
23
|
+
return `${screenName}/${uniqueId}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Key is not in the expected format, use original
|
|
27
|
+
return key;
|
|
28
|
+
}
|