@datadog/mobile-react-native 2.10.1 → 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 (63) hide show
  1. package/DatadogSDKReactNative.podspec +6 -6
  2. package/android/build.gradle +5 -5
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/ios/Sources/SdkVersion.swift +1 -1
  5. package/jest/mock.js +3 -0
  6. package/lib/commonjs/DdSdkReactNative.js +8 -1
  7. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  8. package/lib/commonjs/index.js +7 -0
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/rum/constants.js +14 -0
  11. package/lib/commonjs/rum/constants.js.map +1 -0
  12. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +92 -0
  13. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -0
  14. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +5 -0
  15. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  16. package/lib/commonjs/rum/types.js +7 -1
  17. package/lib/commonjs/rum/types.js.map +1 -1
  18. package/lib/commonjs/types.js.map +1 -1
  19. package/lib/commonjs/utils/telemetry.js +23 -0
  20. package/lib/commonjs/utils/telemetry.js.map +1 -0
  21. package/lib/commonjs/version.js +1 -1
  22. package/lib/module/DdSdkReactNative.js +9 -2
  23. package/lib/module/DdSdkReactNative.js.map +1 -1
  24. package/lib/module/index.js +6 -5
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/rum/constants.js +8 -0
  27. package/lib/module/rum/constants.js.map +1 -0
  28. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +84 -0
  29. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -0
  30. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +5 -0
  31. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  32. package/lib/module/rum/types.js +6 -0
  33. package/lib/module/rum/types.js.map +1 -1
  34. package/lib/module/types.js.map +1 -1
  35. package/lib/module/utils/telemetry.js +16 -0
  36. package/lib/module/utils/telemetry.js.map +1 -0
  37. package/lib/module/version.js +1 -1
  38. package/lib/typescript/DdSdkReactNative.d.ts +1 -1
  39. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  40. package/lib/typescript/index.d.ts +7 -6
  41. package/lib/typescript/index.d.ts.map +1 -1
  42. package/lib/typescript/rum/constants.d.ts +2 -0
  43. package/lib/typescript/rum/constants.d.ts.map +1 -0
  44. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts +24 -0
  45. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -0
  46. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts.map +1 -1
  47. package/lib/typescript/rum/types.d.ts +5 -0
  48. package/lib/typescript/rum/types.d.ts.map +1 -1
  49. package/lib/typescript/types.d.ts +3 -0
  50. package/lib/typescript/types.d.ts.map +1 -1
  51. package/lib/typescript/utils/telemetry.d.ts +7 -0
  52. package/lib/typescript/utils/telemetry.d.ts.map +1 -0
  53. package/lib/typescript/version.d.ts +1 -1
  54. package/package.json +2 -2
  55. package/src/DdSdkReactNative.tsx +21 -10
  56. package/src/index.tsx +11 -10
  57. package/src/rum/constants.ts +7 -0
  58. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +130 -0
  59. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +9 -1
  60. package/src/rum/types.ts +6 -0
  61. package/src/types.tsx +5 -0
  62. package/src/utils/telemetry.ts +17 -0
  63. package/src/version.ts +1 -1
