@datadog/mobile-react-native 1.1.1 → 1.1.2
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/DatadogSDKReactNative.podspec +2 -2
- package/README.md +2 -2
- package/android/build.gradle +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +5 -5
- package/ios/Sources/DdSdk.swift +1 -0
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +32 -11
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +32 -11
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +15 -0
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +47 -16
- package/src/version.ts +1 -1
|
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/Sources/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
19
|
s.dependency "React-Core"
|
|
20
|
-
s.dependency 'DatadogSDK', '~> 1.12.0
|
|
21
|
-
s.dependency 'DatadogSDKCrashReporting', '~> 1.12.0
|
|
20
|
+
s.dependency 'DatadogSDK', '~> 1.12.0'
|
|
21
|
+
s.dependency 'DatadogSDKCrashReporting', '~> 1.12.0'
|
|
22
22
|
|
|
23
23
|
s.test_spec 'Tests' do |test_spec|
|
|
24
24
|
test_spec.source_files = 'ios/Tests/*.swift'
|
package/README.md
CHANGED
|
@@ -79,11 +79,11 @@ import {
|
|
|
79
79
|
} from '@datadog/mobile-react-native';
|
|
80
80
|
|
|
81
81
|
// Start a view with a unique view identifier, a custom view url, and an object to attach additional attributes to the view
|
|
82
|
-
DdRum.startView('
|
|
82
|
+
DdRum.startView('ViewKey', 'ViewName', Date.now(), {
|
|
83
83
|
'custom.foo': 'something'
|
|
84
84
|
});
|
|
85
85
|
// Stops a previously started view with the same unique view identifier, and an object to attach additional attributes to the view
|
|
86
|
-
DdRum.stopView('
|
|
86
|
+
DdRum.stopView('ViewKey', Date.now(), { 'custom.bar': 42 });
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
## Data Storage
|
package/android/build.gradle
CHANGED
|
@@ -149,7 +149,7 @@ dependencies {
|
|
|
149
149
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
150
150
|
compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
|
|
151
151
|
|
|
152
|
-
implementation "com.datadoghq:dd-sdk-android:1.14.0
|
|
152
|
+
implementation "com.datadoghq:dd-sdk-android:1.14.0"
|
|
153
153
|
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
|
|
154
154
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
|
|
155
155
|
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
|
|
@@ -18,12 +18,12 @@ internal class ProxyAuthenticator(
|
|
|
18
18
|
internal val password: String
|
|
19
19
|
) : Authenticator {
|
|
20
20
|
override fun authenticate(route: Route?, response: Response): Request? {
|
|
21
|
-
val proxyAuthorization = response.code == PROXY_AUTHORIZATION_REQUIRED_STATUS_CODE
|
|
21
|
+
val proxyAuthorization = response.code() == PROXY_AUTHORIZATION_REQUIRED_STATUS_CODE
|
|
22
22
|
|
|
23
23
|
if (!proxyAuthorization) {
|
|
24
24
|
Log.w(
|
|
25
25
|
ProxyAuthenticator::class.java.canonicalName,
|
|
26
|
-
"Unexpected response code=${response.code}" +
|
|
26
|
+
"Unexpected response code=${response.code()}" +
|
|
27
27
|
" received during proxy authentication request."
|
|
28
28
|
)
|
|
29
29
|
return null
|
|
@@ -31,16 +31,16 @@ internal class ProxyAuthenticator(
|
|
|
31
31
|
|
|
32
32
|
val challenges = response.challenges()
|
|
33
33
|
for (challenge in challenges) {
|
|
34
|
-
val scheme = challenge.scheme
|
|
34
|
+
val scheme = challenge.scheme()
|
|
35
35
|
if ("Basic".equals(scheme, ignoreCase = true) ||
|
|
36
36
|
"OkHttp-Preemptive".equals(scheme, ignoreCase = true)
|
|
37
37
|
) {
|
|
38
38
|
val credential = Credentials.basic(
|
|
39
39
|
username,
|
|
40
40
|
password,
|
|
41
|
-
challenge.charset
|
|
41
|
+
challenge.charset()
|
|
42
42
|
)
|
|
43
|
-
return response.request.newBuilder()
|
|
43
|
+
return response.request().newBuilder()
|
|
44
44
|
.header("Proxy-Authorization", credential)
|
|
45
45
|
.build()
|
|
46
46
|
}
|
package/ios/Sources/DdSdk.swift
CHANGED
|
@@ -43,6 +43,7 @@ class RNDdSdk: NSObject {
|
|
|
43
43
|
// Initializing the SDK twice results in Global.rum and
|
|
44
44
|
// Global.sharedTracer to be set to no-op instances
|
|
45
45
|
consolePrint("Datadog SDK is already initialized, skipping initialization.")
|
|
46
|
+
resolve(nil)
|
|
46
47
|
return
|
|
47
48
|
}
|
|
48
49
|
let sdkConfiguration = configuration.asDdSdkConfiguration()
|
|
@@ -42,22 +42,26 @@ class DdRumUserInteractionTracking {
|
|
|
42
42
|
DdRumUserInteractionTracking.eventsInterceptor = new _DdEventsInterceptor.DdEventsInterceptor();
|
|
43
43
|
const original = _react.default.createElement;
|
|
44
44
|
|
|
45
|
-
_react.default.createElement = (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const originalOnPress = props.onPress;
|
|
45
|
+
_react.default.createElement = (...args) => {
|
|
46
|
+
return this.patchCreateElementFunction(original, args);
|
|
47
|
+
};
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
try {
|
|
50
|
+
// We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
51
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
52
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
54
53
|
|
|
54
|
+
const originaljsx = jsxRuntime.jsx;
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
if (!originaljsx) {
|
|
57
|
+
throw new Error('React version does not support new jsx transform');
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
jsxRuntime.jsx = (...args) => {
|
|
61
|
+
return this.patchCreateElementFunction(originaljsx, args);
|
|
62
|
+
};
|
|
63
|
+
} catch (e) {// TODO: Add telemetry
|
|
64
|
+
}
|
|
61
65
|
|
|
62
66
|
const originalMemo = _react.default.memo;
|
|
63
67
|
|
|
@@ -99,4 +103,21 @@ exports.DdRumUserInteractionTracking = DdRumUserInteractionTracking;
|
|
|
99
103
|
_defineProperty(DdRumUserInteractionTracking, "isTracking", false);
|
|
100
104
|
|
|
101
105
|
_defineProperty(DdRumUserInteractionTracking, "eventsInterceptor", new _NoOpEventsInterceptor.default());
|
|
106
|
+
|
|
107
|
+
_defineProperty(DdRumUserInteractionTracking, "patchCreateElementFunction", (originalFunction, [element, props, ...rest]) => {
|
|
108
|
+
if (props && typeof props.onPress === 'function') {
|
|
109
|
+
const originalOnPress = props. // eslint-disable-next-line @typescript-eslint/ban-types
|
|
110
|
+
onPress;
|
|
111
|
+
|
|
112
|
+
props.onPress = (...args) => {
|
|
113
|
+
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(...args);
|
|
114
|
+
return originalOnPress(...args);
|
|
115
|
+
}; // we store the original onPress prop so we can keep memoization working
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return originalFunction(element, props, ...rest);
|
|
122
|
+
});
|
|
102
123
|
//# sourceMappingURL=DdRumUserInteractionTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["DdRumUserInteractionTracking","startTracking","isTracking","InternalLog","log","SdkVerbosity","WARN","eventsInterceptor","DdEventsInterceptor","original","React","createElement","
|
|
1
|
+
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["DdRumUserInteractionTracking","startTracking","isTracking","InternalLog","log","SdkVerbosity","WARN","eventsInterceptor","DdEventsInterceptor","original","React","createElement","args","patchCreateElementFunction","jsxRuntime","require","originaljsx","jsx","Error","e","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","NoOpEventsInterceptor","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;AAEA;;AAEA;;AACA;;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AA6BtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,4BAA4B,CAACE,UAAjC,EAA6C;AACzCC,+BAAYC,GAAZ,CACI,8CADJ,EAEIC,2BAAaC,IAFjB;;AAIA;AACH;;AACDN,IAAAA,4BAA4B,CAACO,iBAA7B,GAAiD,IAAIC,wCAAJ,EAAjD;AAEA,UAAMC,QAAQ,GAAGC,eAAMC,aAAvB;;AACAD,mBAAMC,aAAN,GAAsB,CAClB,GAAGC,IADe,KAEZ;AACN,aAAO,KAAKC,0BAAL,CAAgCJ,QAAhC,EAA0CG,IAA1C,CAAP;AACH,KAJD;;AAMA,QAAI;AACA;AACA;AACA,YAAME,UAAU,GAAGC,OAAO,CAAC,mBAAD,CAA1B;;AACA,YAAMC,WAAW,GAAGF,UAAU,CAACG,GAA/B;;AACA,UAAI,CAACD,WAAL,EAAkB;AACd,cAAM,IAAIE,KAAJ,CACF,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A7BlC,4B,gBACmB,K;;gBADnBA,4B,uBAE6C,IAAImC,8BAAJ,E;;gBAF7CnC,4B,gCAImC,CACxCoC,gBADwC,EAExC,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAFwC,KAGC;AACzC,MACID,KAAK,IACL,OAAQA,KAAD,CAAmCZ,OAA1C,KAAsD,UAF1D,EAGE;AACE,UAAMc,eAAe,GAAIF,KAAD,EAAmC;AACtDZ,IAAAA,OADL;;AAECY,IAAAA,KAAD,CAAmCZ,OAAnC,GAA6C,CAAC,GAAGd,IAAJ,KAAoB;AAC7DZ,MAAAA,4BAA4B,CAACO,iBAA7B,CAA+CkC,gBAA/C,CACI,GAAG7B,IADP;AAGA,aAAO4B,eAAe,CAAC,GAAG5B,IAAJ,CAAtB;AACH,KALD,CAHF,CASE;;;AACC0B,IAAAA,KAAD,CAGGR,sCAHH,GAG4CU,eAH5C;AAIH;;AACD,SAAOJ,gBAAgB,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,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 React from 'react';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n // We have to use inline require here because older React versions (below 17) don't have jsx-runtime\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n const originaljsx = jsxRuntime.jsx;\n if (!originaljsx) {\n throw new Error(\n 'React version does not support new jsx transform'\n );\n }\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originaljsx, args);\n };\n } catch (e) {\n // TODO: Add telemetry\n }\n\n const originalMemo = React.memo;\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n}\n"]}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.2';\n"]}
|
|
@@ -32,22 +32,26 @@ export class DdRumUserInteractionTracking {
|
|
|
32
32
|
DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();
|
|
33
33
|
const original = React.createElement;
|
|
34
34
|
|
|
35
|
-
React.createElement = (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const originalOnPress = props.onPress;
|
|
35
|
+
React.createElement = (...args) => {
|
|
36
|
+
return this.patchCreateElementFunction(original, args);
|
|
37
|
+
};
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
try {
|
|
40
|
+
// We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
41
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
42
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
44
43
|
|
|
44
|
+
const originaljsx = jsxRuntime.jsx;
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
if (!originaljsx) {
|
|
47
|
+
throw new Error('React version does not support new jsx transform');
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
jsxRuntime.jsx = (...args) => {
|
|
51
|
+
return this.patchCreateElementFunction(originaljsx, args);
|
|
52
|
+
};
|
|
53
|
+
} catch (e) {// TODO: Add telemetry
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
const originalMemo = React.memo;
|
|
53
57
|
|
|
@@ -86,4 +90,21 @@ export class DdRumUserInteractionTracking {
|
|
|
86
90
|
_defineProperty(DdRumUserInteractionTracking, "isTracking", false);
|
|
87
91
|
|
|
88
92
|
_defineProperty(DdRumUserInteractionTracking, "eventsInterceptor", new NoOpEventsInterceptor());
|
|
93
|
+
|
|
94
|
+
_defineProperty(DdRumUserInteractionTracking, "patchCreateElementFunction", (originalFunction, [element, props, ...rest]) => {
|
|
95
|
+
if (props && typeof props.onPress === 'function') {
|
|
96
|
+
const originalOnPress = props. // eslint-disable-next-line @typescript-eslint/ban-types
|
|
97
|
+
onPress;
|
|
98
|
+
|
|
99
|
+
props.onPress = (...args) => {
|
|
100
|
+
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(...args);
|
|
101
|
+
return originalOnPress(...args);
|
|
102
|
+
}; // we store the original onPress prop so we can keep memoization working
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return originalFunction(element, props, ...rest);
|
|
109
|
+
});
|
|
89
110
|
//# sourceMappingURL=DdRumUserInteractionTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","
|
|
1
|
+
{"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","args","patchCreateElementFunction","jsxRuntime","require","originaljsx","jsx","Error","e","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,WAAT,QAA4B,mBAA5B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,qBAAT,QAAsC,gCAAtC;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,4BAAN,CAAmC;AA6BtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,4BAA4B,CAACE,UAAjC,EAA6C;AACzCP,MAAAA,WAAW,CAACQ,GAAZ,CACI,8CADJ,EAEIP,YAAY,CAACQ,IAFjB;AAIA;AACH;;AACDJ,IAAAA,4BAA4B,CAACK,iBAA7B,GAAiD,IAAIR,mBAAJ,EAAjD;AAEA,UAAMS,QAAQ,GAAGZ,KAAK,CAACa,aAAvB;;AACAb,IAAAA,KAAK,CAACa,aAAN,GAAsB,CAClB,GAAGC,IADe,KAEZ;AACN,aAAO,KAAKC,0BAAL,CAAgCH,QAAhC,EAA0CE,IAA1C,CAAP;AACH,KAJD;;AAMA,QAAI;AACA;AAC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EAAYJ,SAAZ,CAF3B;AAGH,OAvBkB,CAAnB;AAwBH,KA5BD;;AA8BAzB,IAAAA,4BAA4B,CAACE,UAA7B,GAA0C,IAA1C;AACAP,IAAAA,WAAW,CAACQ,GAAZ,CACI,sCADJ,EAEIP,YAAY,CAACkC,IAFjB;AAIH;;AA3GqC;;gBAA7B9B,4B,gBACmB,K;;gBADnBA,4B,uBAE6C,IAAIF,qBAAJ,E;;gBAF7CE,4B,gCAImC,CACxC+B,gBADwC,EAExC,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAFwC,KAGC;AACzC,MACID,KAAK,IACL,OAAQA,KAAD,CAAmCX,OAA1C,KAAsD,UAF1D,EAGE;AACE,UAAMa,eAAe,GAAIF,KAAD,EAAmC;AACtDX,IAAAA,OADL;;AAECW,IAAAA,KAAD,CAAmCX,OAAnC,GAA6C,CAAC,GAAGd,IAAJ,KAAoB;AAC7DR,MAAAA,4BAA4B,CAACK,iBAA7B,CAA+C+B,gBAA/C,CACI,GAAG5B,IADP;AAGA,aAAO2B,eAAe,CAAC,GAAG3B,IAAJ,CAAtB;AACH,KALD,CAHF,CASE;;;AACCyB,IAAAA,KAAD,CAGGP,sCAHH,GAG4CS,eAH5C;AAIH;;AACD,SAAOJ,gBAAgB,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,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 React from 'react';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n // We have to use inline require here because older React versions (below 17) don't have jsx-runtime\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n const originaljsx = jsxRuntime.jsx;\n if (!originaljsx) {\n throw new Error(\n 'React version does not support new jsx transform'\n );\n }\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originaljsx, args);\n };\n } catch (e) {\n // TODO: Add telemetry\n }\n\n const originalMemo = React.memo;\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n}\n"]}
|
package/lib/module/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.2';\n"]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export declare class DdRumUserInteractionTracking {
|
|
6
6
|
private static isTracking;
|
|
7
7
|
private static eventsInterceptor;
|
|
8
|
+
private static patchCreateElementFunction;
|
|
8
9
|
/**
|
|
9
10
|
* Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.
|
|
10
11
|
* Please note that we are only considering as valid - for - tracking only the user interactions that have
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
]
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "a989d6b713cb2ec1b0af717d214b0443e2f9e68d"
|
|
77
77
|
}
|
|
@@ -340,3 +340,18 @@ it('M keep memoization working for elements W an onPress prop is passed and cust
|
|
|
340
340
|
// THEN
|
|
341
341
|
expect(rendersCount).toBe(2);
|
|
342
342
|
});
|
|
343
|
+
|
|
344
|
+
describe('startTracking', () => {
|
|
345
|
+
it('does not crash if jsx-runtime is not exported from react', () => {
|
|
346
|
+
expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
|
|
347
|
+
jest.setMock('react/jsx-runtime', null);
|
|
348
|
+
DdRumUserInteractionTracking.startTracking();
|
|
349
|
+
expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
|
|
350
|
+
});
|
|
351
|
+
it('does not crash if jsx-runtime does not contain jsx', () => {
|
|
352
|
+
expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
|
|
353
|
+
jest.setMock('react/jsx-runtime', {});
|
|
354
|
+
DdRumUserInteractionTracking.startTracking();
|
|
355
|
+
expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
@@ -22,6 +22,31 @@ export class DdRumUserInteractionTracking {
|
|
|
22
22
|
private static isTracking = false;
|
|
23
23
|
private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();
|
|
24
24
|
|
|
25
|
+
private static patchCreateElementFunction = (
|
|
26
|
+
originalFunction: typeof React.createElement,
|
|
27
|
+
[element, props, ...rest]: Parameters<typeof React.createElement>
|
|
28
|
+
): ReturnType<typeof React.createElement> => {
|
|
29
|
+
if (
|
|
30
|
+
props &&
|
|
31
|
+
typeof (props as Record<string, unknown>).onPress === 'function'
|
|
32
|
+
) {
|
|
33
|
+
const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types
|
|
34
|
+
.onPress as Function;
|
|
35
|
+
(props as Record<string, unknown>).onPress = (...args: any[]) => {
|
|
36
|
+
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(
|
|
37
|
+
...args
|
|
38
|
+
);
|
|
39
|
+
return originalOnPress(...args);
|
|
40
|
+
};
|
|
41
|
+
// we store the original onPress prop so we can keep memoization working
|
|
42
|
+
(props as Record<
|
|
43
|
+
string,
|
|
44
|
+
unknown
|
|
45
|
+
>).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
|
|
46
|
+
}
|
|
47
|
+
return originalFunction(element, props, ...rest);
|
|
48
|
+
};
|
|
49
|
+
|
|
25
50
|
/**
|
|
26
51
|
* Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.
|
|
27
52
|
* Please note that we are only considering as valid - for - tracking only the user interactions that have
|
|
@@ -37,27 +62,33 @@ export class DdRumUserInteractionTracking {
|
|
|
37
62
|
return;
|
|
38
63
|
}
|
|
39
64
|
DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();
|
|
65
|
+
|
|
40
66
|
const original = React.createElement;
|
|
41
67
|
React.createElement = (
|
|
42
|
-
|
|
43
|
-
props: any,
|
|
44
|
-
...children: any
|
|
68
|
+
...args: Parameters<typeof React.createElement>
|
|
45
69
|
): any => {
|
|
46
|
-
|
|
47
|
-
if (props && typeof props.onPress === 'function') {
|
|
48
|
-
const originalOnPress = props.onPress;
|
|
49
|
-
props.onPress = (...args: any[]) => {
|
|
50
|
-
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(
|
|
51
|
-
...args
|
|
52
|
-
);
|
|
53
|
-
return originalOnPress(...args);
|
|
54
|
-
};
|
|
55
|
-
// we store the original onPress prop so we can keep memoization working
|
|
56
|
-
props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
|
|
57
|
-
}
|
|
58
|
-
return original(element, props, ...children);
|
|
70
|
+
return this.patchCreateElementFunction(original, args);
|
|
59
71
|
};
|
|
60
72
|
|
|
73
|
+
try {
|
|
74
|
+
// We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
75
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
76
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
77
|
+
const originaljsx = jsxRuntime.jsx;
|
|
78
|
+
if (!originaljsx) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'React version does not support new jsx transform'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
jsxRuntime.jsx = (
|
|
84
|
+
...args: Parameters<typeof React.createElement>
|
|
85
|
+
): ReturnType<typeof React.createElement> => {
|
|
86
|
+
return this.patchCreateElementFunction(originaljsx, args);
|
|
87
|
+
};
|
|
88
|
+
} catch (e) {
|
|
89
|
+
// TODO: Add telemetry
|
|
90
|
+
}
|
|
91
|
+
|
|
61
92
|
const originalMemo = React.memo;
|
|
62
93
|
React.memo = (
|
|
63
94
|
component: any,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.1.
|
|
2
|
+
export const version = '1.1.2';
|