react-native-clarity 2.3.0 → 3.0.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,122 +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 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
- }
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.m ADDED
@@ -0,0 +1,131 @@
1
+ #import "Clarity.h"
2
+ #import <React/RCTLog.h>
3
+
4
+ @import Clarity;
5
+
6
+ @implementation Clarity
7
+ RCT_EXPORT_MODULE()
8
+
9
+ RCT_EXPORT_METHOD(initialize:(NSString *)projectId
10
+ userId:(NSString *)userId
11
+ logLevel:(NSString *)logLevel
12
+ allowMeteredNetworkUsage:(BOOL)allowMeteredNetworkUsage
13
+ enableWebViewCapture:(BOOL)enableWebViewCapture
14
+ allowedDomains:(NSArray *)allowedDomains
15
+ disableOnLowEndDevices:(BOOL)disableOnLowEndDevices
16
+ enableDailyNetworkUsageLimit:(BOOL)enableDailyNetworkUsageLimit
17
+ maximumDailyNetworkUsageInMB:(double)maximumDailyNetworkUsageInMB
18
+ resolver:(RCTPromiseResolveBlock)resolve
19
+ rejecter:(RCTPromiseRejectBlock)reject)
20
+ {
21
+ dispatch_async(dispatch_get_main_queue(), ^{
22
+ ClarityConfig* config = [[ClarityConfig alloc]
23
+ initWithProjectId:projectId
24
+ userId:userId
25
+ logLevel:[self convertLogLevelToEnum:logLevel]
26
+ allowMeteredNetworkUsage:allowMeteredNetworkUsage
27
+ enableWebViewCapture:enableWebViewCapture
28
+ disableOnLowEndDevices:disableOnLowEndDevices
29
+ applicationFramework:ApplicationFrameworkReactNative];
30
+
31
+ [ClaritySDK initializeWithConfig:config];
32
+ });
33
+
34
+ resolve(@(true));
35
+ }
36
+
37
+ RCT_EXPORT_METHOD(pause:(RCTPromiseResolveBlock)resolve
38
+ rejecter:(RCTPromiseRejectBlock)reject)
39
+ {
40
+ [ClaritySDK pause];
41
+ resolve(@([ClaritySDK isPaused]));
42
+ }
43
+
44
+ RCT_EXPORT_METHOD(resume:(RCTPromiseResolveBlock)resolve
45
+ rejecter:(RCTPromiseRejectBlock)reject)
46
+ {
47
+ [ClaritySDK resume];
48
+ resolve(@((BOOL)(![ClaritySDK isPaused])));
49
+ }
50
+
51
+ RCT_EXPORT_METHOD(isPaused:(RCTPromiseResolveBlock)resolve
52
+ rejecter:(RCTPromiseRejectBlock)reject)
53
+ {
54
+ resolve(@([ClaritySDK isPaused]));
55
+ }
56
+
57
+ RCT_EXPORT_METHOD(setCustomUserId:(NSString *)customUserId
58
+ resolver:(RCTPromiseResolveBlock)resolve
59
+ rejecter:(RCTPromiseRejectBlock)reject)
60
+ {
61
+ resolve(@([ClaritySDK setCustomUserId:customUserId]));
62
+ }
63
+
64
+ RCT_EXPORT_METHOD(setCustomSessionId:(NSString *)customSessionId
65
+ resolver:(RCTPromiseResolveBlock)resolve
66
+ rejecter:(RCTPromiseRejectBlock)reject)
67
+ {
68
+ resolve(@([ClaritySDK setCustomSessionId:customSessionId]));
69
+ }
70
+
71
+ RCT_EXPORT_METHOD(getCurrentSessionId:(RCTPromiseResolveBlock)resolve
72
+ rejecter:(RCTPromiseRejectBlock)reject)
73
+ {
74
+ resolve([ClaritySDK getCurrentSessionId]);
75
+ }
76
+
77
+ RCT_EXPORT_METHOD(setCustomTag:(NSString *)key value:(NSString *)value
78
+ resolver:(RCTPromiseResolveBlock)resolve
79
+ rejecter:(RCTPromiseRejectBlock)reject)
80
+ {
81
+ resolve(@([ClaritySDK setCustomTagWithKey:key value:value]));
82
+ }
83
+
84
+ RCT_EXPORT_METHOD(setCurrentScreenName:(NSString *)currentScreenName
85
+ resolver:(RCTPromiseResolveBlock)resolve
86
+ rejecter:(RCTPromiseRejectBlock)reject)
87
+ {
88
+ resolve(@([ClaritySDK setCurrentScreenNameWithName:currentScreenName]));
89
+ }
90
+
91
+ RCT_EXPORT_METHOD(getCurrentSessionUrl:(RCTPromiseResolveBlock)resolve
92
+ rejecter:(RCTPromiseRejectBlock)reject)
93
+ {
94
+ resolve([ClaritySDK getCurrentSessionUrl]);
95
+ }
96
+
97
+ - (LogLevel)convertLogLevelToEnum:(NSString*)logLevel
98
+ {
99
+ if ([logLevel isEqual:@"Verbose"]) {
100
+ return LogLevelVerbose;
101
+ }
102
+
103
+ if ([logLevel isEqual:@"Debug"]) {
104
+ return LogLevelDebug;
105
+ }
106
+
107
+ if ([logLevel isEqual:@"Info"]) {
108
+ return LogLevelInfo;
109
+ }
110
+
111
+ if ([logLevel isEqual:@"Warning"]) {
112
+ return LogLevelWarning;
113
+ }
114
+
115
+ if ([logLevel isEqual:@"Error"]) {
116
+ return LogLevelError;
117
+ }
118
+
119
+ return LogLevelNone;
120
+ }
121
+
122
+ // Don't compile this code when we build for the old architecture.
123
+ #ifdef RCT_NEW_ARCH_ENABLED
124
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
125
+ (const facebook::react::ObjCTurboModule::InitParams &)params
126
+ {
127
+ return std::make_shared<facebook::react::NativeClaritySpecJSI>(params);
128
+ }
129
+ #endif
130
+
131
+ @end
@@ -7,7 +7,7 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
- 5E555C0D2413F4C50049A1A2 /* Clarity.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* Clarity.m */; };
10
+ 6F8543912B793D4F00B05BAC /* Clarity.m in Sources */ = {isa = PBXBuildFile; fileRef = 6F8543902B793D4F00B05BAC /* Clarity.m */; };
11
11
  /* End PBXBuildFile section */