@@ -0,0 +1,130 @@
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
+
7
+ import { InternalLog } from '../../../InternalLog';
8
+ import { SdkVerbosity } from '../../../SdkVerbosity';
9
+ import DdNativeRum from '../../../specs/NativeDdRum';
10
+ import DdSdk from '../../../specs/NativeDdSdk';
11
+ import { getBabelTelemetryConfig } from '../../../utils/telemetry';
12
+ import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
13
+ import type { TimeProvider } from '../../../utils/time-provider/TimeProvider';
14
+ import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
15
+ import type { RumActionType } from '../../types';
16
+ import { ActionSource } from '../../types';
17
+
18
+ const StateErrors = {
19
+ ALREADY_INITIALIZED:
20
+ 'Interaction Tracking singleton already initialized, please use `getInstance`.'
21
+ } as const;
22
+
23
+ type BabelConfig = {
24
+ trackInteractions: boolean;
25
+ useAccessibilityLabel: boolean;
26
+ };
27
+
28
+ type TargetObject = {
29
+ compoenentName: string;
30
+ 'dd-action-name': string;
31
+ accessibilityLabel: string;
32
+ [key: string]: string;
33
+ };
34
+
35
+ export class DdBabelInteractionTracking {
36
+ private static instance: DdBabelInteractionTracking | null = null;
37
+
38
+ static config: BabelConfig = {
39
+ trackInteractions: false,
40
+ useAccessibilityLabel: true
41
+ };
42
+
43
+ private timeProvider: TimeProvider = new DefaultTimeProvider();
44
+
45
+ private telemetrySent: boolean = false;
46
+
47
+ isInitialized: boolean = false;
48
+
49
+ private constructor() {
50
+ if (DdBabelInteractionTracking.instance) {
51
+ throw new Error(StateErrors.ALREADY_INITIALIZED);
52
+ }
53
+
54
+ DdBabelInteractionTracking.instance = this;
55
+ }
56
+
57
+ static getInstance() {
58
+ if (!DdBabelInteractionTracking.instance) {
59
+ DdBabelInteractionTracking.instance = new DdBabelInteractionTracking();
60
+ }
61
+
62
+ return DdBabelInteractionTracking.instance;
63
+ }
64
+
65
+ private getTargetName(targetObject: TargetObject) {
66
+ const {
67
+ componentName,
68
+ 'dd-action-name': actionName,
69
+ accessibilityLabel,
70
+ ...attrs
71
+ } = targetObject;
72
+
73
+ const { useAccessibilityLabel } = DdBabelInteractionTracking.config;
74
+
75
+ if (actionName) {
76
+ return actionName;
77
+ }
78
+
79
+ const keys = Object.keys(attrs);
80
+ if (keys.length) {
81
+ return attrs[keys[0]];
82
+ }
83
+
84
+ if (useAccessibilityLabel && accessibilityLabel) {
85
+ return accessibilityLabel;
86
+ }
87
+
88
+ return componentName;
89
+ }
90
+
91
+ wrapRumAction(
92
+ func: (...args: any[]) => any,
93
+ action: RumActionType,
94
+ targetObject: TargetObject
95
+ ): (...args: any[]) => any {
96
+ return (...args: any[]) => {
97
+ const result = func(...args);
98
+
99
+ if (!this.telemetrySent) {
100
+ DdSdk?.sendTelemetryLog(
101
+ BABEL_PLUGIN_TELEMETRY,
102
+ getBabelTelemetryConfig(),
103
+ { onlyOnce: true }
104
+ );
105
+
106
+ this.telemetrySent = true;
107
+ }
108
+
109
+ const targetName = this.getTargetName(targetObject);
110
+
111
+ const { trackInteractions } = DdBabelInteractionTracking.config;
112
+
113
+ if (trackInteractions) {
114
+ InternalLog.log(
115
+ `Adding RUM Action “${targetName}” (${action}, auto)`,
116
+ SdkVerbosity.DEBUG
117
+ );
118
+
119
+ DdNativeRum?.addAction(
120
+ action,
121
+ targetName,
122
+ { '__dd.action_source': ActionSource.BABEL },
123
+ this.timeProvider.now()
124
+ );
125
+ }
126
+
127
+ return result;
128
+ };
129
+ }
130
+ }
@@ -10,9 +10,11 @@ import { InternalLog } from '../../../InternalLog';
10
10
  import { SdkVerbosity } from '../../../SdkVerbosity';
11
11
  import { DdSdk } from '../../../sdk/DdSdk';
12
12
  import { getErrorMessage } from '../../../utils/errorUtils';
13
+ import { getBabelTelemetryConfig } from '../../../utils/telemetry';
14
+ import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
13
15
 
14
- import { DdEventsInterceptor } from './DdEventsInterceptor';
15
16
  import type { DdEventsInterceptorOptions } from './DdEventsInterceptor';
17
+ import { DdEventsInterceptor } from './DdEventsInterceptor';
16
18
  import type { EventsInterceptor } from './EventsInterceptor';
17
19
  import { NoOpEventsInterceptor } from './NoOpEventsInterceptor';
18
20
  import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
@@ -70,6 +72,12 @@ export class DdRumUserInteractionTracking {
70
72
  return;
71
73
  }
72
74
 
75
+ DdSdk?.sendTelemetryLog(
76
+ BABEL_PLUGIN_TELEMETRY,
77
+ getBabelTelemetryConfig(),
78
+ { onlyOnce: true }
79
+ );
80
+
73
81
  DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(
74
82
  options
75
83
  );
package/src/rum/types.ts CHANGED
@@ -255,6 +255,12 @@ export enum PropagatorType {
255
255
  B3MULTI = 'b3multi'
256
256
  }
257
257
 
258
+ export enum ActionSource {
259
+ MANUAL = 'MANUAL',
260
+ LEGACY = 'LEGACY',
261
+ BABEL = 'BABEL'
262
+ }
263
+
258
264
  export type FirstPartyHost = {
259
265
  match: string;
260
266
  propagatorTypes: PropagatorType[];
package/src/types.tsx CHANGED
@@ -6,6 +6,11 @@
6
6
 
7
7
  import type { BatchProcessingLevel } from './DdSdkReactNativeConfiguration';
8
8
 
9
+ declare global {
10
+ // eslint-disable-next-line no-var, vars-on-top
11
+ var __DD_RN_BABEL_PLUGIN_ENABLED__: boolean;
12
+ }
13
+
9
14
  /**
10
15
  * A configuration object to initialize Datadog's features.
11
16
  */
@@ -0,0 +1,17 @@
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
+
7
+ import { DdBabelInteractionTracking } from '../rum/instrumentation/interactionTracking/DdBabelInteractionTracking';
8
+
9
+ export const getBabelTelemetryConfig = () => {
10
+ return {
11
+ babel_plugin: {
12
+ enabled: !!globalThis.__DD_RN_BABEL_PLUGIN_ENABLED__,
13
+ track_interactions: !!DdBabelInteractionTracking.config
14
+ .trackInteractions
15
+ }
16
+ };
17
+ };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.10.1';
2
+ export const version = '2.11.0';