react-native-clarity 2.3.0 → 3.0.1
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 +9 -3
- package/android/build.gradle +1 -1
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityPackage.kt +17 -17
- package/ios/Clarity.h +12 -12
- package/ios/Clarity.m +131 -0
- package/ios/Clarity.xcodeproj/project.pbxproj +280 -274
- package/lib/commonjs/index.js +60 -83
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +58 -81
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +105 -101
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +8 -2
- package/react-native-clarity.podspec +36 -35
- package/src/index.tsx +89 -104
- package/ios/Clarity.mm +0 -15
package/lib/commonjs/index.js
CHANGED
|
@@ -15,11 +15,13 @@ exports.setCustomSessionId = setCustomSessionId;
|
|
|
15
15
|
exports.setCustomTag = setCustomTag;
|
|
16
16
|
exports.setCustomUserId = setCustomUserId;
|
|
17
17
|
var _reactNative = require("react-native");
|
|
18
|
-
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
19
|
+
ios: "- You have run 'pod install --repo-update'\n",
|
|
20
|
+
default: ''
|
|
21
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
21
22
|
const Clarity = _reactNative.NativeModules.Clarity;
|
|
22
23
|
const SupportedPlatforms = ['android'];
|
|
24
|
+
let SupportWarningWasShown = false;
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* The configuration that will be used to customize the Clarity behaviour.
|
|
@@ -34,13 +36,16 @@ const SupportedPlatforms = ['android'];
|
|
|
34
36
|
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
35
37
|
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
36
38
|
* If it contains "*" as an element, all domains will be captured.
|
|
39
|
+
* Note: iOS currently does not support allowedDomains feature.
|
|
37
40
|
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
38
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.
|
|
39
44
|
*/
|
|
40
45
|
/**
|
|
41
46
|
* The level of logging to show in the device logcat stream.
|
|
42
47
|
*/
|
|
43
|
-
let LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
48
|
+
let LogLevel = exports.LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
44
49
|
LogLevel["Verbose"] = "Verbose";
|
|
45
50
|
LogLevel["Debug"] = "Debug";
|
|
46
51
|
LogLevel["Info"] = "Info";
|
|
@@ -49,15 +54,33 @@ let LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
|
49
54
|
LogLevel["None"] = "None";
|
|
50
55
|
return LogLevel;
|
|
51
56
|
}({});
|
|
57
|
+
function isClarityUnavailable() {
|
|
58
|
+
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
|
+
if (!SupportWarningWasShown) {
|
|
64
|
+
console.warn(warningMessage);
|
|
65
|
+
SupportWarningWasShown = true;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (Clarity === null) {
|
|
70
|
+
console.error('Clarity did not initialize properly.', LINKING_ERROR);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
52
76
|
/**
|
|
53
77
|
* Initializes the Clarity SDK if the API level is supported.
|
|
54
78
|
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
55
79
|
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
56
|
-
*/
|
|
57
|
-
exports.LogLevel = LogLevel;
|
|
80
|
+
*/
|
|
58
81
|
function initialize(projectId, config) {
|
|
59
|
-
if (typeof projectId !==
|
|
60
|
-
throw Error(
|
|
82
|
+
if (typeof projectId !== 'string' || !(typeof config === 'object' || typeof config === 'undefined')) {
|
|
83
|
+
throw Error('Invalid Clarity initialization arguments. Please check the docs for assitance.');
|
|
61
84
|
}
|
|
62
85
|
|
|
63
86
|
// applying default values
|
|
@@ -66,16 +89,15 @@ function initialize(projectId, config) {
|
|
|
66
89
|
logLevel = LogLevel.None,
|
|
67
90
|
allowMeteredNetworkUsage = false,
|
|
68
91
|
enableWebViewCapture = true,
|
|
69
|
-
allowedDomains = [
|
|
92
|
+
allowedDomains = ['*'],
|
|
70
93
|
disableOnLowEndDevices = false,
|
|
71
|
-
maximumDailyNetworkUsageInMB = null
|
|
94
|
+
maximumDailyNetworkUsageInMB = null,
|
|
95
|
+
enableIOS_experimental = false
|
|
72
96
|
} = config ?? {};
|
|
73
|
-
if (!SupportedPlatforms.includes(
|
|
74
|
-
|
|
75
|
-
return;
|
|
97
|
+
if (enableIOS_experimental === true && !SupportedPlatforms.includes('ios')) {
|
|
98
|
+
SupportedPlatforms.push('ios');
|
|
76
99
|
}
|
|
77
|
-
if (
|
|
78
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
100
|
+
if (isClarityUnavailable()) {
|
|
79
101
|
return;
|
|
80
102
|
}
|
|
81
103
|
|
|
@@ -89,15 +111,10 @@ function initialize(projectId, config) {
|
|
|
89
111
|
* Pauses the Clarity capturing processes until the next resume() is called.
|
|
90
112
|
*/
|
|
91
113
|
function pause() {
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (Clarity === null) {
|
|
97
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
98
|
-
return;
|
|
114
|
+
if (isClarityUnavailable()) {
|
|
115
|
+
return Promise.resolve(undefined);
|
|
99
116
|
}
|
|
100
|
-
Clarity.pause();
|
|
117
|
+
return Clarity.pause();
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
/**
|
|
@@ -105,27 +122,17 @@ function pause() {
|
|
|
105
122
|
* Note: Clarity starts capturing data right on initialization.
|
|
106
123
|
*/
|
|
107
124
|
function resume() {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (Clarity === null) {
|
|
113
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
114
|
-
return;
|
|
125
|
+
if (isClarityUnavailable()) {
|
|
126
|
+
return Promise.resolve(undefined);
|
|
115
127
|
}
|
|
116
|
-
Clarity.resume();
|
|
128
|
+
return Clarity.resume();
|
|
117
129
|
}
|
|
118
130
|
|
|
119
131
|
/**
|
|
120
132
|
* Returns true if Clarity has been paused by the user.
|
|
121
133
|
*/
|
|
122
134
|
function isPaused() {
|
|
123
|
-
if (
|
|
124
|
-
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
125
|
-
return Promise.resolve(undefined);
|
|
126
|
-
}
|
|
127
|
-
if (Clarity === null) {
|
|
128
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
135
|
+
if (isClarityUnavailable()) {
|
|
129
136
|
return Promise.resolve(undefined);
|
|
130
137
|
}
|
|
131
138
|
return Clarity.isPaused();
|
|
@@ -142,15 +149,10 @@ function isPaused() {
|
|
|
142
149
|
* @param customUserId The custom user id to set.
|
|
143
150
|
*/
|
|
144
151
|
function setCustomUserId(customUserId) {
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (Clarity === null) {
|
|
150
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
151
|
-
return;
|
|
152
|
+
if (isClarityUnavailable()) {
|
|
153
|
+
return Promise.resolve(undefined);
|
|
152
154
|
}
|
|
153
|
-
Clarity.setCustomUserId(customUserId);
|
|
155
|
+
return Clarity.setCustomUserId(customUserId);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
/**
|
|
@@ -161,15 +163,10 @@ function setCustomUserId(customUserId) {
|
|
|
161
163
|
* @param customSessionId The custom session id to set.
|
|
162
164
|
*/
|
|
163
165
|
function setCustomSessionId(customSessionId) {
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (Clarity === null) {
|
|
169
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
170
|
-
return;
|
|
166
|
+
if (isClarityUnavailable()) {
|
|
167
|
+
return Promise.resolve(undefined);
|
|
171
168
|
}
|
|
172
|
-
Clarity.setCustomSessionId(customSessionId);
|
|
169
|
+
return Clarity.setCustomSessionId(customSessionId);
|
|
173
170
|
}
|
|
174
171
|
|
|
175
172
|
/**
|
|
@@ -178,15 +175,10 @@ function setCustomSessionId(customSessionId) {
|
|
|
178
175
|
* @param value The tag value to set.
|
|
179
176
|
*/
|
|
180
177
|
function setCustomTag(key, value) {
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (Clarity === null) {
|
|
186
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
187
|
-
return;
|
|
178
|
+
if (isClarityUnavailable()) {
|
|
179
|
+
return Promise.resolve(undefined);
|
|
188
180
|
}
|
|
189
|
-
Clarity.setCustomTag(key, value);
|
|
181
|
+
return Clarity.setCustomTag(key, value);
|
|
190
182
|
}
|
|
191
183
|
|
|
192
184
|
/**
|
|
@@ -197,15 +189,10 @@ function setCustomTag(key, value) {
|
|
|
197
189
|
* @param screenName The current screen name to set.
|
|
198
190
|
*/
|
|
199
191
|
function setCurrentScreenName(screenName) {
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (Clarity === null) {
|
|
205
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
206
|
-
return;
|
|
192
|
+
if (isClarityUnavailable()) {
|
|
193
|
+
return Promise.resolve(undefined);
|
|
207
194
|
}
|
|
208
|
-
Clarity.setCurrentScreenName(screenName);
|
|
195
|
+
return Clarity.setCurrentScreenName(screenName);
|
|
209
196
|
}
|
|
210
197
|
|
|
211
198
|
/**
|
|
@@ -214,13 +201,8 @@ function setCurrentScreenName(screenName) {
|
|
|
214
201
|
* @returns a promise that resolves to the current session id.
|
|
215
202
|
*/
|
|
216
203
|
function getCurrentSessionId() {
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
return Promise.resolve("Undefined");
|
|
220
|
-
}
|
|
221
|
-
if (Clarity === null) {
|
|
222
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
223
|
-
return Promise.resolve("Undefined");
|
|
204
|
+
if (isClarityUnavailable()) {
|
|
205
|
+
return Promise.resolve('Undefined');
|
|
224
206
|
}
|
|
225
207
|
return Clarity.getCurrentSessionId();
|
|
226
208
|
}
|
|
@@ -232,13 +214,8 @@ function getCurrentSessionId() {
|
|
|
232
214
|
* @returns a promise that resolves to the current session url if there is an active one.
|
|
233
215
|
*/
|
|
234
216
|
function getCurrentSessionUrl() {
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
return Promise.resolve("Undefined");
|
|
238
|
-
}
|
|
239
|
-
if (Clarity === null) {
|
|
240
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
241
|
-
return Promise.resolve("Undefined");
|
|
217
|
+
if (isClarityUnavailable()) {
|
|
218
|
+
return Promise.resolve('Undefined');
|
|
242
219
|
}
|
|
243
220
|
return Clarity.getCurrentSessionUrl();
|
|
244
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Clarity","NativeModules","SupportedPlatforms","LogLevel","exports","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Clarity","NativeModules","SupportedPlatforms","SupportWarningWasShown","LogLevel","exports","isClarityUnavailable","includes","OS","warningMessage","join","console","warn","error","initialize","projectId","config","Error","userId","logLevel","None","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","disableOnLowEndDevices","maximumDailyNetworkUsageInMB","enableIOS_experimental","push","enableDailyNetworkUsageLimit","refinedMaximumDailyNetworkUsageInMB","pause","Promise","resolve","undefined","resume","isPaused","setCustomUserId","customUserId","setCustomSessionId","customSessionId","setCustomTag","key","value","setCurrentScreenName","screenName","getCurrentSessionId","getCurrentSessionUrl"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,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,OAAO,GAAGC,0BAAa,CAACD,OAAO;AAErC,MAAME,kBAAkB,GAAG,CAAC,SAAS,CAAC;AAEtC,IAAIC,sBAAsB,GAAG,KAAK;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAYA;AACA;AACA;AAFA,IAGYC,QAAQ,GAAAC,OAAA,CAAAD,QAA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oBAAoB,CAAC,CAAC;AACvC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NativeModules, Platform } from 'react-native';
|
|
2
|
-
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
3
|
+
ios: "- You have run 'pod install --repo-update'\n",
|
|
4
|
+
default: ''
|
|
5
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
5
6
|
const Clarity = NativeModules.Clarity;
|
|
6
7
|
const SupportedPlatforms = ['android'];
|
|
8
|
+
let SupportWarningWasShown = false;
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* The configuration that will be used to customize the Clarity behaviour.
|
|
@@ -18,8 +20,11 @@ const SupportedPlatforms = ['android'];
|
|
|
18
20
|
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
19
21
|
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
20
22
|
* If it contains "*" as an element, all domains will be captured.
|
|
23
|
+
* Note: iOS currently does not support allowedDomains feature.
|
|
21
24
|
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
22
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.
|
|
23
28
|
*/
|
|
24
29
|
|
|
25
30
|
/**
|
|
@@ -34,15 +39,33 @@ export let LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
|
34
39
|
LogLevel["None"] = "None";
|
|
35
40
|
return LogLevel;
|
|
36
41
|
}({});
|
|
42
|
+
function isClarityUnavailable() {
|
|
43
|
+
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
|
+
if (!SupportWarningWasShown) {
|
|
49
|
+
console.warn(warningMessage);
|
|
50
|
+
SupportWarningWasShown = true;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (Clarity === null) {
|
|
55
|
+
console.error('Clarity did not initialize properly.', LINKING_ERROR);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
37
60
|
|
|
38
61
|
/**
|
|
39
62
|
* Initializes the Clarity SDK if the API level is supported.
|
|
40
63
|
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
41
64
|
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
42
|
-
*/
|
|
65
|
+
*/
|
|
43
66
|
export function initialize(projectId, config) {
|
|
44
|
-
if (typeof projectId !==
|
|
45
|
-
throw Error(
|
|
67
|
+
if (typeof projectId !== 'string' || !(typeof config === 'object' || typeof config === 'undefined')) {
|
|
68
|
+
throw Error('Invalid Clarity initialization arguments. Please check the docs for assitance.');
|
|
46
69
|
}
|
|
47
70
|
|
|
48
71
|
// applying default values
|
|
@@ -51,16 +74,15 @@ export function initialize(projectId, config) {
|
|
|
51
74
|
logLevel = LogLevel.None,
|
|
52
75
|
allowMeteredNetworkUsage = false,
|
|
53
76
|
enableWebViewCapture = true,
|
|
54
|
-
allowedDomains = [
|
|
77
|
+
allowedDomains = ['*'],
|
|
55
78
|
disableOnLowEndDevices = false,
|
|
56
|
-
maximumDailyNetworkUsageInMB = null
|
|
79
|
+
maximumDailyNetworkUsageInMB = null,
|
|
80
|
+
enableIOS_experimental = false
|
|
57
81
|
} = config ?? {};
|
|
58
|
-
if (!SupportedPlatforms.includes(
|
|
59
|
-
|
|
60
|
-
return;
|
|
82
|
+
if (enableIOS_experimental === true && !SupportedPlatforms.includes('ios')) {
|
|
83
|
+
SupportedPlatforms.push('ios');
|
|
61
84
|
}
|
|
62
|
-
if (
|
|
63
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
85
|
+
if (isClarityUnavailable()) {
|
|
64
86
|
return;
|
|
65
87
|
}
|
|
66
88
|
|
|
@@ -74,15 +96,10 @@ export function initialize(projectId, config) {
|
|
|
74
96
|
* Pauses the Clarity capturing processes until the next resume() is called.
|
|
75
97
|
*/
|
|
76
98
|
export function pause() {
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (Clarity === null) {
|
|
82
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
83
|
-
return;
|
|
99
|
+
if (isClarityUnavailable()) {
|
|
100
|
+
return Promise.resolve(undefined);
|
|
84
101
|
}
|
|
85
|
-
Clarity.pause();
|
|
102
|
+
return Clarity.pause();
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
/**
|
|
@@ -90,27 +107,17 @@ export function pause() {
|
|
|
90
107
|
* Note: Clarity starts capturing data right on initialization.
|
|
91
108
|
*/
|
|
92
109
|
export function resume() {
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (Clarity === null) {
|
|
98
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
99
|
-
return;
|
|
110
|
+
if (isClarityUnavailable()) {
|
|
111
|
+
return Promise.resolve(undefined);
|
|
100
112
|
}
|
|
101
|
-
Clarity.resume();
|
|
113
|
+
return Clarity.resume();
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
/**
|
|
105
117
|
* Returns true if Clarity has been paused by the user.
|
|
106
118
|
*/
|
|
107
119
|
export function isPaused() {
|
|
108
|
-
if (
|
|
109
|
-
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
110
|
-
return Promise.resolve(undefined);
|
|
111
|
-
}
|
|
112
|
-
if (Clarity === null) {
|
|
113
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
120
|
+
if (isClarityUnavailable()) {
|
|
114
121
|
return Promise.resolve(undefined);
|
|
115
122
|
}
|
|
116
123
|
return Clarity.isPaused();
|
|
@@ -127,15 +134,10 @@ export function isPaused() {
|
|
|
127
134
|
* @param customUserId The custom user id to set.
|
|
128
135
|
*/
|
|
129
136
|
export function setCustomUserId(customUserId) {
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (Clarity === null) {
|
|
135
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
136
|
-
return;
|
|
137
|
+
if (isClarityUnavailable()) {
|
|
138
|
+
return Promise.resolve(undefined);
|
|
137
139
|
}
|
|
138
|
-
Clarity.setCustomUserId(customUserId);
|
|
140
|
+
return Clarity.setCustomUserId(customUserId);
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/**
|
|
@@ -146,15 +148,10 @@ export function setCustomUserId(customUserId) {
|
|
|
146
148
|
* @param customSessionId The custom session id to set.
|
|
147
149
|
*/
|
|
148
150
|
export function setCustomSessionId(customSessionId) {
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (Clarity === null) {
|
|
154
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
155
|
-
return;
|
|
151
|
+
if (isClarityUnavailable()) {
|
|
152
|
+
return Promise.resolve(undefined);
|
|
156
153
|
}
|
|
157
|
-
Clarity.setCustomSessionId(customSessionId);
|
|
154
|
+
return Clarity.setCustomSessionId(customSessionId);
|
|
158
155
|
}
|
|
159
156
|
|
|
160
157
|
/**
|
|
@@ -163,15 +160,10 @@ export function setCustomSessionId(customSessionId) {
|
|
|
163
160
|
* @param value The tag value to set.
|
|
164
161
|
*/
|
|
165
162
|
export function setCustomTag(key, value) {
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (Clarity === null) {
|
|
171
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
172
|
-
return;
|
|
163
|
+
if (isClarityUnavailable()) {
|
|
164
|
+
return Promise.resolve(undefined);
|
|
173
165
|
}
|
|
174
|
-
Clarity.setCustomTag(key, value);
|
|
166
|
+
return Clarity.setCustomTag(key, value);
|
|
175
167
|
}
|
|
176
168
|
|
|
177
169
|
/**
|
|
@@ -182,15 +174,10 @@ export function setCustomTag(key, value) {
|
|
|
182
174
|
* @param screenName The current screen name to set.
|
|
183
175
|
*/
|
|
184
176
|
export function setCurrentScreenName(screenName) {
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (Clarity === null) {
|
|
190
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
191
|
-
return;
|
|
177
|
+
if (isClarityUnavailable()) {
|
|
178
|
+
return Promise.resolve(undefined);
|
|
192
179
|
}
|
|
193
|
-
Clarity.setCurrentScreenName(screenName);
|
|
180
|
+
return Clarity.setCurrentScreenName(screenName);
|
|
194
181
|
}
|
|
195
182
|
|
|
196
183
|
/**
|
|
@@ -199,13 +186,8 @@ export function setCurrentScreenName(screenName) {
|
|
|
199
186
|
* @returns a promise that resolves to the current session id.
|
|
200
187
|
*/
|
|
201
188
|
export function getCurrentSessionId() {
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
return Promise.resolve("Undefined");
|
|
205
|
-
}
|
|
206
|
-
if (Clarity === null) {
|
|
207
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
208
|
-
return Promise.resolve("Undefined");
|
|
189
|
+
if (isClarityUnavailable()) {
|
|
190
|
+
return Promise.resolve('Undefined');
|
|
209
191
|
}
|
|
210
192
|
return Clarity.getCurrentSessionId();
|
|
211
193
|
}
|
|
@@ -217,13 +199,8 @@ export function getCurrentSessionId() {
|
|
|
217
199
|
* @returns a promise that resolves to the current session url if there is an active one.
|
|
218
200
|
*/
|
|
219
201
|
export function getCurrentSessionUrl() {
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
return Promise.resolve("Undefined");
|
|
223
|
-
}
|
|
224
|
-
if (Clarity === null) {
|
|
225
|
-
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
226
|
-
return Promise.resolve("Undefined");
|
|
202
|
+
if (isClarityUnavailable()) {
|
|
203
|
+
return Promise.resolve('Undefined');
|
|
227
204
|
}
|
|
228
205
|
return Clarity.getCurrentSessionUrl();
|
|
229
206
|
}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","Clarity","SupportedPlatforms","LogLevel","
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","Clarity","SupportedPlatforms","SupportWarningWasShown","LogLevel","isClarityUnavailable","includes","OS","warningMessage","join","console","warn","error","initialize","projectId","config","Error","userId","logLevel","None","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","disableOnLowEndDevices","maximumDailyNetworkUsageInMB","enableIOS_experimental","push","enableDailyNetworkUsageLimit","refinedMaximumDailyNetworkUsageInMB","pause","Promise","resolve","undefined","resume","isPaused","setCustomUserId","customUserId","setCustomSessionId","customSessionId","setCustomTag","key","value","setCurrentScreenName","screenName","getCurrentSessionId","getCurrentSessionUrl"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,+EAA+E,GAC/ED,QAAQ,CAACE,MAAM,CAAC;EACdC,GAAG,EAAE,8C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