12
12
 
13
13
  /* Begin PBXCopyFilesBuildPhase section */
@@ -24,8 +24,8 @@
24
24
 
25
25
  /* Begin PBXFileReference section */
26
26
  134814201AA4EA6300B7C361 /* libClarity.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libClarity.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
- B3E7B5881CC2AC0600A0062D /* Clarity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clarity.h; sourceTree = "<group>"; };
28
- B3E7B5891CC2AC0600A0062D /* Clarity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Clarity.m; sourceTree = "<group>"; };
27
+ 6F85438F2B793D4F00B05BAC /* Clarity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clarity.h; sourceTree = "<group>"; };
28
+ 6F8543902B793D4F00B05BAC /* Clarity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Clarity.m; sourceTree = "<group>"; };
29
29
  /* End PBXFileReference section */
30
30
 
31
31
  /* Begin PBXFrameworksBuildPhase section */
@@ -50,8 +50,8 @@
50
50
  58B511D21A9E6C8500147676 = {
51
51
  isa = PBXGroup;
52
52
  children = (
53
- B3E7B5881CC2AC0600A0062D /* Clarity.h */,
54
- B3E7B5891CC2AC0600A0062D /* Clarity.m */,
53
+ 6F85438F2B793D4F00B05BAC /* Clarity.h */,
54
+ 6F8543902B793D4F00B05BAC /* Clarity.m */,
55
55
  134814211AA4EA7D00B7C361 /* Products */,
56
56
  );
57
57
  sourceTree = "<group>";
@@ -87,6 +87,7 @@
87
87
  TargetAttributes = {
88
88
  58B511DA1A9E6C8500147676 = {
89
89
  CreatedOnToolsVersion = 6.1.1;
90
+ LastSwiftMigration = 1520;
90
91
  };
91
92
  };
92
93
  };
@@ -113,7 +114,7 @@
113
114
  isa = PBXSourcesBuildPhase;
114
115
  buildActionMask = 2147483647;
115
116
  files = (
116
- B3E7B58A1CC2AC0600A0062D /* Clarity.m in Sources */,
117
+ 6F8543912B793D4F00B05BAC /* Clarity.m in Sources */,
117
118
  );
118
119
  runOnlyForDeploymentPostprocessing = 0;
119
120
  };
@@ -164,7 +165,6 @@
164
165
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
165
166
  GCC_WARN_UNUSED_FUNCTION = YES;
166
167
  GCC_WARN_UNUSED_VARIABLE = YES;
167
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
168
168
  MTL_ENABLE_DEBUG_INFO = YES;
169
169
  ONLY_ACTIVE_ARCH = YES;
170
170
  SDKROOT = iphoneos;
@@ -208,7 +208,6 @@
208
208
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
209
209
  GCC_WARN_UNUSED_FUNCTION = YES;
210
210
  GCC_WARN_UNUSED_VARIABLE = YES;
211
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
212
211
  MTL_ENABLE_DEBUG_INFO = NO;
213
212
  SDKROOT = iphoneos;
214
213
  VALIDATE_PRODUCT = YES;
@@ -218,6 +217,7 @@
218
217
  58B511F01A9E6C8500147676 /* Debug */ = {
219
218
  isa = XCBuildConfiguration;
220
219
  buildSettings = {
220
+ CLANG_ENABLE_MODULES = YES;
221
221
  HEADER_SEARCH_PATHS = (
222
222
  "$(inherited)",
223
223
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
@@ -228,12 +228,16 @@
228
228
  OTHER_LDFLAGS = "-ObjC";
229
229
  PRODUCT_NAME = Clarity;
230
230
  SKIP_INSTALL = YES;
231
+ SWIFT_OBJC_BRIDGING_HEADER = "Clarity-Bridging-Header.h";
232
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
233
+ SWIFT_VERSION = 5.0;
231
234
  };
232
235
  name = Debug;
233
236
  };
234
237
  58B511F11A9E6C8500147676 /* Release */ = {
235
238
  isa = XCBuildConfiguration;
236
239
  buildSettings = {
240
+ CLANG_ENABLE_MODULES = YES;
237
241
  HEADER_SEARCH_PATHS = (
238
242
  "$(inherited)",
239
243
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
@@ -244,6 +248,8 @@
244
248
  OTHER_LDFLAGS = "-ObjC";
245
249
  PRODUCT_NAME = Clarity;
246
250
  SKIP_INSTALL = YES;
251
+ SWIFT_OBJC_BRIDGING_HEADER = "Clarity-Bridging-Header.h";
252
+ SWIFT_VERSION = 5.0;
247
253
  };
248
254
  name = Release;
249
255
  };