@datadog/mobile-react-native 3.5.4 → 3.6.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 (142) hide show
  1. package/README.md +10 -0
  2. package/android/build.gradle +14 -1
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +23 -4
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/HeatmapActionHandler.kt +121 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/HeatmapTouchResolver.kt +108 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +19 -2
  9. package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +1 -1
  10. package/android/src/oldarch/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +38 -0
  11. package/android/src/oldarch65/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +20 -0
  12. package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdRum.kt +15 -2
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +482 -0
  14. package/android/src/test/kotlin/com/datadog/reactnative/HeatmapTouchResolverTest.kt +529 -0
  15. package/datadog-configuration.schema.json +4 -0
  16. package/ios/Sources/DdSdk.mm +2 -0
  17. package/ios/Sources/DdSdkImplementation.swift +0 -1
  18. package/ios/Sources/SdkVersion.swift +1 -1
  19. package/lib/commonjs/DdSdkReactNative.js +3 -1
  20. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  21. package/lib/commonjs/config/FileBasedConfiguration.js +1 -0
  22. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  23. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +1 -0
  24. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  25. package/lib/commonjs/config/features/RumConfiguration.js +4 -0
  26. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +270 -0
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  33. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +33 -0
  34. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
  35. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +39 -0
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +109 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
  45. package/lib/commonjs/version.js +1 -1
  46. package/lib/module/DdSdkReactNative.js +3 -1
  47. package/lib/module/DdSdkReactNative.js.map +1 -1
  48. package/lib/module/config/FileBasedConfiguration.js +1 -0
  49. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  50. package/lib/module/config/async/AutoInstrumentationConfiguration.js +1 -0
  51. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  52. package/lib/module/config/features/RumConfiguration.js +4 -0
  53. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  54. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
  55. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  56. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +263 -0
  57. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
  58. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
  59. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  60. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +25 -0
  61. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
  62. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +32 -0
  63. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
  64. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
  65. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
  66. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
  67. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
  68. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +101 -0
  69. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
  70. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
  71. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
  72. package/lib/module/version.js +1 -1
  73. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  74. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  75. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +1 -0
  76. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  77. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +2 -0
  78. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  79. package/lib/typescript/config/features/RumConfiguration.d.ts +2 -0
  80. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  81. package/lib/typescript/config/features/RumConfiguration.type.d.ts +7 -0
  82. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  83. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -2
  84. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  85. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts +29 -0
  86. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -0
  87. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +1 -1
  88. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  89. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts +8 -0
  90. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts.map +1 -0
  91. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +20 -0
  92. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -0
  93. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.d.ts +2 -2
  94. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.d.ts.map +1 -0
  95. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts +3 -0
  96. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts.map +1 -0
  97. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts +18 -0
  98. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts.map +1 -0
  99. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.d.ts +0 -6
  100. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.d.ts.map +1 -0
  101. package/lib/typescript/version.d.ts +1 -1
  102. package/package.json +11 -2
  103. package/src/DdSdkReactNative.tsx +5 -1
  104. package/src/__tests__/DdSdkReactNative.test.tsx +5 -2
  105. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
  106. package/src/config/FileBasedConfiguration.ts +2 -0
  107. package/src/config/FileBasedConfiguration.type.ts +1 -0
  108. package/src/config/__tests__/FileBasedConfiguration.test.ts +3 -0
  109. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +1 -0
  110. package/src/config/async/AutoInstrumentationConfiguration.ts +5 -0
  111. package/src/config/features/RumConfiguration.ts +4 -0
  112. package/src/config/features/RumConfiguration.type.ts +8 -0
  113. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +38 -13
  114. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +101 -0
  115. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +316 -0
  116. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +393 -0
  117. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +1 -1
  118. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +1 -1
  119. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +49 -115
  120. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +1 -1
  121. package/src/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.ts +25 -0
  122. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +54 -0
  123. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.ts +5 -5
  124. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.ts +1 -17
  125. package/src/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.ts +106 -0
  126. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.ts +0 -18
  127. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +1 -0
  128. package/src/version.ts +1 -1
  129. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
  130. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  131. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
  133. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  134. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
  135. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.d.ts.map +0 -1
  136. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts +0 -7
  137. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts.map +0 -1
  138. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.d.ts.map +0 -1
  139. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdFlags.kt +0 -0
  140. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdLogs.kt +0 -0
  141. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdSdk.kt +0 -0
  142. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdTrace.kt +0 -0
