react-native-clarity 2.2.1 → 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,35 +1,36 @@
1
- require "json"
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
-
6
- Pod::Spec.new do |s|
7
- s.name = "react-native-clarity"
8
- s.version = package["version"]
9
- s.summary = package["description"]
10
- s.homepage = package["homepage"]
11
- s.license = package["license"]
12
- s.authors = package["author"]
13
-
14
- s.platforms = { :ios => "11.0" }
15
- s.source = { :git => "https://msasg.visualstudio.com/Clarity/_git/clarity-react-native.git", :tag => "#{s.version}" }
16
-
17
- s.source_files = "ios/**/*.{h,m,mm}"
18
-
19
- s.dependency "React-Core"
20
-
21
- # Don't install the dependencies when we run `pod install` in the old architecture.
22
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
23
- s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
24
- s.pod_target_xcconfig = {
25
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
26
- "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
27
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
28
- }
29
- s.dependency "React-Codegen"
30
- s.dependency "RCT-Folly"
31
- s.dependency "RCTRequired"
32
- s.dependency "RCTTypeSafety"
33
- s.dependency "ReactCommon/turbomodule/core"
34
- end
35
- end
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-clarity"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "13.0" }
15
+ s.source = { :git => "https://msasg.visualstudio.com/Clarity/_git/clarity-react-native.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}"
18
+
19
+ s.dependency "React-Core"
20
+ s.dependency "Clarity", '1.0.0'
21
+
22
+ # Don't install the dependencies when we run `pod install` in the old architecture.
23
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
24
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
25
+ s.pod_target_xcconfig = {
26
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
27
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
28
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
29
+ }
30
+ s.dependency "React-Codegen"
31
+ s.dependency "RCT-Folly"
32
+ s.dependency "RCTRequired"
33
+ s.dependency "RCTTypeSafety"
34
+ s.dependency "ReactCommon/turbomodule/core"
35
+ end
36
+ end
package/src/index.tsx CHANGED
@@ -2,13 +2,16 @@ import { NativeModules, Platform } from 'react-native';
2
2
 
3
3
  const LINKING_ERROR =
4
4
  `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
5
- // Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + TODO: add back when iOS is supported.
5
+ Platform.select({
6
+ ios: "- You have run 'pod install --repo-update'\n",
7
+ default: '',
8
+ }) +
6
9
  '- You rebuilt the app after installing the package\n' +
7
10
  '- You are not using Expo Go\n';
8
11
 
9
12
  const Clarity = NativeModules.Clarity;
10
13
 
11
- const SupportedPlatforms = ['android']
14
+ const SupportedPlatforms = ['android'];
12
15
 
13
16
  /**
14
17
  * The configuration that will be used to customize the Clarity behaviour.
@@ -23,8 +26,11 @@ const SupportedPlatforms = ['android']
23
26
  * @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
24
27
  * @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
25
28
  * If it contains "*" as an element, all domains will be captured.
29
+ * Note: iOS currently does not support allowedDomains feature.
26
30
  * @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
27
31
  * @param maximumDailyNetworkUsageInMB [OPTIONAL default = null] Maximum daily network usage for Clarity (null = No limit). When the limit is reached, Clarity will turn on lean mode.
32
+ * Note: iOS currently does not support limiting network usage.
33
+ * @param enableIOS_experimental [OPTIONAL default = false] Experimental flag to enable Clarity on iOS platform.
28
34
  */
29
35
  export interface ClarityConfig {
30
36
  userId?: string | null;
@@ -34,47 +40,69 @@ export interface ClarityConfig {
34
40
  allowedDomains?: string[];
35
41
  disableOnLowEndDevices?: Boolean;
36
42
  maximumDailyNetworkUsageInMB?: number;
43
+ enableIOS_experimental?: boolean;
37
44
  }
38
45
 
39
46
  /**
40
47
  * The level of logging to show in the device logcat stream.
41
48
  */
42
49
  export enum LogLevel {
43
- Verbose = "Verbose",
44
- Debug = "Debug",
45
- Info = "Info",
46
- Warning = "Warning",
47
- Error = "Error",
48
- None = "None"
50
+ Verbose = 'Verbose',
51
+ Debug = 'Debug',
52
+ Info = 'Info',
53
+ Warning = 'Warning',
54
+ Error = 'Error',
55
+ None = 'None',
56
+ }
57
+
58
+ function isClarityUnavailable(): boolean {
59
+ if (!SupportedPlatforms.includes(Platform.OS)) {
60
+ console.warn(
61
+ 'Clarity supports ' + SupportedPlatforms.join(', ') + ' only for now.'
62
+ );
63
+ return true;
64
+ }
65
+
66
+ if (Clarity === null) {
67
+ console.error('Clarity did not initialize properly.', LINKING_ERROR);
68
+ return true;
69
+ }
70
+
71
+ return false;
49
72
  }
50
73
 
51
74
  /**
52
75
  * Initializes the Clarity SDK if the API level is supported.
53
76
  * @param projectId [REQUIRED] The Clarity project id to send data to.
54
77
  * @param config [OPTIONAL] The clarity config, if not provided default values are used.
55
- */
78
+ */
56
79
  export function initialize(projectId: string, config?: ClarityConfig) {
57
-
58
- if (typeof projectId !== "string" || !(typeof config === "object" || typeof config === "undefined")) {
59
- throw Error("Invalid Clarity initialization arguments. Please check the docs for assitance.")
80
+ if (
81
+ typeof projectId !== 'string' ||
82
+ !(typeof config === 'object' || typeof config === 'undefined')
83
+ ) {
84
+ throw Error(
85
+ 'Invalid Clarity initialization arguments. Please check the docs for assitance.'
86
+ );
60
87
  }
61
88
 
62
89
  // applying default values
63
- let { userId = null,
90
+ let {
91
+ userId = null,
64
92
  logLevel = LogLevel.None,
65
93
  allowMeteredNetworkUsage = false,
66
94
  enableWebViewCapture = true,
67
- allowedDomains = ["*"],
95
+ allowedDomains = ['*'],
68
96
  disableOnLowEndDevices = false,
69
- maximumDailyNetworkUsageInMB = null } = config ?? {};
97
+ maximumDailyNetworkUsageInMB = null,
98
+ enableIOS_experimental = false,
99
+ } = config ?? {};
70
100
 
71
- if (!SupportedPlatforms.includes(Platform.OS)) {
72
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
73
- return;
101
+ if (enableIOS_experimental === true && !SupportedPlatforms.includes('ios')) {
102
+ SupportedPlatforms.push('ios');
74
103
  }
75
104
 
76
- if (Clarity === null) {
77
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
105
+ if (isClarityUnavailable()) {
78
106
  return;
79
107
  }
80
108
 
@@ -95,6 +123,40 @@ export function initialize(projectId: string, config?: ClarityConfig) {
95
123
  );
96
124
  }
97
125
 
126
+ /**
127
+ * Pauses the Clarity capturing processes until the next resume() is called.
128
+ */
129
+ export function pause(): Promise<boolean | undefined> {
130
+ if (isClarityUnavailable()) {
131
+ return Promise.resolve(undefined);
132
+ }
133
+
134
+ return Clarity.pause();
135
+ }
136
+
137
+ /**
138
+ * Resumes the Clarity capturing processes if they are not already resumed.
139
+ * Note: Clarity starts capturing data right on initialization.
140
+ */
141
+ export function resume(): Promise<boolean | undefined> {
142
+ if (isClarityUnavailable()) {
143
+ return Promise.resolve(undefined);
144
+ }
145
+
146
+ return Clarity.resume();
147
+ }
148
+
149
+ /**
150
+ * Returns true if Clarity has been paused by the user.
151
+ */
152
+ export function isPaused(): Promise<Boolean | undefined> {
153
+ if (isClarityUnavailable()) {
154
+ return Promise.resolve(undefined);
155
+ }
156
+
157
+ return Clarity.isPaused();
158
+ }
159
+
98
160
  /**
99
161
  * Sets a custom user id that can be used to identify the user. It has less
100
162
  * restrictions than the userId parameter. You can pass any string and
@@ -105,18 +167,12 @@ export function initialize(projectId: string, config?: ClarityConfig) {
105
167
  * </p>
106
168
  * @param customUserId The custom user id to set.
107
169
  */
108
- export function setCustomUserId(customUserId: string) {
109
- if (!SupportedPlatforms.includes(Platform.OS)) {
110
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
111
- return;
112
- }
113
-
114
- if (Clarity === null) {
115
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
116
- return;
170
+ export function setCustomUserId(customUserId: string): Promise<boolean | undefined> {
171
+ if (isClarityUnavailable()) {
172
+ return Promise.resolve(undefined);
117
173
  }
118
174
 
119
- Clarity.setCustomUserId(customUserId);
175
+ return Clarity.setCustomUserId(customUserId);
120
176
  }
121
177
 
122
178
  /**
@@ -126,18 +182,12 @@ export function setCustomUserId(customUserId: string) {
126
182
  * </p>
127
183
  * @param customSessionId The custom session id to set.
128
184
  */
129
- export function setCustomSessionId(customSessionId: string) {
130
- if (!SupportedPlatforms.includes(Platform.OS)) {
131
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
132
- return;
133
- }
134
-
135
- if (Clarity === null) {
136
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
137
- return;
185
+ export function setCustomSessionId(customSessionId: string): Promise<boolean | undefined> {
186
+ if (isClarityUnavailable()) {
187
+ return Promise.resolve(undefined);
138
188
  }
139
189
 
140
- Clarity.setCustomSessionId(customSessionId);
190
+ return Clarity.setCustomSessionId(customSessionId);
141
191
  }
142
192
 
143
193
  /**
@@ -145,18 +195,12 @@ export function setCustomSessionId(customSessionId: string) {
145
195
  * @param key The tag key to set.
146
196
  * @param value The tag value to set.
147
197
  */
148
- export function setCustomTag(key: string, value: string) {
149
- if (!SupportedPlatforms.includes(Platform.OS)) {
150
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
151
- return;
198
+ export function setCustomTag(key: string, value: string): Promise<boolean | undefined> {
199
+ if (isClarityUnavailable()) {
200
+ return Promise.resolve(undefined);
152
201
  }
153
202
 
154
- if (Clarity === null) {
155
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
156
- return;
157
- }
158
-
159
- Clarity.setCustomTag(key, value);
203
+ return Clarity.setCustomTag(key, value);
160
204
  }
161
205
 
162
206
  /**
@@ -166,18 +210,14 @@ export function setCustomTag(key: string, value: string) {
166
210
  * You can it set to `null` to remove the latest set value.
167
211
  * @param screenName The current screen name to set.
168
212
  */
169
- export function setCurrentScreenName(screenName: string | null) {
170
- if (!SupportedPlatforms.includes(Platform.OS)) {
171
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
172
- return;
173
- }
174
-
175
- if (Clarity === null) {
176
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
177
- return;
213
+ export function setCurrentScreenName(
214
+ screenName: string | null
215
+ ): Promise<boolean | undefined> {
216
+ if (isClarityUnavailable()) {
217
+ return Promise.resolve(undefined);
178
218
  }
179
219
 
180
- Clarity.setCurrentScreenName(screenName);
220
+ return Clarity.setCurrentScreenName(screenName);
181
221
  }
182
222
 
183
223
  /**
@@ -186,14 +226,8 @@ export function setCurrentScreenName(screenName: string | null) {
186
226
  * @returns a promise that resolves to the current session id.
187
227
  */
188
228
  export function getCurrentSessionId(): Promise<string> {
189
- if (!SupportedPlatforms.includes(Platform.OS)) {
190
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
191
- return Promise.resolve("Undefined");
192
- }
193
-
194
- if (Clarity === null) {
195
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
196
- return Promise.resolve("Undefined");
229
+ if (isClarityUnavailable()) {
230
+ return Promise.resolve('Undefined');
197
231
  }
198
232
 
199
233
  return Clarity.getCurrentSessionId();
@@ -206,14 +240,8 @@ export function getCurrentSessionId(): Promise<string> {
206
240
  * @returns a promise that resolves to the current session url if there is an active one.
207
241
  */
208
242
  export function getCurrentSessionUrl(): Promise<string> {
209
- if (!SupportedPlatforms.includes(Platform.OS)) {
210
- console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
211
- return Promise.resolve("Undefined");
212
- }
213
-
214
- if (Clarity === null) {
215
- console.error("Clarity did not initialize properly.", LINKING_ERROR);
216
- return Promise.resolve("Undefined");
243
+ if (isClarityUnavailable()) {
244
+ return Promise.resolve('Undefined');
217
245
  }
218
246
 
219
247
  return Clarity.getCurrentSessionUrl();
package/ios/Clarity.mm DELETED
@@ -1,15 +0,0 @@
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,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- </Workspace>