@datadog/mobile-react-navigation 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +67 -7
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  3. package/lib/commonjs/rum/instrumentation/NavigationTimeline.js +87 -0
  4. package/lib/commonjs/rum/instrumentation/NavigationTimeline.js.map +1 -0
  5. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +67 -7
  6. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  7. package/lib/module/rum/instrumentation/NavigationTimeline.js +79 -0
  8. package/lib/module/rum/instrumentation/NavigationTimeline.js.map +1 -0
  9. package/lib/typescript/core/src/DdSdkReactNative.d.ts +1 -1
  10. package/lib/typescript/core/src/DdSdkReactNative.d.ts.map +1 -1
  11. package/lib/typescript/core/src/index.d.ts +7 -6
  12. package/lib/typescript/core/src/index.d.ts.map +1 -1
  13. package/lib/typescript/core/src/rum/constants.d.ts +2 -0
  14. package/lib/typescript/core/src/rum/constants.d.ts.map +1 -0
  15. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts +24 -0
  16. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -0
  17. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts.map +1 -1
  18. package/lib/typescript/core/src/rum/types.d.ts +5 -0
  19. package/lib/typescript/core/src/rum/types.d.ts.map +1 -1
  20. package/lib/typescript/core/src/specs/NativeDdSdk.d.ts +6 -0
  21. package/lib/typescript/core/src/specs/NativeDdSdk.d.ts.map +1 -1
  22. package/lib/typescript/core/src/types.d.ts +3 -0
  23. package/lib/typescript/core/src/types.d.ts.map +1 -1
  24. package/lib/typescript/core/src/utils/telemetry.d.ts +7 -0
  25. package/lib/typescript/core/src/utils/telemetry.d.ts.map +1 -0
  26. package/lib/typescript/core/src/version.d.ts +1 -1
  27. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +22 -0
  28. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts.map +1 -1
  29. package/lib/typescript/react-navigation/src/rum/instrumentation/NavigationTimeline.d.ts +45 -0
  30. package/lib/typescript/react-navigation/src/rum/instrumentation/NavigationTimeline.d.ts.map +1 -0
  31. package/package.json +3 -3
  32. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +112 -14
  33. package/src/rum/instrumentation/NavigationTimeline.ts +134 -0
@@ -0,0 +1,134 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+ export type NavigationState = {
7
+ activeView: string | undefined;
8
+ trackingState: 'TRACKING' | 'NOT_TRACKING';
9
+ };
10
+
11
+ export type NavigationStateEventType = 'START_VIEW' | 'STOP_VIEW' | 'DISCARDED';
12
+
13
+ export class StateEvent {
14
+ name: string;
15
+ shortTimestamp: string = '';
16
+ fullTimestamp: string = '';
17
+ constructor(name: string, timestamp: number) {
18
+ this.name = name;
19
+ const date = new Date(timestamp);
20
+ const hours = String(date.getHours()).padStart(2, '0');
21
+ const minutes = String(date.getMinutes()).padStart(2, '0');
22
+ const seconds = String(date.getSeconds()).padStart(2, '0');
23
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
24
+ const day = String(date.getDate()).padStart(2, '0');
25
+ const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
26
+ const year = date.getFullYear();
27
+
28
+ this.shortTimestamp = `${hours}:${minutes}:${seconds}:${milliseconds}`;
29
+ this.fullTimestamp = `${day}/${month}/${year} ${hours}:${minutes}:${seconds}:${milliseconds}`;
30
+ }
31
+ }
32
+
33
+ class StartTrackingStateEvent extends StateEvent {
34
+ constructor() {
35
+ super('INITIALIZE', Date.now());
36
+ }
37
+ }
38
+
39
+ class StopTrackingStateEvent extends StateEvent {
40
+ constructor() {
41
+ super('STOP_TRACKING', Date.now());
42
+ }
43
+ }
44
+
45
+ class NewRouteStateEvent extends StateEvent {
46
+ previousRoute: string;
47
+ newRoute: string;
48
+
49
+ constructor(previousRoute: string, newRoute: string) {
50
+ super('NEW_ROUTE', Date.now());
51
+ this.previousRoute = previousRoute;
52
+ this.newRoute = newRoute;
53
+ }
54
+ }
55
+
56
+ class AppStateChangeEvent extends StateEvent {
57
+ previousState: string;
58
+ newState: string;
59
+
60
+ constructor(previousState: string, newState: string) {
61
+ super('APP_STATE_CHANGE', Date.now());
62
+ this.previousState = previousState;
63
+ this.newState = newState;
64
+ }
65
+ }
66
+
67
+ class NavigationStateEvent extends StateEvent {
68
+ eventType: 'START_VIEW' | 'STOP_VIEW' | 'DISCARDED';
69
+ view: string;
70
+ reason: StateEvent;
71
+ state: NavigationState;
72
+
73
+ constructor(
74
+ eventType: 'START_VIEW' | 'STOP_VIEW' | 'DISCARDED',
75
+ view: string,
76
+ reason: StateEvent | undefined,
77
+ state: NavigationState
78
+ ) {
79
+ super('NAVIGATION_STATE_EVENT', Date.now());
80
+ this.view = view;
81
+ this.eventType = eventType;
82
+ this.reason = reason ?? new StateEvent('UNKNOWN_EVENT', Date.now());
83
+ this.state = state;
84
+ }
85
+ }
86
+
87
+ export class NavigationTimeline {
88
+ readonly events: StateEvent[] = [];
89
+
90
+ addStartTrackingEvent(): StartTrackingStateEvent {
91
+ return this.addEvent(new StartTrackingStateEvent());
92
+ }
93
+
94
+ addStopTrackingEvent(): StopTrackingStateEvent {
95
+ return this.addEvent(new StopTrackingStateEvent());
96
+ }
97
+
98
+ addNewRouteEvent(
99
+ previousRoute: string | undefined,
100
+ newRoute: string | undefined
101
+ ): NewRouteStateEvent {
102
+ return this.addEvent(
103
+ new NewRouteStateEvent(
104
+ previousRoute ?? 'undefined',
105
+ newRoute ?? 'undefined'
106
+ )
107
+ );
108
+ }
109
+
110
+ addAppStateChangeEvent(
111
+ previousState: string | undefined,
112
+ newState: string
113
+ ): AppStateChangeEvent {
114
+ return this.addEvent(
115
+ new AppStateChangeEvent(previousState || 'undefined', newState)
116
+ );
117
+ }
118
+
119
+ addNavigationStateEvent(
120
+ eventType: NavigationStateEventType,
121
+ view: string,
122
+ reason: StateEvent | undefined,
123
+ state: NavigationState
124
+ ): NavigationStateEvent {
125
+ return this.addEvent(
126
+ new NavigationStateEvent(eventType, view, reason, state)
127
+ );
128
+ }
129
+
130
+ addEvent<T extends StateEvent>(stateEvent: T): T {
131
+ this.events.push(stateEvent);
132
+ return stateEvent;
133
+ }
134
+ }