react-native-clarity 2.2.1 → 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.
@@ -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 setCustomUserId(customUserId: String, promise: Promise) {
60
- promise.resolve(Clarity.setCustomUserId(customUserId))
61
- }
62
-
63
- @ReactMethod
64
- fun setCustomSessionId(customSessionId: String, promise: Promise) {
65
- promise.resolve(Clarity.setCustomSessionId(customSessionId))
66
- }
67
-
68
- @ReactMethod
69
- fun getCurrentSessionId(promise: Promise) {
70
- promise.resolve(Clarity.getCurrentSessionId())
71
- }
72
-
73
- @ReactMethod
74
- fun setCustomTag(key: String?, value: String?, promise: Promise) {
75
- promise.resolve(Clarity.setCustomTag(key, value))
76
- }
77
-
78
- @ReactMethod
79
- fun setCurrentScreenName(screenName: String?, promise: Promise) {
80
- promise.resolve(Clarity.setCurrentScreenName(screenName))
81
- }
82
-
83
- @ReactMethod
84
- fun getCurrentSessionUrl(promise: Promise) {
85
- promise.resolve(Clarity.getCurrentSessionUrl())
86
- }
87
-
88
-
89
- private fun readableArrayToList(arr: ReadableArray): List<String> {
90
- val ret = mutableListOf<String>()
91
-
92
- for (i in 0 until arr.size()) {
93
- ret.add(arr.getString(i))
94
- }
95
-
96
- return ret
97
- }
98
-
99
- companion object {
100
- const val NAME = "Clarity"
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