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