package/README.md CHANGED
@@ -47,6 +47,7 @@ const datadogConfiguration = new DatadogProviderConfiguration(
47
47
  applicationId: '<RUM_APPLICATION_ID>',
48
48
  trackInteractions: true, // track User interactions (e.g.: Tap on buttons. You can use 'accessibilityLabel' element property to give tap action the name, otherwise element type will be reported)
49
49
  trackResources: true, // track XHR Resources
50
+ trackFetchResources: true, // Optional: also track requests made with the global Expo Fetch implementation
50
51
  trackFrustrations: true, // track Frustrations
51
52
  trackErrors: true, // track errors
52
53
  nativeCrashReportEnabled: true, // Optional: enable or disable native crash reports
@@ -80,6 +81,15 @@ export default function App() {
80
81
  }
81
82
  ```
82
83
 
84
+ `trackFetchResources` tracks calls made through the Expo-installed global
85
+ `fetch`. Direct imports retained from `expo/fetch` are not intercepted. XHR
86
+ tracking remains enabled for clients such as axios.
87
+
88
+ GraphQL error extraction (via `DatadogLink({ trackErrors: true })`) for
89
+ requests made through `expo/fetch` requires Expo SDK 56 or later, as older
90
+ versions of `expo/fetch` do not implement `Response.clone()`. On earlier
91
+ versions, GraphQL metadata is still reported, but response errors are not.
92
+
83
93
  ### Track view navigation
84
94
 
85
95
  Because React Native offers a wide range of libraries to create screen navigation, by default only manual View tracking is supported. You can manually start and stop a View using the following `startView()` and `stopView` methods.
@@ -138,7 +138,20 @@ android {
138
138
  if (isNewArchitectureEnabled()) {
139
139
  java.srcDirs += ['src/newarch/kotlin']
140
140
  } else {
141
- java.srcDirs += ['src/oldarch/kotlin']
141
+ // `oldarchCommon` holds everything shared by all old-architecture RN versions.
142
+ // Version-specific pieces (currently just heatmap tap-to-view resolution, whose
143
+ // `UIManager.resolveView` API was added in RN 0.66) live in their own small source set,
144
+ // named `oldarch<N>` for the highest old-arch minor version they cover (inclusive) —
145
+ // e.g. `oldarch65` for RN <= 65. The bare `oldarch` directory has no number because it
146
+ // always means "newer than the highest split defined" (today: RN > 65); if a future RN
147
+ // release breaks another old-arch API, split off the next `oldarch<N>` the same way and
148
+ // `oldarch` keeps that same "later than the highest split" meaning.
149
+ java.srcDirs += ['src/oldarchCommon/kotlin']
150
+ if (reactNativeMajorVersion == 0 && reactNativeMinorVersion <= 65) {
151
+ java.srcDirs += ['src/oldarch65/kotlin']
152
+ } else {
153
+ java.srcDirs += ['src/oldarch/kotlin']
154
+ }
142
155
  }
143
156
  }
144
157
  test {
@@ -22,7 +22,10 @@ import java.util.Locale
22
22
  * The entry point to use Datadog's RUM feature.
23
23
  */
24
24
  @Suppress("TooManyFunctions")
25
- class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrapper()) {
25
+ class DdRumImplementation internal constructor(
26
+ private val datadog: DatadogWrapper = DatadogSDKWrapper(),
27
+ private val heatmapActionHandler: HeatmapActionHandler = HeatmapActionHandler()
28
+ ) {
26
29
  /**
27
30
  * Start tracking a RUM View.
28
31
  * @param key The view unique key identifier.
@@ -120,11 +123,10 @@ class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrappe
120
123
  * @param type The action type (tap, scroll, swipe, click, custom).
121
124
  * @param name The action name.
122
125
  * @param touch The native touch data for tap actions, or null for other action types.
123
- * Currently unused on Android; reserved for heatmap support.
124
126
  * @param context The additional context to send.
125
127
  * @param timestampMs The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
126
128
  */
127
- @Suppress("LongParameterList", "UnusedParameter")
129
+ @Suppress("LongParameterList")
128
130
  fun addAction(
129
131
  type: String,
130
132
  name: String,
@@ -136,12 +138,28 @@ class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrappe
136
138
  val attributes = context.toHashMap().toMutableMap().apply {
137
139
  put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong())
138
140
  }
141
+
142
+ val eligibleAction = heatmapActionHandler.resolveEligibility(datadog, type, name, touch)
143
+ if (eligibleAction == null) {
144
+ addActionWithoutHeatmap(type, name, attributes)
145
+ promise.resolve(null)
146
+ return
147
+ }
148
+
149
+ // Resolve before dispatching heatmap work (iOS parity).
150
+ promise.resolve(null)
151
+
152
+ heatmapActionHandler.attachHeatmapData(eligibleAction, name, attributes) {
153
+ addActionWithoutHeatmap(type, name, attributes)
154
+ }
155
+ }
156
+
157
+ private fun addActionWithoutHeatmap(type: String, name: String, attributes: Map<String, Any?>) {
139
158
  datadog.getRumMonitor().addAction(
140
159
  type = type.asRumActionType(),
141
160
  name = name,
142
161
  attributes = attributes
143
162
  )
144
- promise.resolve(null)
145
163
  }
146
164
 
147
165
  /**
@@ -460,6 +478,7 @@ class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrappe
460
478
  }
461
479
 
462
480
  // endregion
481
+
463
482
  @Suppress("UndocumentedPublicClass")
464
483
  companion object {
465
484
  private const val MISSING_RESOURCE_SIZE = -1L
@@ -34,7 +34,6 @@ import com.datadog.android.trace.TraceConfiguration
34
34
  import com.datadog.android.ndk.NdkCrashReports
35
35
  import com.google.gson.Gson
36
36
  import java.util.Locale
37
- import kotlin.time.Duration.Companion.seconds
38
37
 
39
38
 
40
39
  /**
@@ -250,7 +249,7 @@ class DdSdkNativeInitialization internal constructor(
250
249
  }
251
250
 
252
251
  configuration.rumConfiguration?.initialResourceThreshold?.let {
253
- val milliseconds = it.seconds.inWholeMilliseconds
252
+ val milliseconds = (it * MILLISECONDS_IN_SECOND).toLong()
254
253
  configBuilder.setInitialResourceIdentifier(TimeBasedInitialResourceIdentifier(milliseconds))
255
254
  }
256
255
 
@@ -409,6 +408,8 @@ class DdSdkNativeInitialization internal constructor(
409
408
 
410
409
  @Suppress("UndocumentedPublicClass")
411
410
  companion object {
411
+ private const val MILLISECONDS_IN_SECOND = 1000
412
+
412
413
  /**
413
414
  * Initializes the Datadog React Native SDK from your MainApplication.
414
415
  *
@@ -0,0 +1,121 @@
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
+ package com.datadog.reactnative
8
+
9
+ import android.os.Handler
10
+ import android.os.Looper
11
+ import com.datadog.android.api.InternalLogger
12
+ import com.datadog.android.rum.RumActionType
13
+ import com.datadog.android.rum._RumInternalProxy
14
+ import com.facebook.react.bridge.ReadableMap
15
+
16
+ /**
17
+ * Decides whether an `addAction` call is eligible for heatmap tracking and, if so, resolves and
18
+ * attaches the heatmap data via [HeatmapTouchResolver]. Split into two steps so the caller can
19
+ * resolve its own promise between them, before the heatmap work dispatches.
20
+ */
21
+ class HeatmapActionHandler internal constructor(
22
+ private val heatmapTouchResolver: HeatmapTouchResolver = HeatmapTouchResolver(),
23
+ private val mainThreadExecutor: (() -> Unit) -> Unit = defaultMainThreadExecutor()
24
+ ) {
25
+
26
+ internal data class EligibleAction(
27
+ val internalProxy: _RumInternalProxy,
28
+ val viewUrl: String,
29
+ val reactTag: Int,
30
+ val positionX: Long,
31
+ val positionY: Long
32
+ )
33
+
34
+ internal fun resolveEligibility(
35
+ datadog: DatadogWrapper,
36
+ type: String,
37
+ name: String,
38
+ touch: ReadableMap?
39
+ ): EligibleAction? {
40
+ if (!heatmapsEnabled || touch == null || !type.equals("tap", ignoreCase = true)) {
41
+ return null
42
+ }
43
+
44
+ val internalProxy = datadog.getRumMonitor()._getInternal()
45
+ // Read now — the view can transition asynchronously right after a tap.
46
+ val viewUrl = internalProxy?.getCurrentViewUrl()
47
+ val touchFields = touch.toTouchFieldsOrNull(name)
48
+
49
+ return if (internalProxy != null && viewUrl != null && touchFields != null) {
50
+ val (reactTag, positionX, positionY) = touchFields
51
+ EligibleAction(internalProxy, viewUrl, reactTag, positionX, positionY)
52
+ } else {
53
+ null
54
+ }
55
+ }
56
+
57
+ internal fun attachHeatmapData(
58
+ eligibleAction: EligibleAction,
59
+ name: String,
60
+ attributes: Map<String, Any?>,
61
+ fallback: () -> Unit
62
+ ) {
63
+ mainThreadExecutor {
64
+ val heatmapData = heatmapTouchResolver.resolveHeatmapActionData(
65
+ eligibleAction.reactTag,
66
+ eligibleAction.positionX,
67
+ eligibleAction.positionY,
68
+ eligibleAction.viewUrl
69
+ )
70
+ if (heatmapData != null) {
71
+ eligibleAction.internalProxy.addActionWithHeatmap(
72
+ type = RumActionType.TAP,
73
+ name = name,
74
+ crossPlatformHeatmapActionData = heatmapData,
75
+ attributes = attributes
76
+ )
77
+ } else {
78
+ fallback()
79
+ }
80
+ }
81
+ }
82
+
83
+ // Missing fields are not warned on: `actionContext` is an optional addAction parameter, and
84
+ // a caller intentionally tracking a TAP action without real touch coordinates is valid usage.
85
+ private fun ReadableMap.toTouchFieldsOrNull(actionName: String): Triple<Int, Long, Long>? {
86
+ if (!hasKey("reactTag") || !hasKey("x") || !hasKey("y")) return null
87
+ return runCatching {
88
+ Triple(getInt("reactTag"), getDouble("x").toLong(), getDouble("y").toLong())
89
+ }.onFailure {
90
+ InternalLogger.UNBOUND.log(
91
+ InternalLogger.Level.WARN,
92
+ InternalLogger.Target.USER,
93
+ {
94
+ "addAction(\"$actionName\"): heatmap tracking requires actionContext's " +
95
+ "nativeEvent.target/locationX/locationY to be numbers, as produced by a " +
96
+ "standard onPress GestureResponderEvent. The value passed for this " +
97
+ "action didn't match that shape, so heatmap tracking was skipped for it " +
98
+ "— this is expected if actionContext came from a non-standard event " +
99
+ "source (e.g. a different gesture library)."
100
+ },
101
+ throwable = it,
102
+ onlyOnce = true
103
+ )
104
+ }.getOrNull()
105
+ }
106
+
107
+ @Suppress("UndocumentedPublicClass")
108
+ companion object {
109
+ private fun defaultMainThreadExecutor(): ((() -> Unit) -> Unit) {
110
+ val handler by lazy { Handler(Looper.getMainLooper()) }
111
+ return { action -> handler.post(action) }
112
+ }
113
+
114
+ /**
115
+ * Whether heatmap data should be attached to TAP actions. Set by
116
+ * [com.datadog.reactnative.sessionreplay.DdSessionReplayImplementation.enable].
117
+ */
118
+ @Volatile
119
+ var heatmapsEnabled: Boolean = false
120
+ }
121
+ }
@@ -0,0 +1,108 @@
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
+ package com.datadog.reactnative
8
+
9
+ import android.content.res.Resources
10
+ import android.view.View
11
+ import android.view.ViewGroup
12
+ import com.datadog.android.heatmaps.CrossPlatformHeatmapActionData
13
+
14
+ /**
15
+ * Resolves a React Native touch into [CrossPlatformHeatmapActionData] by walking the view
16
+ * hierarchy to the nearest clickable-and-visible ancestor — matching Session Replay's own
17
+ * `HeatmapIdentifierResolver` rule — and building its element path using the same convention, so
18
+ * the resulting hash matches the `permanentId` SR assigned to that view's wireframe.
19
+ */
20
+ internal class HeatmapTouchResolver(
21
+ private val viewResolver: (Int) -> View? = { null },
22
+ private val telemetry: DdTelemetry = DdTelemetry()
23
+ ) {
24
+
25
+ /** Returns null if [reactTag] doesn't resolve to a valid tap target. */
26
+ fun resolveHeatmapActionData(
27
+ reactTag: Int,
28
+ positionX: Long,
29
+ positionY: Long,
30
+ viewUrl: String
31
+ ): CrossPlatformHeatmapActionData? = runCatching {
32
+ val view = viewResolver(reactTag)?.let { clickableVisibleAncestorOf(it) }
33
+ val elementPath = view?.let { elementPathFromRootTo(it) }
34
+
35
+ if (view != null && !elementPath.isNullOrEmpty()) {
36
+ val density = view.resources?.displayMetrics?.density ?: 1f
37
+ val targetWidth = (view.width / density).toLong().takeIf { it > 0 }
38
+ val targetHeight = (view.height / density).toLong().takeIf { it > 0 }
39
+
40
+ CrossPlatformHeatmapActionData(
41
+ elementPath = elementPath,
42
+ viewUrl = viewUrl,
43
+ positionX = positionX,
44
+ positionY = positionY,
45
+ targetWidth = targetWidth,
46
+ targetHeight = targetHeight
47
+ )
48
+ } else {
49
+ null
50
+ }
51
+ }.onFailure {
52
+ telemetry.telemetryError("Failed to resolve heatmap action data", it)
53
+ }.getOrNull()
54
+
55
+ // region Private helpers
56
+
57
+ private fun clickableVisibleAncestorOf(view: View): View? {
58
+ var current: View? = view
59
+ while (current != null) {
60
+ if (current.isClickable && current.visibility == View.VISIBLE) {
61
+ return current
62
+ }
63
+ current = current.parent as? View
64
+ }
65
+ return null
66
+ }
67
+
68
+ private fun elementPathFromRootTo(view: View): List<String> {
69
+ val path = mutableListOf<String>()
70
+ var current: View? = view
71
+ while (current != null) {
72
+ val parent = current.parent as? ViewGroup
73
+ val typeIndex = if (parent != null) computeTypeIndex(current, parent) else 0
74
+ path.add(pathComponentFor(current, typeIndex))
75
+ current = parent
76
+ }
77
+ path.reverse()
78
+ return path
79
+ }
80
+
81
+ private fun computeTypeIndex(view: View, parent: ViewGroup): Int {
82
+ val cls = view.javaClass
83
+ var index = 0
84
+ for (i in 0 until parent.childCount) {
85
+ val child = parent.getChildAt(i) ?: continue
86
+ if (child === view) break
87
+ if (child.javaClass === cls) index++
88
+ }
89
+ return index
90
+ }
91
+
92
+ private fun pathComponentFor(view: View, typeIndex: Int): String {
93
+ val viewId = view.id
94
+ if (viewId != View.NO_ID) {
95
+ try {
96
+ @Suppress("UnsafeThirdPartyFunctionCall")
97
+ val name = view.resources?.getResourceName(viewId)
98
+ if (!name.isNullOrEmpty()) {
99
+ return "$name#$typeIndex"
100
+ }
101
+ } catch (_: Resources.NotFoundException) {
102
+ }
103
+ }
104
+ return "cls:${view.javaClass.name}#$typeIndex"
105
+ }
106
+
107
+ // endregion
108
+ }
@@ -7,4 +7,4 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- internal const val SDK_VERSION = "3.5.4"
10
+ internal const val SDK_VERSION = "3.6.0"
@@ -12,6 +12,8 @@ import com.facebook.react.bridge.ReactApplicationContext
12
12
  import com.facebook.react.bridge.ReactMethod
13
13
  import com.facebook.react.bridge.ReadableArray
14
14
  import com.facebook.react.bridge.ReadableMap
15
+ import com.facebook.react.uimanager.UIManagerHelper
16
+ import com.facebook.react.uimanager.common.ViewUtil
15
17
 
16
18
  /**
17
19
  * The entry point to use Datadog's RUM feature.
@@ -22,7 +24,23 @@ class DdRum(
22
24
  datadogWrapper: DatadogWrapper = DatadogSDKWrapper()
23
25
  ) : NativeDdRumSpec(reactContext) {
24
26
 
25
- private val implementation = DdRumImplementation(datadog = datadogWrapper)
27
+ private val telemetry = DdTelemetry()
28
+
29
+ private val implementation = DdRumImplementation(
30
+ datadog = datadogWrapper,
31
+ heatmapActionHandler = HeatmapActionHandler(
32
+ heatmapTouchResolver = HeatmapTouchResolver(viewResolver = { reactTag ->
33
+ try {
34
+ val uiManagerType = ViewUtil.getUIManagerType(reactTag)
35
+ UIManagerHelper.getUIManager(reactApplicationContext, uiManagerType)
36
+ ?.resolveView(reactTag)
37
+ } catch (e: Exception) {
38
+ telemetry.telemetryError("Failed to resolve view for heatmap tracking", e)
39
+ null
40
+ }
41
+ })
42
+ )
43
+ )
26
44
 
27
45
  override fun getName(): String = DdRumImplementation.NAME
28
46
 
@@ -105,7 +123,6 @@ class DdRum(
105
123
  * @param type The action type (tap, scroll, swipe, click, custom).
106
124
  * @param name The action name.
107
125
  * @param touch The native touch data for tap actions, or null for other action types.
108
- * Currently unused on Android; reserved for heatmap support.
109
126
  * @param context The additional context to send.
110
127
  * @param timestampMs The timestamp when the action occurred (in milliseconds).
111
128
  * If not provided, current timestamp will be used.
@@ -201,7 +201,7 @@ class DdSdk(
201
201
  private fun registerLifecycleEvents(reactContext: ReactApplicationContext) {
202
202
  reactContext.addLifecycleEventListener(object : LifecycleEventListener {
203
203
  override fun onHostResume() {
204
- val currentActivity: Activity? = currentActivity
204
+ val currentActivity: Activity? = reactContext.currentActivity
205
205
  if (currentActivity != null) {
206
206
  val intent = currentActivity.intent
207
207
  val extras = intent.extras
@@ -0,0 +1,38 @@
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
+ package com.datadog.reactnative
8
+
9
+ import android.view.View
10
+ import com.facebook.react.bridge.ReactApplicationContext
11
+ import com.facebook.react.uimanager.UIManagerHelper
12
+ import com.facebook.react.uimanager.common.UIManagerType
13
+
14
+ /**
15
+ * Resolves a React tag to its native [View] for heatmap tap tracking, via
16
+ * `UIManager.resolveView(reactTag)`. That method exists on the old-architecture `UIManager`
17
+ * interface from React Native 0.66 onward — see the `oldarch65` source set's counterpart of
18
+ * this function for RN <= 65, where it doesn't exist.
19
+ *
20
+ * This is the base `oldarch` source set, used whenever no more specific split applies: it
21
+ * covers every old-architecture RN version newer than the highest version-specific split
22
+ * defined (currently `oldarch65`). If a future RN release removes/changes another API this
23
+ * function (or another old-arch file) depends on, split off a new `oldarch<N>` source set named
24
+ * for the highest old-arch minor version it covers — e.g. `oldarch70` for RN <= 70 — following
25
+ * this same pattern, and this directory keeps meaning "later than the highest split."
26
+ */
27
+ internal fun createHeatmapViewResolver(
28
+ reactApplicationContext: ReactApplicationContext,
29
+ telemetry: DdTelemetry
30
+ ): (Int) -> View? = { reactTag ->
31
+ try {
32
+ UIManagerHelper.getUIManager(reactApplicationContext, UIManagerType.DEFAULT)
33
+ ?.resolveView(reactTag)
34
+ } catch (e: Exception) {
35
+ telemetry.telemetryError("Failed to resolve view for heatmap tracking", e)
36
+ null
37
+ }
38
+ }
@@ -0,0 +1,20 @@
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
+ package com.datadog.reactnative
8
+
9
+ import android.view.View
10
+ import com.facebook.react.bridge.ReactApplicationContext
11
+
12
+ /**
13
+ * `UIManager.resolveView(reactTag)` was added in React Native 0.66; the old-architecture
14
+ * `UIManager` interface doesn't declare it on RN <= 65 (this source set), so a React tag can't
15
+ * be resolved to its native [View] for heatmap tap tracking here — this always returns null.
16
+ */
17
+ internal fun createHeatmapViewResolver(
18
+ reactApplicationContext: ReactApplicationContext,
19
+ telemetry: DdTelemetry
20
+ ): (Int) -> View? = { null }
@@ -23,7 +23,21 @@ class DdRum(
23
23
  datadogWrapper: DatadogWrapper = DatadogSDKWrapper()
24
24
  ) : ReactContextBaseJavaModule(reactContext) {
25
25
 
26
- private val implementation = DdRumImplementation(datadog = datadogWrapper)
26
+ private val telemetry = DdTelemetry()
27
+
28
+ // `createHeatmapViewResolver` is version-gated at the source-set level: it resolves a React
29
+ // tag to its native View via `UIManager.resolveView`, which only exists on the
30
+ // old-architecture `UIManager` interface from React Native 0.66 onward. See
31
+ // HeatmapViewResolverFactory.kt in the `oldarch` (RN > 65) and `oldarch65` (RN <= 65, no-op)
32
+ // source sets.
33
+ private val implementation = DdRumImplementation(
34
+ datadog = datadogWrapper,
35
+ heatmapActionHandler = HeatmapActionHandler(
36
+ heatmapTouchResolver = HeatmapTouchResolver(
37
+ viewResolver = createHeatmapViewResolver(reactApplicationContext, telemetry)
38
+ )
39
+ )
40
+ )
27
41
 
28
42
  override fun getName(): String = DdRumImplementation.NAME
29
43
 
@@ -98,7 +112,6 @@ class DdRum(
98
112
  * @param type The action type (tap, scroll, swipe, click, custom).
99
113
  * @param name The action name.
100
114
  * @param touch The native touch data for tap actions, or null for other action types.
101
- * Currently unused on Android; reserved for heatmap support.
102
115
  * @param context The additional context to send.
103
116
  * @param timestampMs The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
104
117
  */