react-native-clarity 3.0.0 → 3.0.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/LICENSE +20 -20
- package/README.md +127 -127
- package/android/build.gradle +81 -81
- package/android/gradle.properties +7 -7
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityModule.kt +122 -122
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityPackage.kt +17 -17
- package/ios/Clarity.h +12 -12
- package/ios/Clarity.m +131 -131
- package/ios/Clarity.xcodeproj/project.pbxproj +280 -280
- package/lib/commonjs/index.js +74 -66
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +74 -66
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +105 -105
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +165 -165
- package/react-native-clarity.podspec +36 -36
- package/src/index.tsx +257 -248
package/src/index.tsx
CHANGED
|
@@ -1,248 +1,257 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native';
|
|
2
|
-
|
|
3
|
-
const LINKING_ERROR =
|
|
4
|
-
`The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({
|
|
6
|
-
ios: "- You have run 'pod install --repo-update'\n",
|
|
7
|
-
default: '',
|
|
8
|
-
}) +
|
|
9
|
-
'- You rebuilt the app after installing the package\n' +
|
|
10
|
-
'- You are not using Expo Go\n';
|
|
11
|
-
|
|
12
|
-
const Clarity = NativeModules.Clarity;
|
|
13
|
-
|
|
14
|
-
const SupportedPlatforms = ['android'];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({
|
|
6
|
+
ios: "- You have run 'pod install --repo-update'\n",
|
|
7
|
+
default: '',
|
|
8
|
+
}) +
|
|
9
|
+
'- You rebuilt the app after installing the package\n' +
|
|
10
|
+
'- You are not using Expo Go\n';
|
|
11
|
+
|
|
12
|
+
const Clarity = NativeModules.Clarity;
|
|
13
|
+
|
|
14
|
+
const SupportedPlatforms = ['android'];
|
|
15
|
+
|
|
16
|
+
let SupportWarningWasShown = false;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
20
|
+
*
|
|
21
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
22
|
+
* will be auto generated. The user id in general is sticky across sessions.
|
|
23
|
+
* The provided user id must follow these conditions:
|
|
24
|
+
* 1. Cannot be an empty string.
|
|
25
|
+
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
26
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
27
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
28
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
29
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
30
|
+
* If it contains "*" as an element, all domains will be captured.
|
|
31
|
+
* Note: iOS currently does not support allowedDomains feature.
|
|
32
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
33
|
+
* @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.
|
|
34
|
+
* Note: iOS currently does not support limiting network usage.
|
|
35
|
+
* @param enableIOS_experimental [OPTIONAL default = false] Experimental flag to enable Clarity on iOS platform.
|
|
36
|
+
*/
|
|
37
|
+
export interface ClarityConfig {
|
|
38
|
+
userId?: string | null;
|
|
39
|
+
logLevel?: LogLevel;
|
|
40
|
+
allowMeteredNetworkUsage?: boolean;
|
|
41
|
+
enableWebViewCapture?: boolean;
|
|
42
|
+
allowedDomains?: string[];
|
|
43
|
+
disableOnLowEndDevices?: Boolean;
|
|
44
|
+
maximumDailyNetworkUsageInMB?: number;
|
|
45
|
+
enableIOS_experimental?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The level of logging to show in the device logcat stream.
|
|
50
|
+
*/
|
|
51
|
+
export enum LogLevel {
|
|
52
|
+
Verbose = 'Verbose',
|
|
53
|
+
Debug = 'Debug',
|
|
54
|
+
Info = 'Info',
|
|
55
|
+
Warning = 'Warning',
|
|
56
|
+
Error = 'Error',
|
|
57
|
+
None = 'None',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isClarityUnavailable(): boolean {
|
|
61
|
+
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
62
|
+
let warningMessage = 'Clarity supports ' + SupportedPlatforms.join(', ') + ' only for now.';
|
|
63
|
+
if (Platform.OS === 'ios') {
|
|
64
|
+
warningMessage = `${warningMessage} To enable experimental iOS support, set the 'enableIOS_experimental' config value to true.`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!SupportWarningWasShown) {
|
|
68
|
+
console.warn(warningMessage);
|
|
69
|
+
SupportWarningWasShown = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Clarity === null) {
|
|
76
|
+
console.error('Clarity did not initialize properly.', LINKING_ERROR);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
85
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
86
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
87
|
+
*/
|
|
88
|
+
export function initialize(projectId: string, config?: ClarityConfig) {
|
|
89
|
+
if (
|
|
90
|
+
typeof projectId !== 'string' ||
|
|
91
|
+
!(typeof config === 'object' || typeof config === 'undefined')
|
|
92
|
+
) {
|
|
93
|
+
throw Error(
|
|
94
|
+
'Invalid Clarity initialization arguments. Please check the docs for assitance.'
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// applying default values
|
|
99
|
+
let {
|
|
100
|
+
userId = null,
|
|
101
|
+
logLevel = LogLevel.None,
|
|
102
|
+
allowMeteredNetworkUsage = false,
|
|
103
|
+
enableWebViewCapture = true,
|
|
104
|
+
allowedDomains = ['*'],
|
|
105
|
+
disableOnLowEndDevices = false,
|
|
106
|
+
maximumDailyNetworkUsageInMB = null,
|
|
107
|
+
enableIOS_experimental = false,
|
|
108
|
+
} = config ?? {};
|
|
109
|
+
|
|
110
|
+
if (enableIOS_experimental === true && !SupportedPlatforms.includes('ios')) {
|
|
111
|
+
SupportedPlatforms.push('ios');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (isClarityUnavailable()) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// We use two parameters because the react method parameters do not accept nullable primitive types.
|
|
119
|
+
let enableDailyNetworkUsageLimit = maximumDailyNetworkUsageInMB != null;
|
|
120
|
+
let refinedMaximumDailyNetworkUsageInMB = maximumDailyNetworkUsageInMB ?? 0;
|
|
121
|
+
|
|
122
|
+
Clarity.initialize(
|
|
123
|
+
projectId,
|
|
124
|
+
userId,
|
|
125
|
+
logLevel,
|
|
126
|
+
allowMeteredNetworkUsage,
|
|
127
|
+
enableWebViewCapture,
|
|
128
|
+
allowedDomains,
|
|
129
|
+
disableOnLowEndDevices,
|
|
130
|
+
enableDailyNetworkUsageLimit,
|
|
131
|
+
refinedMaximumDailyNetworkUsageInMB
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Pauses the Clarity capturing processes until the next resume() is called.
|
|
137
|
+
*/
|
|
138
|
+
export function pause(): Promise<boolean | undefined> {
|
|
139
|
+
if (isClarityUnavailable()) {
|
|
140
|
+
return Promise.resolve(undefined);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return Clarity.pause();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Resumes the Clarity capturing processes if they are not already resumed.
|
|
148
|
+
* Note: Clarity starts capturing data right on initialization.
|
|
149
|
+
*/
|
|
150
|
+
export function resume(): Promise<boolean | undefined> {
|
|
151
|
+
if (isClarityUnavailable()) {
|
|
152
|
+
return Promise.resolve(undefined);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return Clarity.resume();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns true if Clarity has been paused by the user.
|
|
160
|
+
*/
|
|
161
|
+
export function isPaused(): Promise<Boolean | undefined> {
|
|
162
|
+
if (isClarityUnavailable()) {
|
|
163
|
+
return Promise.resolve(undefined);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return Clarity.isPaused();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Sets a custom user id that can be used to identify the user. It has less
|
|
171
|
+
* restrictions than the userId parameter. You can pass any string and
|
|
172
|
+
* you can filter on it on the dashboard side. If you need the most efficient
|
|
173
|
+
* filtering on the dashboard, use the userId parameter if possible.
|
|
174
|
+
* <p>
|
|
175
|
+
* Note: custom user id cannot be null or empty, or consists only of whitespaces.
|
|
176
|
+
* </p>
|
|
177
|
+
* @param customUserId The custom user id to set.
|
|
178
|
+
*/
|
|
179
|
+
export function setCustomUserId(customUserId: string): Promise<boolean | undefined> {
|
|
180
|
+
if (isClarityUnavailable()) {
|
|
181
|
+
return Promise.resolve(undefined);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return Clarity.setCustomUserId(customUserId);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Sets a custom session id that can be used to identify the session.
|
|
189
|
+
* <p>
|
|
190
|
+
* Note: custom session id cannot be null or empty, or consists only of whitespaces.
|
|
191
|
+
* </p>
|
|
192
|
+
* @param customSessionId The custom session id to set.
|
|
193
|
+
*/
|
|
194
|
+
export function setCustomSessionId(customSessionId: string): Promise<boolean | undefined> {
|
|
195
|
+
if (isClarityUnavailable()) {
|
|
196
|
+
return Promise.resolve(undefined);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return Clarity.setCustomSessionId(customSessionId);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Sets a custom tag for the current session.
|
|
204
|
+
* @param key The tag key to set.
|
|
205
|
+
* @param value The tag value to set.
|
|
206
|
+
*/
|
|
207
|
+
export function setCustomTag(key: string, value: string): Promise<boolean | undefined> {
|
|
208
|
+
if (isClarityUnavailable()) {
|
|
209
|
+
return Promise.resolve(undefined);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return Clarity.setCustomTag(key, value);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* For React Native applications only, this function is used to set the current screen name
|
|
217
|
+
* in case the ReactNative Navigation package is used.
|
|
218
|
+
* This will allow you to split and analyze your data on the screen names.
|
|
219
|
+
* You can it set to `null` to remove the latest set value.
|
|
220
|
+
* @param screenName The current screen name to set.
|
|
221
|
+
*/
|
|
222
|
+
export function setCurrentScreenName(
|
|
223
|
+
screenName: string | null
|
|
224
|
+
): Promise<boolean | undefined> {
|
|
225
|
+
if (isClarityUnavailable()) {
|
|
226
|
+
return Promise.resolve(undefined);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return Clarity.setCurrentScreenName(screenName);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Returns the active session id. This can be used to correlate the Clarity session with other
|
|
234
|
+
* analytics tools that the developer may be using.
|
|
235
|
+
* @returns a promise that resolves to the current session id.
|
|
236
|
+
*/
|
|
237
|
+
export function getCurrentSessionId(): Promise<string> {
|
|
238
|
+
if (isClarityUnavailable()) {
|
|
239
|
+
return Promise.resolve('Undefined');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return Clarity.getCurrentSessionId();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Returns the active session url. This can be used to correlate the Clarity session with other
|
|
247
|
+
* analytics tools that the developer may be using.
|
|
248
|
+
*
|
|
249
|
+
* @returns a promise that resolves to the current session url if there is an active one.
|
|
250
|
+
*/
|
|
251
|
+
export function getCurrentSessionUrl(): Promise<string> {
|
|
252
|
+
if (isClarityUnavailable()) {
|
|
253
|
+
return Promise.resolve('Undefined');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return Clarity.getCurrentSessionUrl();
|
|
257
|
+
}
|