@datadog/mobile-react-navigation 1.0.0-rc5 → 1.0.0-rc7
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/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +70 -51
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/react-navigation.js +2 -0
- package/lib/commonjs/rum/instrumentation/react-navigation.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +66 -52
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/react-navigation.js +2 -0
- package/lib/module/rum/instrumentation/react-navigation.js.map +1 -0
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +6 -6
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +14 -3
- package/lib/typescript/core/src/InternalLog.d.ts +5 -0
- package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
- package/lib/typescript/core/src/Timer.d.ts +3 -2
- package/lib/typescript/core/src/index.d.ts +4 -3
- package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
- package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +8 -3
- package/lib/typescript/react-navigation/src/rum/instrumentation/react-navigation.d.ts +116 -0
- package/package.json +11 -6
- package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +467 -384
- package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +56 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV5.tsx +105 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV6.tsx +105 -0
- package/src/index.tsx +4 -1
- package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +136 -64
- package/src/rum/instrumentation/react-navigation.ts +158 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA","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 {
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA","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 {\n DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -19,27 +19,27 @@ class DdRumReactNavigationTracking {
|
|
|
19
19
|
* Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
|
|
20
20
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
21
21
|
*/
|
|
22
|
-
static startTrackingViews(navigationRef) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
22
|
+
static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
|
|
23
|
+
return trackedName;
|
|
24
|
+
}) {
|
|
27
25
|
if (navigationRef == null) {
|
|
28
|
-
|
|
26
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
|
|
27
|
+
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
|
|
33
|
-
|
|
32
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
|
|
34
33
|
} else if (DdRumReactNavigationTracking.registeredContainer == null) {
|
|
35
34
|
DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
|
|
36
35
|
const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
|
|
37
36
|
DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
|
|
38
|
-
navigationRef.addListener(
|
|
37
|
+
navigationRef.addListener('state', listener);
|
|
39
38
|
DdRumReactNavigationTracking.registeredContainer = navigationRef;
|
|
40
|
-
|
|
39
|
+
DdRumReactNavigationTracking.backHandler = _reactNative.BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
_reactNative.AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Stops tracking the NavigationContainer.
|
|
@@ -49,22 +49,28 @@ class DdRumReactNavigationTracking {
|
|
|
49
49
|
|
|
50
50
|
static stopTrackingViews(navigationRef) {
|
|
51
51
|
if (navigationRef != null) {
|
|
52
|
-
|
|
52
|
+
var _DdRumReactNavigation;
|
|
53
|
+
|
|
54
|
+
navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
|
|
55
|
+
(_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
|
|
56
|
+
DdRumReactNavigationTracking.backHandler = null;
|
|
53
57
|
DdRumReactNavigationTracking.registeredContainer = null;
|
|
54
58
|
|
|
55
59
|
DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
|
|
56
60
|
return trackedName;
|
|
57
61
|
};
|
|
58
62
|
}
|
|
63
|
+
|
|
64
|
+
_reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
static handleRouteNavigation(route) {
|
|
67
|
+
static handleRouteNavigation(route, appStateStatus = undefined) {
|
|
62
68
|
var _predicate;
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
if (route === undefined || route === null) {
|
|
71
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
|
|
72
|
+
|
|
65
73
|
|
|
66
|
-
if (route == undefined || route == null) {
|
|
67
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
68
74
|
return;
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -75,8 +81,8 @@ class DdRumReactNavigationTracking {
|
|
|
75
81
|
if (key != null && screenName != null) {
|
|
76
82
|
if (appStateStatus === 'background') {
|
|
77
83
|
_mobileReactNative.DdRum.stopView(key);
|
|
78
|
-
} else if (appStateStatus === 'active' || appStateStatus
|
|
79
|
-
// case when app goes into foreground,
|
|
84
|
+
} else if (appStateStatus === 'active' || appStateStatus === undefined) {
|
|
85
|
+
// case when app goes into foreground,
|
|
80
86
|
// in that case navigation listener won't be called
|
|
81
87
|
_mobileReactNative.DdRum.startView(key, screenName);
|
|
82
88
|
}
|
|
@@ -85,25 +91,15 @@ class DdRumReactNavigationTracking {
|
|
|
85
91
|
|
|
86
92
|
static resolveNavigationStateChangeListener() {
|
|
87
93
|
if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
|
|
88
|
-
DdRumReactNavigationTracking.navigationStateChangeListener =
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
let route = (_event$data = event.data) === null || _event$data === void 0 ? void 0 : (_event$data$state = _event$data.state) === null || _event$data$state === void 0 ? void 0 : _event$data$state.routes[(_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : (_event$data2$state = _event$data2.state) === null || _event$data2$state === void 0 ? void 0 : _event$data2$state.index];
|
|
94
|
+
DdRumReactNavigationTracking.navigationStateChangeListener = () => {
|
|
95
|
+
var _DdRumReactNavigation2;
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
+
const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
if (route === undefined) {
|
|
100
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN);
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
route = nestedRoute;
|
|
102
|
+
return;
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
DdRumReactNavigationTracking.handleRouteNavigation(route);
|
|
@@ -113,34 +109,57 @@ class DdRumReactNavigationTracking {
|
|
|
113
109
|
return DdRumReactNavigationTracking.navigationStateChangeListener;
|
|
114
110
|
}
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
if (DdRumReactNavigationTracking.appStateListener == null) {
|
|
118
|
-
DdRumReactNavigationTracking.appStateListener = appStateStatus => {
|
|
119
|
-
var _DdRumReactNavigation;
|
|
112
|
+
}
|
|
120
113
|
|
|
121
|
-
|
|
114
|
+
exports.DdRumReactNavigationTracking = DdRumReactNavigationTracking;
|
|
122
115
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
_defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
|
|
117
|
+
|
|
118
|
+
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
126
119
|
|
|
127
|
-
|
|
128
|
-
}; // AppState is singleton, so we should add a listener only once in the app lifetime
|
|
120
|
+
_defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
|
|
129
121
|
|
|
122
|
+
_defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
_defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
|
|
125
|
+
|
|
126
|
+
_defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
|
|
127
|
+
|
|
128
|
+
_defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
|
|
129
|
+
|
|
130
|
+
_defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
|
|
131
|
+
if (DdRumReactNavigationTracking.registeredContainer === null) {
|
|
132
|
+
return false;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
return true;
|
|
140
|
+
});
|
|
138
141
|
|
|
139
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
142
|
+
_defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
|
|
143
|
+
if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
|
|
144
|
+
DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
|
|
145
|
+
} // We always return false so we make sure the react-navigation callback is called.
|
|
146
|
+
// See https://reactnative.dev/docs/backhandler
|
|
140
147
|
|
|
141
|
-
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
142
148
|
|
|
143
|
-
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
144
151
|
|
|
145
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
152
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
|
|
153
|
+
var _DdRumReactNavigation3;
|
|
154
|
+
|
|
155
|
+
const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
|
|
156
|
+
|
|
157
|
+
if (currentRoute === undefined || currentRoute === null) {
|
|
158
|
+
_mobileReactNative.InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, _mobileReactNative.SdkVerbosity.ERROR);
|
|
159
|
+
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
|
|
164
|
+
});
|
|
146
165
|
//# sourceMappingURL=DdRumReactNavigationTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","DdRum","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","AppState","addEventListener"],"mappings":";;;;;;;AAOA;;AACA;;;;AAcA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAUtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACjBC,aADiB,EAGb;AAAA,QADJC,iBACI,uEADmC,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,aAAOA,WAAP;AAAqB,KACjI;;AAER,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,MAAAA,OAAO,CAACC,GAAR,CAAa,8CAAb;AACA;AACH;;AAED,QAAIP,4BAA4B,CAACQ,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BN,aAA7F,EAA4G;AACxGI,MAAAA,OAAO,CAACG,KAAR,CAAc,0EAAd;AACH,KAFD,MAEO,IAAIT,4BAA4B,CAACQ,mBAA7B,IAAoD,IAAxD,EAA8D;AACjER,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMO,QAAQ,GAAGV,4BAA4B,CAACW,oCAA7B,EAAjB;AACAX,MAAAA,4BAA4B,CAACY,qBAA7B,CAAmDV,aAAa,CAACW,eAAd,EAAnD;AACAX,MAAAA,aAAa,CAACY,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAV,MAAAA,4BAA4B,CAACQ,mBAA7B,GAAmDN,aAAnD;AACH;;AAGDF,IAAAA,4BAA4B,CAACe,gCAA7B;AACH;AAED;AACJ;AACA;AACA;;;AAC4B,SAAjBC,iBAAiB,CAACd,aAAD,EAAqD;AACzE,QAAIA,aAAa,IAAI,IAArB,EAA2B;AACvBA,MAAAA,aAAa,CAACe,cAAd,CAA6B,OAA7B,EAAsCjB,4BAA4B,CAACkB,6BAAnE;AACAlB,MAAAA,4BAA4B,CAACQ,mBAA7B,GAAmD,IAAnD;;AACAR,MAAAA,4BAA4B,CAACG,iBAA7B,G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CAACY,KAAN,CAAYC,MAAZ,CAAmBb,KAAK,CAACY,KAAN,CAAYE,KAA/B,CAApB;;AACA,cAAIC,WAAW,IAAIb,SAAnB,EAA8B;AAC1B;AACA;AACH;;AACDF,UAAAA,KAAK,GAAGe,WAAR;AACH;;AAEDlC,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDO,KAAnD;AACH,OAlBD;AAmBH;;AACD,WAAOnB,4BAA4B,CAACkB,6BAApC;AACH;;AAE8C,SAAhCH,gCAAgC,GAAG;AAC9C,QAAIf,4BAA4B,CAACmC,gBAA7B,IAAiD,IAArD,EAA2D;AACvDnC,MAAAA,4BAA4B,CAACmC,gBAA7B,GAAiDf,cAAD,IAAoC;AAAA;;AAEhF,cAAMgB,YAAY,4BAAGpC,4BAA4B,CAACQ,mBAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIuB,YAAY,IAAIf,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDwB,YAAnD,EAAiEhB,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACAiB,4BAASC,gBAAT,CAA0B,QAA1B,EAAoCtC,4BAA4B,CAACmC,gBAAjE;AACH;AACJ;;AAlHqC;;;;gBAA7BnC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","InternalLog","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","SdkVerbosity","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","BackHandler","addEventListener","onBackPress","AppState","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","DdRum","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAqCtC;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;AAGAd,MAAAA,aAAa,CAACe,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAb,MAAAA,4BAA4B,CAACW,mBAA7B,GAAmDT,aAAnD;AACAF,MAAAA,4BAA4B,CAACk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vB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQX,4B,sBAsKL8B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAG3C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI2B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDrC,mCAAYC,GAAZ,CACK,4EAA2EuB,cAAe,gDAD/F,EAEIrB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI4B,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;\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 static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n 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 AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SACIA,4BADJ,EAEIC,iBAFJ,QAGO,oDAHP;AAKA,SAASD,4BAAT,EAAuCC,iBAAvC","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 {\n DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -5,8 +5,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
5
5
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
6
|
* Copyright 2016-Present Datadog, Inc.
|
|
7
7
|
*/
|
|
8
|
-
import { DdRum } from '@datadog/mobile-react-native';
|
|
9
|
-
import { AppState } from 'react-native';
|
|
8
|
+
import { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';
|
|
9
|
+
import { AppState, BackHandler } from 'react-native';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
|
|
@@ -16,27 +16,25 @@ export class DdRumReactNavigationTracking {
|
|
|
16
16
|
* Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
|
|
17
17
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
18
18
|
*/
|
|
19
|
-
static startTrackingViews(navigationRef) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
19
|
+
static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
|
|
20
|
+
return trackedName;
|
|
21
|
+
}) {
|
|
24
22
|
if (navigationRef == null) {
|
|
25
|
-
|
|
23
|
+
InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, SdkVerbosity.ERROR);
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
|
|
30
|
-
|
|
28
|
+
InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, SdkVerbosity.ERROR);
|
|
31
29
|
} else if (DdRumReactNavigationTracking.registeredContainer == null) {
|
|
32
30
|
DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
|
|
33
31
|
const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
|
|
34
32
|
DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
|
|
35
|
-
navigationRef.addListener(
|
|
33
|
+
navigationRef.addListener('state', listener);
|
|
36
34
|
DdRumReactNavigationTracking.registeredContainer = navigationRef;
|
|
35
|
+
DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
|
|
36
|
+
AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* Stops tracking the NavigationContainer.
|
|
@@ -46,22 +44,27 @@ export class DdRumReactNavigationTracking {
|
|
|
46
44
|
|
|
47
45
|
static stopTrackingViews(navigationRef) {
|
|
48
46
|
if (navigationRef != null) {
|
|
49
|
-
|
|
47
|
+
var _DdRumReactNavigation;
|
|
48
|
+
|
|
49
|
+
navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
|
|
50
|
+
(_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
|
|
51
|
+
DdRumReactNavigationTracking.backHandler = null;
|
|
50
52
|
DdRumReactNavigationTracking.registeredContainer = null;
|
|
51
53
|
|
|
52
54
|
DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
|
|
53
55
|
return trackedName;
|
|
54
56
|
};
|
|
55
57
|
}
|
|
58
|
+
|
|
59
|
+
AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
static handleRouteNavigation(route) {
|
|
62
|
+
static handleRouteNavigation(route, appStateStatus = undefined) {
|
|
59
63
|
var _predicate;
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
if (route === undefined || route === null) {
|
|
66
|
+
InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
|
|
62
67
|
|
|
63
|
-
if (route == undefined || route == null) {
|
|
64
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -72,8 +75,8 @@ export class DdRumReactNavigationTracking {
|
|
|
72
75
|
if (key != null && screenName != null) {
|
|
73
76
|
if (appStateStatus === 'background') {
|
|
74
77
|
DdRum.stopView(key);
|
|
75
|
-
} else if (appStateStatus === 'active' || appStateStatus
|
|
76
|
-
// case when app goes into foreground,
|
|
78
|
+
} else if (appStateStatus === 'active' || appStateStatus === undefined) {
|
|
79
|
+
// case when app goes into foreground,
|
|
77
80
|
// in that case navigation listener won't be called
|
|
78
81
|
DdRum.startView(key, screenName);
|
|
79
82
|
}
|
|
@@ -82,27 +85,16 @@ export class DdRumReactNavigationTracking {
|
|
|
82
85
|
|
|
83
86
|
static resolveNavigationStateChangeListener() {
|
|
84
87
|
if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
|
|
85
|
-
DdRumReactNavigationTracking.navigationStateChangeListener =
|
|
86
|
-
var
|
|
88
|
+
DdRumReactNavigationTracking.navigationStateChangeListener = () => {
|
|
89
|
+
var _DdRumReactNavigation2;
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
|
|
89
92
|
|
|
90
|
-
if (route
|
|
91
|
-
|
|
93
|
+
if (route === undefined) {
|
|
94
|
+
InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN);
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
while (route.state != undefined) {
|
|
96
|
-
const nestedRoute = route.state.routes[route.state.index];
|
|
97
|
-
|
|
98
|
-
if (nestedRoute == undefined) {
|
|
99
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
route = nestedRoute;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
98
|
DdRumReactNavigationTracking.handleRouteNavigation(route);
|
|
107
99
|
};
|
|
108
100
|
}
|
|
@@ -110,32 +102,54 @@ export class DdRumReactNavigationTracking {
|
|
|
110
102
|
return DdRumReactNavigationTracking.navigationStateChangeListener;
|
|
111
103
|
}
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
if (DdRumReactNavigationTracking.appStateListener == null) {
|
|
115
|
-
DdRumReactNavigationTracking.appStateListener = appStateStatus => {
|
|
116
|
-
var _DdRumReactNavigation;
|
|
105
|
+
}
|
|
117
106
|
|
|
118
|
-
|
|
107
|
+
_defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
|
|
119
108
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
110
|
+
|
|
111
|
+
_defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
}; // AppState is singleton, so we should add a listener only once in the app lifetime
|
|
113
|
+
_defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
|
|
126
114
|
|
|
115
|
+
_defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
_defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
|
|
118
|
+
|
|
119
|
+
_defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
|
|
120
|
+
|
|
121
|
+
_defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
|
|
122
|
+
if (DdRumReactNavigationTracking.registeredContainer === null) {
|
|
123
|
+
return false;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
|
|
126
|
+
if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
133
129
|
|
|
134
|
-
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
135
132
|
|
|
136
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
133
|
+
_defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
|
|
134
|
+
if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
|
|
135
|
+
DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
|
|
136
|
+
} // We always return false so we make sure the react-navigation callback is called.
|
|
137
|
+
// See https://reactnative.dev/docs/backhandler
|
|
137
138
|
|
|
138
|
-
_defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
return false;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
|
|
144
|
+
var _DdRumReactNavigation3;
|
|
145
|
+
|
|
146
|
+
const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
|
|
147
|
+
|
|
148
|
+
if (currentRoute === undefined || currentRoute === null) {
|
|
149
|
+
InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, SdkVerbosity.ERROR);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
|
|
154
|
+
});
|
|
141
155
|
//# sourceMappingURL=DdRumReactNavigationTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","AppState","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","addEventListener"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,KAAT,QAAsB,8BAAtB;AACA,SAASC,QAAT,QAAyC,cAAzC;;AAcA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAUtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACjBC,aADiB,EAGb;AAAA,QADJC,iBACI,uEADmC,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,aAAOA,WAAP;AAAqB,KACjI;;AAER,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,MAAAA,OAAO,CAACC,GAAR,CAAa,8CAAb;AACA;AACH;;AAED,QAAIP,4BAA4B,CAACQ,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BN,aAA7F,EAA4G;AACxGI,MAAAA,OAAO,CAACG,KAAR,CAAc,0EAAd;AACH,KAFD,MAEO,IAAIT,4BAA4B,CAACQ,mBAA7B,IAAoD,IAAxD,EAA8D;AACjER,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMO,QAAQ,GAAGV,4BAA4B,CAACW,oCAA7B,EAAjB;AACAX,MAAAA,4BAA4B,CAACY,qBAA7B,CAAmDV,aAAa,CAACW,eAAd,EAAnD;AACAX,MAAAA,aAAa,CAACY,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAV,MAAAA,4BAA4B,CAACQ,mBAA7B,GAAmDN,aAAnD;AACH;;AAGDF,IAAAA,4BAA4B,CAACe,gCAA7B;AACH;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IT,KAAK,kBAAGS,KAAK,CAACC,IAAT,qEAAG,YAAYC,KAAf,sDAAG,kBAAmBC,MAAnB,iBAA0BH,KAAK,CAACC,IAAhC,uEAA0B,aAAYC,KAAtC,uDAA0B,mBAAmBE,KAA7C,CAAZ;;AAEA,YAAIb,KAAK,IAAIE,SAAb,EAAwB;AACpB;AACA;AACH;;AAED,eAAOF,KAAK,CAACW,KAAN,IAAeT,SAAtB,EAAiC;AAC7B,gBAAMY,WAAW,GAAGd,KAAK,CAACW,KAAN,CAAYC,MAAZ,CAAmBZ,KAAK,CAACW,KAAN,CAAYE,KAA/B,CAApB;;AACA,cAAIC,WAAW,IAAIZ,SAAnB,EAA8B;AAC1B;AACA;AACH;;AACDF,UAAAA,KAAK,GAAGc,WAAR;AACH;;AAEDjC,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDO,KAAnD;AACH,OAlBD;AAmBH;;AACD,WAAOnB,4BAA4B,CAACkB,6BAApC;AACH;;AAE8C,SAAhCH,gCAAgC,GAAG;AAC9C,QAAIf,4BAA4B,CAACkC,gBAA7B,IAAiD,IAArD,EAA2D;AACvDlC,MAAAA,4BAA4B,CAACkC,gBAA7B,GAAiDd,cAAD,IAAoC;AAAA;;AAEhF,cAAMe,YAAY,4BAAGnC,4BAA4B,CAACQ,mBAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIsB,YAAY,IAAId,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDuB,YAAnD,EAAiEf,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACArB,MAAAA,QAAQ,CAACqC,gBAAT,CAA0B,QAA1B,EAAoCpC,4BAA4B,CAACkC,gBAAjE;AACH;AACJ;;AAlHqC;;gBAA7BlC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","SdkVerbosity","InternalLog","AppState","BackHandler","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","addEventListener","onBackPress","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,YAAhB,EAA8BC,WAA9B,QAAiD,8BAAjD;AAEA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,cAAtC;;AAqBA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAqCtC;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,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4B,CAACsB,6BAApC;AACH;;AAnKqC;;gBAA7BtB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAUL,gG;;gBAVKA,4B,uCAYL,+C;;gBAZKA,4B,yCAcL,6K;;gBAdKA,4B,6BAgBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD2B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBAxBQpC,4B,iBA0BY,MAAM;AACvB,MAAIA,4BAA4B,CAACqC,uBAA7B,EAAJ,EAA4D;AACxDrC,IAAAA,4BAA4B,CAACoB,iBAA7B,CACIpB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQT,4B,sBAsKL0B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGtC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIwB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrDzC,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EoB,cAAe,gDAD/F,EAEI9B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACIyB,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;\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 static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n 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 AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DdSdkReactNativeConfiguration } from
|
|
2
|
-
import type { TrackingConsent } from
|
|
1
|
+
import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
2
|
+
import type { TrackingConsent } from './TrackingConsent';
|
|
3
3
|
/**
|
|
4
4
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
5
5
|
*/
|
|
@@ -18,10 +18,10 @@ export declare class DdSdkReactNative {
|
|
|
18
18
|
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
19
19
|
private static wasInitialized;
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
* Initializes the Datadog SDK.
|
|
22
|
+
* @param configuration the configuration for the SDK library
|
|
23
|
+
* @returns a Promise.
|
|
24
|
+
*/
|
|
25
25
|
static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TrackingConsent } from './TrackingConsent';
|
|
2
|
-
import type { SdkVerbosity } from './SdkVerbosity';
|
|
3
1
|
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
2
|
+
import type { SdkVerbosity } from './SdkVerbosity';
|
|
3
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
4
4
|
/**
|
|
5
5
|
* The SDK configuration class.
|
|
6
6
|
* It will be used to configure the SDK functionality at initialization.
|
|
@@ -14,7 +14,18 @@ export declare class DdSdkReactNativeConfiguration {
|
|
|
14
14
|
readonly trackErrors: boolean;
|
|
15
15
|
readonly trackingConsent: TrackingConsent;
|
|
16
16
|
nativeCrashReportEnabled: boolean;
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
|
+
*/
|
|
20
|
+
sampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
|
+
*/
|
|
24
|
+
sessionSamplingRate: number;
|
|
25
|
+
/**
|
|
26
|
+
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
|
+
*/
|
|
28
|
+
resourceTracingSamplingRate: number;
|
|
18
29
|
site: string;
|
|
19
30
|
verbosity: SdkVerbosity | undefined;
|
|
20
31
|
nativeViewTracking: boolean;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
2
|
+
/**
|
|
3
|
+
* /!\ DO NOT USE THIS IN YOUR APP /!\\
|
|
4
|
+
*
|
|
5
|
+
* This logger is only for debugging the Datadog SDK.
|
|
6
|
+
*/
|
|
2
7
|
export declare class InternalLog {
|
|
3
8
|
private static levelMap;
|
|
4
9
|
static verbosity: SdkVerbosity | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Timestamp structure holding the
|
|
3
|
+
*/
|
|
4
|
+
export declare type Timestamp = {
|
|
5
|
+
unix: number;
|
|
6
|
+
react_native: number | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Simple class providing timestamps in milliseconds.
|
|
10
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TimeProvider {
|
|
13
|
+
private canUsePerformanceNow;
|
|
14
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
15
|
+
private baseOffset;
|
|
16
|
+
constructor();
|
|
17
|
+
getTimestamp(): Timestamp;
|
|
18
|
+
now(): number;
|
|
19
|
+
private performanceNow;
|
|
20
|
+
}
|