react-native-clarity 3.1.1 → 4.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/README.md +113 -59
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityEmitter.kt +55 -0
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityModule.kt +12 -22
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityPackage.kt +4 -1
- package/ios/Clarity.m +38 -22
- package/ios/Clarity.xcodeproj/project.pbxproj +6 -0
- package/ios/ClarityEmitter.h +6 -0
- package/ios/ClarityEmitter.m +50 -0
- package/lib/commonjs/index.js +198 -84
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +195 -85
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +130 -68
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/react-native-clarity.podspec +1 -1
- package/src/index.tsx +268 -120
package/lib/commonjs/index.js
CHANGED
|
@@ -10,40 +10,37 @@ exports.initialize = initialize;
|
|
|
10
10
|
exports.isPaused = isPaused;
|
|
11
11
|
exports.pause = pause;
|
|
12
12
|
exports.resume = resume;
|
|
13
|
+
exports.sendCustomEvent = sendCustomEvent;
|
|
13
14
|
exports.setCurrentScreenName = setCurrentScreenName;
|
|
14
15
|
exports.setCustomSessionId = setCustomSessionId;
|
|
15
16
|
exports.setCustomTag = setCustomTag;
|
|
16
17
|
exports.setCustomUserId = setCustomUserId;
|
|
18
|
+
exports.setOnSessionStartedCallback = setOnSessionStartedCallback;
|
|
19
|
+
exports.startNewSession = startNewSession;
|
|
17
20
|
var _reactNative = require("react-native");
|
|
18
21
|
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
19
22
|
ios: "- You have run 'pod install --repo-update'\n",
|
|
20
23
|
default: ''
|
|
21
24
|
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
25
|
+
const ReferToDocs = 'Please check the docs at https://www.npmjs.com/package/react-native-clarity for assistance.';
|
|
22
26
|
const Clarity = _reactNative.NativeModules.Clarity;
|
|
23
|
-
const
|
|
27
|
+
const ClarityEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.ClarityEmitter);
|
|
28
|
+
const SupportedPlatforms = ['android', 'ios'];
|
|
24
29
|
let SupportWarningWasShown = false;
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
30
|
-
* will be auto generated. The user id in general is sticky across sessions.
|
|
31
|
-
* The provided user id must follow these conditions:
|
|
32
|
-
* 1. Cannot be an empty string.
|
|
33
|
-
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
34
|
-
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
35
|
-
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
36
|
-
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
37
|
-
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
38
|
-
* If it contains "*" as an element, all domains will be captured.
|
|
39
|
-
* Note: iOS currently does not support allowedDomains feature.
|
|
40
|
-
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
41
|
-
* @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.
|
|
42
|
-
* Note: iOS currently does not support limiting network usage.
|
|
43
|
-
* @param enableIOS_experimental [OPTIONAL default = false] Experimental flag to enable Clarity on iOS platform.
|
|
32
|
+
* A class that allows you to configure the Clarity SDK behavior.
|
|
44
33
|
*/
|
|
34
|
+
|
|
35
|
+
const ValidConfigKeys = new Set(Object.keys({
|
|
36
|
+
userId: undefined,
|
|
37
|
+
// Deprecated.
|
|
38
|
+
logLevel: undefined
|
|
39
|
+
}));
|
|
40
|
+
const RemovedDynamicConfigKeys = new Set(['allowMeteredNetworkUsage', 'enableWebViewCapture', 'allowedDomains', 'disableOnLowEndDevices', 'maximumDailyNetworkUsageInMB']);
|
|
41
|
+
|
|
45
42
|
/**
|
|
46
|
-
* The level of logging to show in the device
|
|
43
|
+
* The level of logging to show in the device logging stream.
|
|
47
44
|
*/
|
|
48
45
|
let LogLevel = exports.LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
49
46
|
LogLevel["Verbose"] = "Verbose";
|
|
@@ -54,14 +51,16 @@ let LogLevel = exports.LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
|
54
51
|
LogLevel["None"] = "None";
|
|
55
52
|
return LogLevel;
|
|
56
53
|
}({});
|
|
54
|
+
class ClarityError extends Error {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = 'ClarityError';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
57
60
|
function isClarityUnavailable() {
|
|
58
61
|
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
59
|
-
let warningMessage = 'Clarity supports ' + SupportedPlatforms.join(', ') + ' only for now.';
|
|
60
|
-
if (_reactNative.Platform.OS === 'ios') {
|
|
61
|
-
warningMessage = `${warningMessage} To enable experimental iOS support, set the 'enableIOS_experimental' config value to true.`;
|
|
62
|
-
}
|
|
63
62
|
if (!SupportWarningWasShown) {
|
|
64
|
-
console.warn(
|
|
63
|
+
console.warn('Clarity supports ' + SupportedPlatforms.join(', ') + ' only for now.');
|
|
65
64
|
SupportWarningWasShown = true;
|
|
66
65
|
}
|
|
67
66
|
return true;
|
|
@@ -72,150 +71,265 @@ function isClarityUnavailable() {
|
|
|
72
71
|
}
|
|
73
72
|
return false;
|
|
74
73
|
}
|
|
74
|
+
function validateClarityConfig(config) {
|
|
75
|
+
if (typeof config === 'undefined') {
|
|
76
|
+
// Allow using defaults when config is `null` or `undefined`.
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof config !== 'object') {
|
|
80
|
+
throw new ClarityError(`Invalid Clarity initialization \`config\` argument. Expected an object, but received ${typeof config}. ${ReferToDocs}`);
|
|
81
|
+
}
|
|
82
|
+
if (config !== null && config !== void 0 && config.logLevel && !Object.values(LogLevel).includes(config.logLevel)) {
|
|
83
|
+
console.error(`Invalid ClarityConfig \`logLevel\` property value: ${config.logLevel}. Valid values are: ${Object.values(LogLevel).join(', ')}. ${ReferToDocs}`);
|
|
84
|
+
}
|
|
85
|
+
for (const key in config) {
|
|
86
|
+
if (RemovedDynamicConfigKeys.has(key)) {
|
|
87
|
+
throw new ClarityError(`The ClarityConfig \`${key}\` property is removed and it's configurable from Clarity dashboard.`);
|
|
88
|
+
} else if (key === 'enableIOS_experimental') {
|
|
89
|
+
const errorMessage = 'The ClarityConfig `enableIOS_experimental` property is removed and iOS is supported by default.';
|
|
90
|
+
if (config.enableIOS_experimental) {
|
|
91
|
+
// Proceed with initialization if the user intended to enable iOS support.
|
|
92
|
+
console.error(errorMessage);
|
|
93
|
+
} else {
|
|
94
|
+
throw new ClarityError(errorMessage);
|
|
95
|
+
}
|
|
96
|
+
} else if (key === 'userId') {
|
|
97
|
+
console.warn('The ClarityConfig `userId` property is deprecated and would be removed in a future major version. Use `setCustomUserId()` instead.');
|
|
98
|
+
} else if (!ValidConfigKeys.has(key)) {
|
|
99
|
+
console.warn(`Invalid ClarityConfig property: \`${key}\`.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
75
103
|
|
|
76
104
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param
|
|
79
|
-
*
|
|
105
|
+
* @param projectId - The unique identifier assigned to your Clarity project. You can find it on the **Settings** page of Clarity dashboard. This ID is essential for routing data to the correct Clarity project (required).
|
|
106
|
+
* @param config - Configuration of Clarity that tunes the SDK behavior (for example, which log level to use, and so on).
|
|
107
|
+
*
|
|
108
|
+
* **Notes:**
|
|
109
|
+
* - The initialization function is asynchronous, meaning it returns before Clarity is fully initialized.
|
|
110
|
+
* - For actions that require Clarity to be fully initialized, it's recommended to use the {@linkcode setOnSessionStartedCallback} function.
|
|
80
111
|
*/
|
|
81
112
|
function initialize(projectId, config) {
|
|
82
|
-
if (typeof projectId !== 'string'
|
|
83
|
-
throw
|
|
113
|
+
if (typeof projectId !== 'string') {
|
|
114
|
+
throw new ClarityError(`Invalid Clarity initialization \`projectId\` argument. Expected a string, but received ${typeof projectId}. ${ReferToDocs}`);
|
|
84
115
|
}
|
|
116
|
+
validateClarityConfig(config);
|
|
85
117
|
|
|
86
118
|
// applying default values
|
|
87
119
|
let {
|
|
88
120
|
userId = null,
|
|
89
|
-
logLevel = LogLevel.None
|
|
90
|
-
allowMeteredNetworkUsage = false,
|
|
91
|
-
enableWebViewCapture = true,
|
|
92
|
-
allowedDomains = ['*'],
|
|
93
|
-
disableOnLowEndDevices = false,
|
|
94
|
-
maximumDailyNetworkUsageInMB = null,
|
|
95
|
-
enableIOS_experimental = false
|
|
121
|
+
logLevel = LogLevel.None
|
|
96
122
|
} = config ?? {};
|
|
97
|
-
if (enableIOS_experimental === true && !SupportedPlatforms.includes('ios')) {
|
|
98
|
-
SupportedPlatforms.push('ios');
|
|
99
|
-
}
|
|
100
123
|
if (isClarityUnavailable()) {
|
|
101
124
|
return;
|
|
102
125
|
}
|
|
103
|
-
|
|
104
|
-
// We use two parameters because the react method parameters do not accept nullable primitive types.
|
|
105
|
-
let enableDailyNetworkUsageLimit = maximumDailyNetworkUsageInMB != null;
|
|
106
|
-
let refinedMaximumDailyNetworkUsageInMB = maximumDailyNetworkUsageInMB ?? 0;
|
|
107
|
-
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices, enableDailyNetworkUsageLimit, refinedMaximumDailyNetworkUsageInMB);
|
|
126
|
+
Clarity.initialize(projectId, userId, logLevel);
|
|
108
127
|
}
|
|
109
128
|
|
|
110
129
|
/**
|
|
111
|
-
* Pauses the Clarity capturing
|
|
130
|
+
* Pauses the Clarity session capturing until a call to the {@linkcode resume} function is made.
|
|
131
|
+
*
|
|
132
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if Clarity session capturing was paused successfully; otherwise `false`.
|
|
112
133
|
*/
|
|
113
134
|
function pause() {
|
|
114
135
|
if (isClarityUnavailable()) {
|
|
115
|
-
return Promise.resolve(
|
|
136
|
+
return Promise.resolve(false);
|
|
116
137
|
}
|
|
117
138
|
return Clarity.pause();
|
|
118
139
|
}
|
|
119
140
|
|
|
120
141
|
/**
|
|
121
|
-
* Resumes the Clarity capturing
|
|
122
|
-
*
|
|
142
|
+
* Resumes the Clarity session capturing only if it was previously paused by a call to the {@linkcode pause} function.
|
|
143
|
+
*
|
|
144
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if Clarity session capturing was resumed successfully; otherwise `false`.
|
|
123
145
|
*/
|
|
124
146
|
function resume() {
|
|
125
147
|
if (isClarityUnavailable()) {
|
|
126
|
-
return Promise.resolve(
|
|
148
|
+
return Promise.resolve(false);
|
|
127
149
|
}
|
|
128
150
|
return Clarity.resume();
|
|
129
151
|
}
|
|
130
152
|
|
|
131
153
|
/**
|
|
132
|
-
*
|
|
154
|
+
* Checks if Clarity session capturing is currently paused based on an earlier call to the {@linkcode pause} function.
|
|
155
|
+
*
|
|
156
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if Clarity session capturing is currently in the paused state based on an earlier call to the {@linkcode pause} function; otherwise `false`.
|
|
133
157
|
*/
|
|
134
158
|
function isPaused() {
|
|
135
159
|
if (isClarityUnavailable()) {
|
|
136
|
-
return Promise.resolve(
|
|
160
|
+
return Promise.resolve(false);
|
|
137
161
|
}
|
|
138
162
|
return Clarity.isPaused();
|
|
139
163
|
}
|
|
140
164
|
|
|
141
165
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
166
|
+
* Forces Clarity to start a new session asynchronously.
|
|
167
|
+
*
|
|
168
|
+
* @param callback - A callback that is invoked when the new session starts. The callback receives the new session ID as a string parameter.
|
|
169
|
+
*
|
|
170
|
+
* **Notes:**
|
|
171
|
+
* - This function is asynchronous, meaning it returns before the new session is started.
|
|
172
|
+
* - Use the {@linkcode callback} parameter to execute logic that needs to run after the new session begins.
|
|
173
|
+
* - Events that occur before invoking the callback are associated with the previous session.
|
|
174
|
+
* - To ensure proper association of custom tags, user ID, or session ID with the new session, set them within the callback.
|
|
175
|
+
*/
|
|
176
|
+
function startNewSession(callback) {
|
|
177
|
+
if (isClarityUnavailable()) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
Clarity.startNewSession(callback);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Sets a custom user ID for the current session. This ID can be used to filter sessions on the Clarity dashboard.
|
|
185
|
+
*
|
|
186
|
+
* @param customUserId - The custom user ID to associate with the current session. The value must be a nonempty string, with a maximum length of 255 characters, and can't consist only of whitespace.
|
|
187
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if the custom user ID was set successfully; otherwise `false`.
|
|
188
|
+
*
|
|
189
|
+
* **Notes:**
|
|
190
|
+
* - To ensure that the custom user ID is associated with the correct session, it's recommended to call this function within the callbacks of {@linkcode setOnSessionStartedCallback} or {@linkcode startNewSession}.
|
|
191
|
+
* - Unlike the `userID`, the {@linkcode customUserId} value has fewer restrictions.
|
|
192
|
+
* - We recommend **not** to set any Personally Identifiable Information (PII) values inside this field.
|
|
150
193
|
*/
|
|
151
194
|
function setCustomUserId(customUserId) {
|
|
152
195
|
if (isClarityUnavailable()) {
|
|
153
|
-
return Promise.resolve(
|
|
196
|
+
return Promise.resolve(false);
|
|
154
197
|
}
|
|
155
198
|
return Clarity.setCustomUserId(customUserId);
|
|
156
199
|
}
|
|
157
200
|
|
|
158
201
|
/**
|
|
159
|
-
* Sets a custom session
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
202
|
+
* Sets a custom session ID for the current session. This ID can be used to filter sessions on the Clarity dashboard.
|
|
203
|
+
*
|
|
204
|
+
* @param customSessionId - The custom session ID to associate with the current session. The value must be a nonempty string, with a maximum length of 255 characters, and can't consist only of whitespace.
|
|
205
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if the custom session ID was set successfully; otherwise `false`.
|
|
206
|
+
*
|
|
207
|
+
* **Notes:**
|
|
208
|
+
* - To ensure that the custom session ID is associated with the correct session, it's recommended to call this function within the callbacks of {@linkcode setOnSessionStartedCallback} or {@linkcode startNewSession}.
|
|
164
209
|
*/
|
|
165
210
|
function setCustomSessionId(customSessionId) {
|
|
166
211
|
if (isClarityUnavailable()) {
|
|
167
|
-
return Promise.resolve(
|
|
212
|
+
return Promise.resolve(false);
|
|
168
213
|
}
|
|
169
214
|
return Clarity.setCustomSessionId(customSessionId);
|
|
170
215
|
}
|
|
171
216
|
|
|
172
217
|
/**
|
|
173
|
-
* Sets a custom tag for the current session.
|
|
174
|
-
*
|
|
175
|
-
* @param
|
|
218
|
+
* Sets a custom tag for the current session. This tag can be used to filter sessions on the Clarity dashboard.
|
|
219
|
+
*
|
|
220
|
+
* @param key - The key for the custom tag. The value must be a nonempty string, with a maximum length of 255 characters, and can't consist only of whitespace.
|
|
221
|
+
* @param value - The value for the custom tag. The value must be a nonempty string, with a maximum length of 255 characters, and can't consist only of whitespace.
|
|
222
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if the custom tag was set successfully; otherwise `false`.
|
|
223
|
+
*
|
|
224
|
+
* **Notes:**
|
|
225
|
+
* - To ensure that the custom tag is associated with the correct session, it's recommended to call this function within the callbacks of {@linkcode setOnSessionStartedCallback} or {@linkcode startNewSession}.
|
|
176
226
|
*/
|
|
177
227
|
function setCustomTag(key, value) {
|
|
178
228
|
if (isClarityUnavailable()) {
|
|
179
|
-
return Promise.resolve(
|
|
229
|
+
return Promise.resolve(false);
|
|
180
230
|
}
|
|
181
231
|
return Clarity.setCustomTag(key, value);
|
|
182
232
|
}
|
|
183
233
|
|
|
184
234
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
235
|
+
* Sends a custom event to the current Clarity session. These custom events can be used to track specific user interactions or actions that Clarity's built-in event tracking doesn't capture.
|
|
236
|
+
*
|
|
237
|
+
* @param value - The name of the custom event. The value must be a nonempty string, with a maximum length of 254 characters, and can't consist only of whitespace.
|
|
238
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if the custom event was sent successfully; otherwise `false`.
|
|
239
|
+
*
|
|
240
|
+
* **Notes:**
|
|
241
|
+
* - This API can be called multiple times per page to track various user actions.
|
|
242
|
+
* - Each custom event is logged individually and can be filtered, viewed, and analyzed on the Clarity dashboard.
|
|
243
|
+
*/
|
|
244
|
+
function sendCustomEvent(value) {
|
|
245
|
+
if (isClarityUnavailable()) {
|
|
246
|
+
return Promise.resolve(false);
|
|
247
|
+
}
|
|
248
|
+
return Clarity.sendCustomEvent(value);
|
|
249
|
+
}
|
|
250
|
+
let onSessionStartedSubscription = null;
|
|
251
|
+
var onSessionStartedCallback = null;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Sets a callback function that's invoked whenever a new Clarity session starts or an existing session is resumed at app startup.
|
|
255
|
+
*
|
|
256
|
+
* @param callback - The callback to be invoked whenever a Clarity session starts. The callback receives the new or resumed session ID as a string parameter.
|
|
257
|
+
* @returns {boolean} `true` if the callback was set successfully; otherwise `false`.
|
|
258
|
+
*
|
|
259
|
+
* **Notes:**
|
|
260
|
+
* - If the callback is set after a session has already started, the callback is invoked right away with the current session ID.
|
|
261
|
+
* - The specified callback is guaranteed to run on the main thread.
|
|
262
|
+
*/
|
|
263
|
+
function setOnSessionStartedCallback(callback) {
|
|
264
|
+
if (isClarityUnavailable()) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
onSessionStartedCallback = callback;
|
|
268
|
+
if (onSessionStartedSubscription === null) {
|
|
269
|
+
onSessionStartedSubscription = ClarityEmitter.addListener('sessionStarted', ({
|
|
270
|
+
sessionId
|
|
271
|
+
}) => {
|
|
272
|
+
if (onSessionStartedCallback !== null) {
|
|
273
|
+
onSessionStartedCallback(sessionId);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* This function allows you to provide a custom screen name tag that's added as a suffix to the base screen name. The base name is automatically generated based on the current activity in Android, or the currently presented view controller's title or type in iOS.
|
|
282
|
+
*
|
|
283
|
+
* @param screenName - The desired screen name tag. The value must be a nonempty string, with a maximum length of 255 characters, and can't consist only of whitespace nor contain `/` character. Set to `null` to reset.
|
|
284
|
+
* @returns {Promise<boolean>} A Promise that resolves with `true` if the specified screen name tag was set successfully; otherwise `false`.
|
|
285
|
+
*
|
|
286
|
+
* **Example:**
|
|
287
|
+
* - If the presented iOS view controller is a `UIViewController`, and `setCurrentScreenName("Settings")` is called, the screen name is tracked as "UIViewController/Settings".
|
|
288
|
+
* - If `setCurrentScreenName(nil)` is called on the same view controller, the screen name is tracked as "UIViewController".
|
|
289
|
+
*
|
|
290
|
+
* **Notes:**
|
|
291
|
+
* - Clarity starts a new page whenever either the base screen name (generated from the Android activity or iOS view controller) or the custom name tag changes.
|
|
292
|
+
* - To mask or disallow a screen, specify the base screen name without the custom tag suffix. For example, to mask the iOS view controller in the previous example, mask the "UIViewController" screen instead of "UIViewController/Settings".
|
|
293
|
+
* - The screen name tag is set globally and persists across all subsequent Android activities or iOS view controllers until explicitly reset.
|
|
190
294
|
*/
|
|
191
295
|
function setCurrentScreenName(screenName) {
|
|
192
296
|
if (isClarityUnavailable()) {
|
|
193
|
-
return Promise.resolve(
|
|
297
|
+
return Promise.resolve(false);
|
|
194
298
|
}
|
|
195
299
|
return Clarity.setCurrentScreenName(screenName);
|
|
196
300
|
}
|
|
197
301
|
|
|
198
302
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
303
|
+
* @deprecated This function is deprecated and would be removed in a future major version. Use {@linkcode getCurrentSessionUrl} instead.
|
|
304
|
+
*
|
|
305
|
+
* Returns the ID of the currently active Clarity session if a session has already started; otherwise `undefined`.
|
|
306
|
+
*
|
|
307
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with a string representing the ID of the currently active Clarity session if a session has already started; otherwise `undefined`.
|
|
308
|
+
*
|
|
309
|
+
* **Note:**
|
|
310
|
+
* - The session ID can be used to correlate Clarity sessions with other telemetry services.
|
|
311
|
+
* - Initially, this function might return `undefined` until a Clarity session begins.
|
|
312
|
+
* - To ensure a valid session ID, use this method within the callbacks of {@linkcode setOnSessionStartedCallback} or {@linkcode startNewSession}.
|
|
202
313
|
*/
|
|
203
314
|
function getCurrentSessionId() {
|
|
204
315
|
if (isClarityUnavailable()) {
|
|
205
|
-
return Promise.resolve(
|
|
316
|
+
return Promise.resolve(undefined);
|
|
206
317
|
}
|
|
207
318
|
return Clarity.getCurrentSessionId();
|
|
208
319
|
}
|
|
209
320
|
|
|
210
321
|
/**
|
|
211
|
-
* Returns the
|
|
212
|
-
* analytics tools that the developer may be using.
|
|
322
|
+
* Returns the URL of the current Clarity session recording on the Clarity dashboard if a session has already started; otherwise `undefined`.
|
|
213
323
|
*
|
|
214
|
-
* @returns
|
|
324
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with a string representing the URL of the current Clarity session recording on the Clarity dashboard if a session has already started; otherwise `undefined`.
|
|
325
|
+
*
|
|
326
|
+
* **Notes:**
|
|
327
|
+
* - Initially, this function might return `undefined` until a Clarity session begins.
|
|
328
|
+
* - To ensure a valid session URL, use this method within the callbacks of {@linkcode setOnSessionStartedCallback} or {@linkcode startNewSession}.
|
|
215
329
|
*/
|
|
216
330
|
function getCurrentSessionUrl() {
|
|
217
331
|
if (isClarityUnavailable()) {
|
|
218
|
-
return Promise.resolve(
|
|
332
|
+
return Promise.resolve(undefined);
|
|
219
333
|
}
|
|
220
334
|
return Clarity.getCurrentSessionUrl();
|
|
221
335
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Clarity","NativeModules","SupportedPlatforms","SupportWarningWasShown","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","ReferToDocs","Clarity","NativeModules","ClarityEmitter","NativeEventEmitter","SupportedPlatforms","SupportWarningWasShown","ValidConfigKeys","Set","Object","keys","userId","undefined","logLevel","RemovedDynamicConfigKeys","LogLevel","exports","ClarityError","Error","constructor","message","name","isClarityUnavailable","includes","OS","console","warn","join","error","validateClarityConfig","config","values","key","has","errorMessage","enableIOS_experimental","initialize","projectId","None","pause","Promise","resolve","resume","isPaused","startNewSession","callback","setCustomUserId","customUserId","setCustomSessionId","customSessionId","setCustomTag","value","sendCustomEvent","onSessionStartedSubscription","onSessionStartedCallback","setOnSessionStartedCallback","addListener","sessionId","setCurrentScreenName","screenName","getCurrentSessionId","getCurrentSessionUrl"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,MAAMC,aAAa,GACjB,+EAA+E,GAC/EC,qBAAQ,CAACC,MAAM,CAAC;EACdC,GAAG,EAAE,8CAA8C;EACnDC,OAAO,EAAE;AACX,CAAC,CAAC,GACF,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,WAAW,GACf,6FAA6F;AAE/F,MAAMC,OAAO,GAAGC,0BAAa,CAACD,OAAO;AACrC,MAAME,cAAc,GAAG,IAAIC,+BAAkB,CAACF,0BAAa,CAACC,cAAc,CAAC;AAE3E,MAAME,kBA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