react-native-clarity 2.2.0 → 2.3.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.
- package/LICENSE +20 -20
- package/README.md +121 -112
- package/android/build.gradle +81 -81
- package/android/gradle.properties +7 -8
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityModule.kt +122 -102
- package/ios/Clarity.h +12 -12
- package/ios/Clarity.mm +15 -15
- package/ios/Clarity.xcodeproj/project.pbxproj +274 -274
- package/lib/commonjs/index.js +104 -55
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +101 -55
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +13 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +159 -159
- package/react-native-clarity.podspec +35 -35
- package/src/index.tsx +272 -220
- package/ios/Clarity.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
|
@@ -1,102 +1,122 @@
|
|
|
1
|
-
package com.microsoft.clarity.reactnative
|
|
2
|
-
|
|
3
|
-
import android.os.Handler
|
|
4
|
-
import android.os.Looper
|
|
5
|
-
import com.facebook.react.bridge.*
|
|
6
|
-
import com.microsoft.clarity.Clarity
|
|
7
|
-
import com.microsoft.clarity.ClarityConfig
|
|
8
|
-
import com.microsoft.clarity.models.ApplicationFramework
|
|
9
|
-
import com.microsoft.clarity.models.LogLevel
|
|
10
|
-
|
|
11
|
-
class ClarityModule(reactContext: ReactApplicationContext) :
|
|
12
|
-
ReactContextBaseJavaModule(reactContext) {
|
|
13
|
-
|
|
14
|
-
override fun getName(): String {
|
|
15
|
-
return NAME
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@ReactMethod
|
|
19
|
-
fun initialize(
|
|
20
|
-
projectId: String,
|
|
21
|
-
userId: String?,
|
|
22
|
-
logLevel: String,
|
|
23
|
-
allowMeteredNetworkUsage: Boolean,
|
|
24
|
-
enableWebViewCapture: Boolean,
|
|
25
|
-
allowedDomains: ReadableArray,
|
|
26
|
-
disableOnLowEndDevices: Boolean,
|
|
27
|
-
enableDailyNetworkUsageLimit: Boolean,
|
|
28
|
-
maximumDailyNetworkUsageInMB: Double,
|
|
29
|
-
promise: Promise
|
|
30
|
-
) {
|
|
31
|
-
val allowedActivities = listOf<String>(); // not supported
|
|
32
|
-
val disallowedActivities = listOf<String>(); // not supported
|
|
33
|
-
|
|
34
|
-
// We use two parameters because the react method parameters do not accept nullable primitive types.
|
|
35
|
-
// Moreover, the Long data type is not supported. Js numbers are translated into doubles.
|
|
36
|
-
val maximumDailyNetworkUsageInMBLong = if (enableDailyNetworkUsageLimit) maximumDailyNetworkUsageInMB.toLong() else null
|
|
37
|
-
|
|
38
|
-
val config = ClarityConfig(
|
|
39
|
-
projectId,
|
|
40
|
-
userId,
|
|
41
|
-
LogLevel.valueOf(logLevel),
|
|
42
|
-
allowMeteredNetworkUsage,
|
|
43
|
-
enableWebViewCapture,
|
|
44
|
-
readableArrayToList(allowedDomains),
|
|
45
|
-
ApplicationFramework.ReactNative,
|
|
46
|
-
allowedActivities,
|
|
47
|
-
disallowedActivities,
|
|
48
|
-
disableOnLowEndDevices,
|
|
49
|
-
maximumDailyNetworkUsageInMBLong
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
// Run on the main thread as recommended by the native Clarity SDK.
|
|
53
|
-
Handler(Looper.getMainLooper()).post {
|
|
54
|
-
promise.resolve(Clarity.initialize(currentActivity, config))
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@ReactMethod
|
|
59
|
-
fun
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
@ReactMethod
|
|
79
|
-
fun
|
|
80
|
-
promise.resolve(Clarity.
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@ReactMethod
|
|
84
|
-
fun
|
|
85
|
-
promise.resolve(Clarity.
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
1
|
+
package com.microsoft.clarity.reactnative
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import com.facebook.react.bridge.*
|
|
6
|
+
import com.microsoft.clarity.Clarity
|
|
7
|
+
import com.microsoft.clarity.ClarityConfig
|
|
8
|
+
import com.microsoft.clarity.models.ApplicationFramework
|
|
9
|
+
import com.microsoft.clarity.models.LogLevel
|
|
10
|
+
|
|
11
|
+
class ClarityModule(reactContext: ReactApplicationContext) :
|
|
12
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
13
|
+
|
|
14
|
+
override fun getName(): String {
|
|
15
|
+
return NAME
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@ReactMethod
|
|
19
|
+
fun initialize(
|
|
20
|
+
projectId: String,
|
|
21
|
+
userId: String?,
|
|
22
|
+
logLevel: String,
|
|
23
|
+
allowMeteredNetworkUsage: Boolean,
|
|
24
|
+
enableWebViewCapture: Boolean,
|
|
25
|
+
allowedDomains: ReadableArray,
|
|
26
|
+
disableOnLowEndDevices: Boolean,
|
|
27
|
+
enableDailyNetworkUsageLimit: Boolean,
|
|
28
|
+
maximumDailyNetworkUsageInMB: Double,
|
|
29
|
+
promise: Promise
|
|
30
|
+
) {
|
|
31
|
+
val allowedActivities = listOf<String>(); // not supported
|
|
32
|
+
val disallowedActivities = listOf<String>(); // not supported
|
|
33
|
+
|
|
34
|
+
// We use two parameters because the react method parameters do not accept nullable primitive types.
|
|
35
|
+
// Moreover, the Long data type is not supported. Js numbers are translated into doubles.
|
|
36
|
+
val maximumDailyNetworkUsageInMBLong = if (enableDailyNetworkUsageLimit) maximumDailyNetworkUsageInMB.toLong() else null
|
|
37
|
+
|
|
38
|
+
val config = ClarityConfig(
|
|
39
|
+
projectId,
|
|
40
|
+
userId,
|
|
41
|
+
LogLevel.valueOf(logLevel),
|
|
42
|
+
allowMeteredNetworkUsage,
|
|
43
|
+
enableWebViewCapture,
|
|
44
|
+
readableArrayToList(allowedDomains),
|
|
45
|
+
ApplicationFramework.ReactNative,
|
|
46
|
+
allowedActivities,
|
|
47
|
+
disallowedActivities,
|
|
48
|
+
disableOnLowEndDevices,
|
|
49
|
+
maximumDailyNetworkUsageInMBLong
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// Run on the main thread as recommended by the native Clarity SDK.
|
|
53
|
+
Handler(Looper.getMainLooper()).post {
|
|
54
|
+
promise.resolve(Clarity.initialize(currentActivity, config))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ReactMethod
|
|
59
|
+
fun pause(promise: Promise) {
|
|
60
|
+
// Cannot resolve void
|
|
61
|
+
Clarity.pause()
|
|
62
|
+
promise.resolve(Clarity.isPaused())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@ReactMethod
|
|
66
|
+
fun resume(promise: Promise) {
|
|
67
|
+
// Cannot resolve void
|
|
68
|
+
Clarity.resume()
|
|
69
|
+
promise.resolve(!Clarity.isPaused())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@ReactMethod
|
|
73
|
+
fun isPaused(promise: Promise) {
|
|
74
|
+
promise.resolve(Clarity.isPaused())
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
fun setCustomUserId(customUserId: String, promise: Promise) {
|
|
80
|
+
promise.resolve(Clarity.setCustomUserId(customUserId))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@ReactMethod
|
|
84
|
+
fun setCustomSessionId(customSessionId: String, promise: Promise) {
|
|
85
|
+
promise.resolve(Clarity.setCustomSessionId(customSessionId))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
fun getCurrentSessionId(promise: Promise) {
|
|
90
|
+
promise.resolve(Clarity.getCurrentSessionId())
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@ReactMethod
|
|
94
|
+
fun setCustomTag(key: String?, value: String?, promise: Promise) {
|
|
95
|
+
promise.resolve(Clarity.setCustomTag(key, value))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@ReactMethod
|
|
99
|
+
fun setCurrentScreenName(screenName: String?, promise: Promise) {
|
|
100
|
+
promise.resolve(Clarity.setCurrentScreenName(screenName))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactMethod
|
|
104
|
+
fun getCurrentSessionUrl(promise: Promise) {
|
|
105
|
+
promise.resolve(Clarity.getCurrentSessionUrl())
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
private fun readableArrayToList(arr: ReadableArray): List<String> {
|
|
110
|
+
val ret = mutableListOf<String>()
|
|
111
|
+
|
|
112
|
+
for (i in 0 until arr.size()) {
|
|
113
|
+
ret.add(arr.getString(i))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return ret
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
companion object {
|
|
120
|
+
const val NAME = "Clarity"
|
|
121
|
+
}
|
|
122
|
+
}
|
package/ios/Clarity.h
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
3
|
-
#import "RNClaritySpec.h"
|
|
4
|
-
|
|
5
|
-
@interface Clarity : NSObject <NativeClaritySpec>
|
|
6
|
-
#else
|
|
7
|
-
#import <React/RCTBridgeModule.h>
|
|
8
|
-
|
|
9
|
-
@interface Clarity : NSObject <RCTBridgeModule>
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
@end
|
|
1
|
+
|
|
2
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
3
|
+
#import "RNClaritySpec.h"
|
|
4
|
+
|
|
5
|
+
@interface Clarity : NSObject <NativeClaritySpec>
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTBridgeModule.h>
|
|
8
|
+
|
|
9
|
+
@interface Clarity : NSObject <RCTBridgeModule>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
@end
|
package/ios/Clarity.mm
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#import "Clarity.h"
|
|
2
|
-
|
|
3
|
-
@implementation Clarity
|
|
4
|
-
RCT_EXPORT_MODULE()
|
|
5
|
-
|
|
6
|
-
// Don't compile this code when we build for the old architecture.
|
|
7
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
8
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
9
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
10
|
-
{
|
|
11
|
-
return std::make_shared<facebook::react::NativeClaritySpecJSI>(params);
|
|
12
|
-
}
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
@end
|
|
1
|
+
#import "Clarity.h"
|
|
2
|
+
|
|
3
|
+
@implementation Clarity
|
|
4
|
+
RCT_EXPORT_MODULE()
|
|
5
|
+
|
|
6
|
+
// Don't compile this code when we build for the old architecture.
|
|
7
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
8
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
9
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
10
|
+
{
|
|
11
|
+
return std::make_shared<facebook::react::NativeClaritySpecJSI>(params);
|
|
12
|
+
}
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
@end
|