react-native-clarity 1.0.0 → 2.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.
- package/README.md +42 -21
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/microsoft/clarity/reactnative/ClarityModule.kt +17 -1
- package/lib/commonjs/index.js +98 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +96 -24
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +54 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +106 -26
package/README.md
CHANGED
|
@@ -11,16 +11,24 @@ npm install react-native-clarity
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import { initialize, setCustomUserId,
|
|
14
|
+
import {LogLevel, initialize, setCustomUserId, setCustomSessionId, setCustomTag, setCurrentScreenName, getCurrentSessionId } from 'react-native-clarity';
|
|
15
15
|
|
|
16
16
|
// Initialize Clarity.
|
|
17
|
-
|
|
17
|
+
let clarityConfig = {
|
|
18
|
+
logLevel: LogLevel.Verbose,
|
|
19
|
+
allowMeteredNetworkUsage: true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
initialize('<ProjectId>', clarityConfig);
|
|
18
23
|
|
|
19
24
|
// Set custom user id.
|
|
20
|
-
setCustomUserId("
|
|
25
|
+
setCustomUserId("<CustomUserId>");
|
|
21
26
|
|
|
22
|
-
//
|
|
23
|
-
|
|
27
|
+
// Set custom session id.
|
|
28
|
+
setCustomSessionId("<CustomSessionId>");
|
|
29
|
+
|
|
30
|
+
// Set custom tag.
|
|
31
|
+
setCustomTag("key", "value");
|
|
24
32
|
|
|
25
33
|
// Setting the current screen name when using React Navigation
|
|
26
34
|
import { ..., useFocusEffect } from '@react-navigation/native';
|
|
@@ -36,33 +44,46 @@ const HomeScreen = ({...}) => {
|
|
|
36
44
|
);
|
|
37
45
|
...
|
|
38
46
|
};
|
|
47
|
+
|
|
48
|
+
// Get current session id to correlate with other tools.
|
|
49
|
+
getCurrentSessionId().then((id) => {...});
|
|
39
50
|
```
|
|
40
51
|
|
|
41
52
|
### Initialization arguments
|
|
42
53
|
|
|
43
|
-
```
|
|
54
|
+
```ts
|
|
44
55
|
/**
|
|
45
|
-
* Initializes the Clarity
|
|
46
|
-
*
|
|
47
|
-
* @param projectId The Clarity project id to send data to.
|
|
48
|
-
* @param
|
|
56
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
57
|
+
*
|
|
58
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
59
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
60
|
+
*/
|
|
61
|
+
function initialize(projectId: string, config?: ClarityConfig)
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
65
|
+
*
|
|
66
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
49
67
|
* will be auto generated. The user id in general is sticky across sessions.
|
|
50
68
|
* The provided user id must follow these conditions:
|
|
51
69
|
* 1. Cannot be an empty string.
|
|
52
70
|
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
53
|
-
* @param logLevel The level of logging to show in the device logcat stream
|
|
54
|
-
* @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
|
|
55
|
-
* @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
|
|
56
|
-
* @param allowedDomains The whitelisted domains to allow Clarity to capture their DOM content.
|
|
71
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
72
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
73
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
74
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
57
75
|
* If it contains "*" as an element, all domains will be captured.
|
|
76
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
58
77
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
userId?: string
|
|
62
|
-
logLevel
|
|
63
|
-
allowMeteredNetworkUsage
|
|
64
|
-
enableWebViewCapture
|
|
65
|
-
allowedDomains
|
|
78
|
+
|
|
79
|
+
interface ClarityConfig {
|
|
80
|
+
userId?: string | null;
|
|
81
|
+
logLevel?: LogLevel;
|
|
82
|
+
allowMeteredNetworkUsage?: boolean;
|
|
83
|
+
enableWebViewCapture?: boolean;
|
|
84
|
+
allowedDomains?: string[];
|
|
85
|
+
disableOnLowEndDevices?: Boolean;
|
|
86
|
+
}
|
|
66
87
|
```
|
|
67
88
|
|
|
68
89
|
## License
|
package/android/build.gradle
CHANGED
|
@@ -69,7 +69,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
69
69
|
dependencies {
|
|
70
70
|
implementation "com.facebook.react:react-native:+"
|
|
71
71
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
72
|
-
implementation "com.microsoft.clarity:clarity:
|
|
72
|
+
implementation "com.microsoft.clarity:clarity:2.0.0"
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (isNewArchitectureEnabled()) {
|
|
@@ -21,8 +21,11 @@ class ClarityModule(reactContext: ReactApplicationContext) :
|
|
|
21
21
|
allowMeteredNetworkUsage: Boolean,
|
|
22
22
|
enableWebViewCapture: Boolean,
|
|
23
23
|
allowedDomains: ReadableArray,
|
|
24
|
+
disableOnLowEndDevices: Boolean,
|
|
24
25
|
promise: Promise
|
|
25
26
|
) {
|
|
27
|
+
val allowedActivities = listOf<String>(); //not supported
|
|
28
|
+
val disallowedActivities = listOf<String>(); //not supported
|
|
26
29
|
val config = ClarityConfig(
|
|
27
30
|
projectId,
|
|
28
31
|
userId,
|
|
@@ -30,7 +33,10 @@ class ClarityModule(reactContext: ReactApplicationContext) :
|
|
|
30
33
|
allowMeteredNetworkUsage,
|
|
31
34
|
enableWebViewCapture,
|
|
32
35
|
readableArrayToList(allowedDomains),
|
|
33
|
-
ApplicationFramework.ReactNative
|
|
36
|
+
ApplicationFramework.ReactNative,
|
|
37
|
+
allowedActivities,
|
|
38
|
+
disallowedActivities,
|
|
39
|
+
disableOnLowEndDevices
|
|
34
40
|
)
|
|
35
41
|
|
|
36
42
|
promise.resolve(Clarity.initialize(currentActivity, config))
|
|
@@ -41,11 +47,21 @@ class ClarityModule(reactContext: ReactApplicationContext) :
|
|
|
41
47
|
promise.resolve(Clarity.setCustomUserId(customUserId))
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
@ReactMethod
|
|
51
|
+
fun setCustomSessionId(customSessionId: String, promise: Promise) {
|
|
52
|
+
promise.resolve(Clarity.setCustomSessionId(customSessionId))
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
@ReactMethod
|
|
45
56
|
fun getCurrentSessionId(promise: Promise) {
|
|
46
57
|
promise.resolve(Clarity.getCurrentSessionId())
|
|
47
58
|
}
|
|
48
59
|
|
|
60
|
+
@ReactMethod
|
|
61
|
+
fun setCustomTag(key: String?, value: String?, promise: Promise) {
|
|
62
|
+
promise.resolve(Clarity.setCustomTag(key, value))
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
@ReactMethod
|
|
50
66
|
fun setCurrentScreenName(screenName: String?, promise: Promise) {
|
|
51
67
|
promise.resolve(Clarity.setCurrentScreenName(screenName))
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.LogLevel = void 0;
|
|
6
7
|
exports.getCurrentSessionId = getCurrentSessionId;
|
|
7
8
|
exports.initialize = initialize;
|
|
8
9
|
exports.setCurrentScreenName = setCurrentScreenName;
|
|
10
|
+
exports.setCustomSessionId = setCustomSessionId;
|
|
11
|
+
exports.setCustomTag = setCustomTag;
|
|
9
12
|
exports.setCustomUserId = setCustomUserId;
|
|
10
13
|
var _reactNative = require("react-native");
|
|
11
14
|
const LINKING_ERROR = `The package 'react-native-clarity' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -15,25 +18,52 @@ const Clarity = _reactNative.NativeModules.Clarity;
|
|
|
15
18
|
const SupportedPlatforms = ['android'];
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
21
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
19
22
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param userId A custom identifier for the current user. If passed as undefined, the user id
|
|
23
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
22
24
|
* will be auto generated. The user id in general is sticky across sessions.
|
|
23
25
|
* The provided user id must follow these conditions:
|
|
24
26
|
* 1. Cannot be an empty string.
|
|
25
27
|
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
26
|
-
* @param logLevel The level of logging to show in the device logcat stream
|
|
27
|
-
* @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
|
|
28
|
-
* @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
|
|
29
|
-
* @param allowedDomains The whitelisted domains to allow Clarity to capture their DOM content.
|
|
28
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
29
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
30
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
31
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
30
32
|
* If it contains "*" as an element, all domains will be captured.
|
|
33
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
31
34
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The level of logging to show in the device logcat stream.
|
|
37
|
+
*/
|
|
38
|
+
let LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
39
|
+
LogLevel["Verbose"] = "Verbose";
|
|
40
|
+
LogLevel["Debug"] = "Debug";
|
|
41
|
+
LogLevel["Info"] = "Info";
|
|
42
|
+
LogLevel["Warning"] = "Warning";
|
|
43
|
+
LogLevel["Error"] = "Error";
|
|
44
|
+
LogLevel["None"] = "None";
|
|
45
|
+
return LogLevel;
|
|
46
|
+
}({});
|
|
47
|
+
/**
|
|
48
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
49
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
50
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
51
|
+
*/
|
|
52
|
+
exports.LogLevel = LogLevel;
|
|
53
|
+
function initialize(projectId, config) {
|
|
54
|
+
if (typeof projectId !== "string" || !(typeof config === "object" || typeof config === "undefined")) {
|
|
55
|
+
throw Error("Invalid Clarity initialization arguments. Please check the docs for assitance.");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// applying default values
|
|
59
|
+
let {
|
|
60
|
+
userId = null,
|
|
61
|
+
logLevel = LogLevel.None,
|
|
62
|
+
allowMeteredNetworkUsage = false,
|
|
63
|
+
enableWebViewCapture = true,
|
|
64
|
+
allowedDomains = ["*"],
|
|
65
|
+
disableOnLowEndDevices = false
|
|
66
|
+
} = config ?? {};
|
|
37
67
|
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
38
68
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
39
69
|
return;
|
|
@@ -42,7 +72,7 @@ function initialize(projectId, userId) {
|
|
|
42
72
|
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
43
73
|
return;
|
|
44
74
|
}
|
|
45
|
-
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains);
|
|
75
|
+
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices);
|
|
46
76
|
}
|
|
47
77
|
|
|
48
78
|
/**
|
|
@@ -68,25 +98,48 @@ function setCustomUserId(customUserId) {
|
|
|
68
98
|
}
|
|
69
99
|
|
|
70
100
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
101
|
+
* Sets a custom session id that can be used to identify the session.
|
|
102
|
+
* <p>
|
|
103
|
+
* Note: custom session id cannot be null or empty, or consists only of whitespaces.
|
|
104
|
+
* </p>
|
|
105
|
+
* @param customSessionId The custom session id to set.
|
|
74
106
|
*/
|
|
75
|
-
function
|
|
107
|
+
function setCustomSessionId(customSessionId) {
|
|
76
108
|
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
77
109
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
78
|
-
return
|
|
79
|
-
resolve("Undefined");
|
|
80
|
-
});
|
|
110
|
+
return;
|
|
81
111
|
}
|
|
82
112
|
if (Clarity === null) {
|
|
83
113
|
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
84
|
-
return
|
|
85
|
-
resolve("Undefined");
|
|
86
|
-
});
|
|
114
|
+
return;
|
|
87
115
|
}
|
|
88
|
-
|
|
116
|
+
Clarity.setCustomSessionId(customSessionId);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Sets a custom tag for the current session.
|
|
121
|
+
* @param key The tag key to set.
|
|
122
|
+
* @param value The tag value to set.
|
|
123
|
+
*/
|
|
124
|
+
function setCustomTag(key, value) {
|
|
125
|
+
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
126
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (Clarity === null) {
|
|
130
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
Clarity.setCustomTag(key, value);
|
|
89
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* For React Native applications only, this function is used to set the current screen name
|
|
138
|
+
* in case the ReactNative Navigation package is used.
|
|
139
|
+
* This will allow you to split and analyze your data on the screen names.
|
|
140
|
+
* You can it set to `null` to remove the latest set value.
|
|
141
|
+
* @param screenName The current screen name to set.
|
|
142
|
+
*/
|
|
90
143
|
function setCurrentScreenName(screenName) {
|
|
91
144
|
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
92
145
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
@@ -98,4 +151,25 @@ function setCurrentScreenName(screenName) {
|
|
|
98
151
|
}
|
|
99
152
|
Clarity.setCurrentScreenName(screenName);
|
|
100
153
|
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns the active session id. This can be used to correlate the Clarity session with other
|
|
157
|
+
* analytics tools that the developer may be using.
|
|
158
|
+
* @returns a promise that resolves to the current session id.
|
|
159
|
+
*/
|
|
160
|
+
function getCurrentSessionId() {
|
|
161
|
+
if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
|
|
162
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
163
|
+
return new Promise(resolve => {
|
|
164
|
+
resolve("Undefined");
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (Clarity === null) {
|
|
168
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
169
|
+
return new Promise(resolve => {
|
|
170
|
+
resolve("Undefined");
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return Clarity.getCurrentSessionId();
|
|
174
|
+
}
|
|
101
175
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Clarity","NativeModules","SupportedPlatforms","initialize","projectId","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Clarity","NativeModules","SupportedPlatforms","LogLevel","exports","initialize","projectId","config","Error","userId","logLevel","None","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","disableOnLowEndDevices","includes","Platform","OS","console","warn","join","error","setCustomUserId","customUserId","setCustomSessionId","customSessionId","setCustomTag","key","value","setCurrentScreenName","screenName","getCurrentSessionId","Promise","resolve"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,+EAA8E;AAC/E;AACA,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,OAAO,GAAGC,0BAAa,CAACD,OAAO;AAErC,MAAME,kBAAkB,GAAG,CAAC,SAAS,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUA;AACA;AACA;AAFA,IAGYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AASpB;AACA;AACA;AACA;AACA;AAJAC,OAAA,CAAAD,QAAA,GAAAA,QAAA;AAKO,SAASE,UAAUA,CAACC,SAAiB,EAAEC,MAAsB,EAAE;EAEpE,IAAI,OAAOD,SAAS,KAAK,QAAQ,IAAI,EAAE,OAAOC,MAAM,KAAK,QAAQ,IAAI,OAAOA,MAAM,KAAK,WAAW,CAAC,EAAE;IACnG,MAAMC,KAAK,CAAC,gFAAgF,CAAC;EAC/F;;EAEA;EACA,IAAI;IAAEC,MAAM,GAAG,IAAI;IACjBC,QAAQ,GAAGP,QAAQ,CAACQ,IAAI;IACxBC,wBAAwB,GAAG,KAAK;IAChCC,oBAAoB,GAAG,IAAI;IAC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AAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGlB,kBAAkB,CAACmB,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF,OAAO,IAAIY,OAAO,CAAEC,OAAO,IAAK;MAC9BA,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC;EACJ;EAEA,IAAIlC,OAAO,KAAK,IAAI,EAAE;IACpBmB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEvB,aAAa,CAAC;IACpE,OAAO,IAAIkC,OAAO,CAAEC,OAAO,IAAK;MAC9BA,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC;EACJ;EAEA,OAAOlC,OAAO,CAACgC,mBAAmB,CAAC,CAAC;AACtC"}
|
package/lib/module/index.js
CHANGED
|
@@ -6,25 +6,53 @@ const Clarity = NativeModules.Clarity;
|
|
|
6
6
|
const SupportedPlatforms = ['android'];
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param userId A custom identifier for the current user. If passed as undefined, the user id
|
|
11
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
13
12
|
* will be auto generated. The user id in general is sticky across sessions.
|
|
14
13
|
* The provided user id must follow these conditions:
|
|
15
14
|
* 1. Cannot be an empty string.
|
|
16
15
|
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
17
|
-
* @param logLevel The level of logging to show in the device logcat stream
|
|
18
|
-
* @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
|
|
19
|
-
* @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
|
|
20
|
-
* @param allowedDomains The whitelisted domains to allow Clarity to capture their DOM content.
|
|
16
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
17
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
18
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
19
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
21
20
|
* If it contains "*" as an element, all domains will be captured.
|
|
21
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The level of logging to show in the device logcat stream.
|
|
26
|
+
*/
|
|
27
|
+
export let LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
28
|
+
LogLevel["Verbose"] = "Verbose";
|
|
29
|
+
LogLevel["Debug"] = "Debug";
|
|
30
|
+
LogLevel["Info"] = "Info";
|
|
31
|
+
LogLevel["Warning"] = "Warning";
|
|
32
|
+
LogLevel["Error"] = "Error";
|
|
33
|
+
LogLevel["None"] = "None";
|
|
34
|
+
return LogLevel;
|
|
35
|
+
}({});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
39
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
40
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
41
|
+
*/
|
|
42
|
+
export function initialize(projectId, config) {
|
|
43
|
+
if (typeof projectId !== "string" || !(typeof config === "object" || typeof config === "undefined")) {
|
|
44
|
+
throw Error("Invalid Clarity initialization arguments. Please check the docs for assitance.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// applying default values
|
|
48
|
+
let {
|
|
49
|
+
userId = null,
|
|
50
|
+
logLevel = LogLevel.None,
|
|
51
|
+
allowMeteredNetworkUsage = false,
|
|
52
|
+
enableWebViewCapture = true,
|
|
53
|
+
allowedDomains = ["*"],
|
|
54
|
+
disableOnLowEndDevices = false
|
|
55
|
+
} = config ?? {};
|
|
28
56
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
29
57
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
30
58
|
return;
|
|
@@ -33,7 +61,7 @@ export function initialize(projectId, userId) {
|
|
|
33
61
|
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
34
62
|
return;
|
|
35
63
|
}
|
|
36
|
-
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains);
|
|
64
|
+
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices);
|
|
37
65
|
}
|
|
38
66
|
|
|
39
67
|
/**
|
|
@@ -59,25 +87,48 @@ export function setCustomUserId(customUserId) {
|
|
|
59
87
|
}
|
|
60
88
|
|
|
61
89
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
90
|
+
* Sets a custom session id that can be used to identify the session.
|
|
91
|
+
* <p>
|
|
92
|
+
* Note: custom session id cannot be null or empty, or consists only of whitespaces.
|
|
93
|
+
* </p>
|
|
94
|
+
* @param customSessionId The custom session id to set.
|
|
65
95
|
*/
|
|
66
|
-
export function
|
|
96
|
+
export function setCustomSessionId(customSessionId) {
|
|
67
97
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
68
98
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
69
|
-
return
|
|
70
|
-
resolve("Undefined");
|
|
71
|
-
});
|
|
99
|
+
return;
|
|
72
100
|
}
|
|
73
101
|
if (Clarity === null) {
|
|
74
102
|
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
75
|
-
return
|
|
76
|
-
resolve("Undefined");
|
|
77
|
-
});
|
|
103
|
+
return;
|
|
78
104
|
}
|
|
79
|
-
|
|
105
|
+
Clarity.setCustomSessionId(customSessionId);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sets a custom tag for the current session.
|
|
110
|
+
* @param key The tag key to set.
|
|
111
|
+
* @param value The tag value to set.
|
|
112
|
+
*/
|
|
113
|
+
export function setCustomTag(key, value) {
|
|
114
|
+
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
115
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (Clarity === null) {
|
|
119
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
Clarity.setCustomTag(key, value);
|
|
80
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* For React Native applications only, this function is used to set the current screen name
|
|
127
|
+
* in case the ReactNative Navigation package is used.
|
|
128
|
+
* This will allow you to split and analyze your data on the screen names.
|
|
129
|
+
* You can it set to `null` to remove the latest set value.
|
|
130
|
+
* @param screenName The current screen name to set.
|
|
131
|
+
*/
|
|
81
132
|
export function setCurrentScreenName(screenName) {
|
|
82
133
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
83
134
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
@@ -89,4 +140,25 @@ export function setCurrentScreenName(screenName) {
|
|
|
89
140
|
}
|
|
90
141
|
Clarity.setCurrentScreenName(screenName);
|
|
91
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns the active session id. This can be used to correlate the Clarity session with other
|
|
146
|
+
* analytics tools that the developer may be using.
|
|
147
|
+
* @returns a promise that resolves to the current session id.
|
|
148
|
+
*/
|
|
149
|
+
export function getCurrentSessionId() {
|
|
150
|
+
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
151
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
152
|
+
return new Promise(resolve => {
|
|
153
|
+
resolve("Undefined");
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (Clarity === null) {
|
|
157
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
158
|
+
return new Promise(resolve => {
|
|
159
|
+
resolve("Undefined");
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return Clarity.getCurrentSessionId();
|
|
163
|
+
}
|
|
92
164
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","Clarity","SupportedPlatforms","initialize","projectId","
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","Clarity","SupportedPlatforms","LogLevel","initialize","projectId","config","Error","userId","logLevel","None","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","disableOnLowEndDevices","includes","OS","console","warn","join","error","setCustomUserId","customUserId","setCustomSessionId","customSessionId","setCustomTag","key","value","setCurrentScreenName","screenName","getCurrentSessionId","Promise","resolve"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GAChB,+EAA8E;AAC/E;AACA,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,OAAO,GAAGH,aAAa,CAACG,OAAO;AAErC,MAAMC,kBAAkB,GAAG,CAAC,SAAS,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA,WAAYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;;AASpB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,SAAiB,EAAEC,MAAsB,EAAE;EAEpE,IAAI,OAAOD,SAAS,KAAK,QAAQ,IAAI,EAA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IAAIlB,OAAO,KAAK,IAAI,EAAE;IACpBgB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEpB,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAAC2B,oBAAoB,CAACC,UAAU,CAAC;AAC1C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAA,EAAoB;EACrD,IAAI,CAAC5B,kBAAkB,CAACa,QAAQ,CAAChB,QAAQ,CAACiB,EAAE,CAAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGhB,kBAAkB,CAACiB,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF,OAAO,IAAIY,OAAO,CAAEC,OAAO,IAAK;MAC9BA,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC;EACJ;EAEA,IAAI/B,OAAO,KAAK,IAAI,EAAE;IACpBgB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEpB,aAAa,CAAC;IACpE,OAAO,IAAI+B,OAAO,CAAEC,OAAO,IAAK;MAC9BA,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC;EACJ;EAEA,OAAO/B,OAAO,CAAC6B,mBAAmB,CAAC,CAAC;AACtC"}
|
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param userId A custom identifier for the current user. If passed as undefined, the user id
|
|
4
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
6
5
|
* will be auto generated. The user id in general is sticky across sessions.
|
|
7
6
|
* The provided user id must follow these conditions:
|
|
8
7
|
* 1. Cannot be an empty string.
|
|
9
8
|
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
10
|
-
* @param logLevel The level of logging to show in the device logcat stream
|
|
11
|
-
* @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
|
|
12
|
-
* @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
|
|
13
|
-
* @param allowedDomains The whitelisted domains to allow Clarity to capture their DOM content.
|
|
9
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
10
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
11
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
12
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
14
13
|
* If it contains "*" as an element, all domains will be captured.
|
|
14
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export interface ClarityConfig {
|
|
17
|
+
userId?: string | null;
|
|
18
|
+
logLevel?: LogLevel;
|
|
19
|
+
allowMeteredNetworkUsage?: boolean;
|
|
20
|
+
enableWebViewCapture?: boolean;
|
|
21
|
+
allowedDomains?: string[];
|
|
22
|
+
disableOnLowEndDevices?: Boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The level of logging to show in the device logcat stream.
|
|
26
|
+
*/
|
|
27
|
+
export declare enum LogLevel {
|
|
28
|
+
Verbose = "Verbose",
|
|
29
|
+
Debug = "Debug",
|
|
30
|
+
Info = "Info",
|
|
31
|
+
Warning = "Warning",
|
|
32
|
+
Error = "Error",
|
|
33
|
+
None = "None"
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
37
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
38
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
39
|
+
*/
|
|
40
|
+
export declare function initialize(projectId: string, config?: ClarityConfig): void;
|
|
17
41
|
/**
|
|
18
42
|
* Sets a custom user id that can be used to identify the user. It has less
|
|
19
43
|
* restrictions than the userId parameter. You can pass any string and
|
|
@@ -25,11 +49,32 @@ export declare function initialize(projectId: string, userId?: string, logLevel?
|
|
|
25
49
|
* @param customUserId The custom user id to set.
|
|
26
50
|
*/
|
|
27
51
|
export declare function setCustomUserId(customUserId: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Sets a custom session id that can be used to identify the session.
|
|
54
|
+
* <p>
|
|
55
|
+
* Note: custom session id cannot be null or empty, or consists only of whitespaces.
|
|
56
|
+
* </p>
|
|
57
|
+
* @param customSessionId The custom session id to set.
|
|
58
|
+
*/
|
|
59
|
+
export declare function setCustomSessionId(customSessionId: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Sets a custom tag for the current session.
|
|
62
|
+
* @param key The tag key to set.
|
|
63
|
+
* @param value The tag value to set.
|
|
64
|
+
*/
|
|
65
|
+
export declare function setCustomTag(key: string, value: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* For React Native applications only, this function is used to set the current screen name
|
|
68
|
+
* in case the ReactNative Navigation package is used.
|
|
69
|
+
* This will allow you to split and analyze your data on the screen names.
|
|
70
|
+
* You can it set to `null` to remove the latest set value.
|
|
71
|
+
* @param screenName The current screen name to set.
|
|
72
|
+
*/
|
|
73
|
+
export declare function setCurrentScreenName(screenName: string): void;
|
|
28
74
|
/**
|
|
29
75
|
* Returns the active session id. This can be used to correlate the Clarity session with other
|
|
30
76
|
* analytics tools that the developer may be using.
|
|
31
77
|
* @returns a promise that resolves to the current session id.
|
|
32
78
|
*/
|
|
33
79
|
export declare function getCurrentSessionId(): Promise<string>;
|
|
34
|
-
export declare function setCurrentScreenName(screenName: string): void;
|
|
35
80
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;GAEG;AACH,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED;;;;EAIE;AACF,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,QAyBnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,QAYnD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,QAYzD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAYtD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,QAYtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAgBrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-clarity",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A plugin to provide the Clarity experience for the React Native applications.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"release": "release-it",
|
|
35
35
|
"example": "yarn --cwd example",
|
|
36
36
|
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
37
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
|
|
37
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build *.tgz"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"react-native",
|
package/src/index.tsx
CHANGED
|
@@ -11,27 +11,60 @@ const Clarity = NativeModules.Clarity;
|
|
|
11
11
|
const SupportedPlatforms = ['android']
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The configuration that will be used to customize the Clarity behaviour.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param userId A custom identifier for the current user. If passed as undefined, the user id
|
|
16
|
+
* @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
|
|
18
17
|
* will be auto generated. The user id in general is sticky across sessions.
|
|
19
18
|
* The provided user id must follow these conditions:
|
|
20
19
|
* 1. Cannot be an empty string.
|
|
21
20
|
* 2. Should be base36 and smaller than "1Z141Z4".
|
|
22
|
-
* @param logLevel The level of logging to show in the device logcat stream
|
|
23
|
-
* @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
|
|
24
|
-
* @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
|
|
25
|
-
* @param allowedDomains The whitelisted domains to allow Clarity to capture their DOM content.
|
|
21
|
+
* @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
|
|
22
|
+
* @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
|
|
23
|
+
* @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
|
|
24
|
+
* @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
|
|
26
25
|
* If it contains "*" as an element, all domains will be captured.
|
|
26
|
+
* @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
export interface ClarityConfig {
|
|
29
|
+
userId?: string | null;
|
|
30
|
+
logLevel?: LogLevel;
|
|
31
|
+
allowMeteredNetworkUsage?: boolean;
|
|
32
|
+
enableWebViewCapture?: boolean;
|
|
33
|
+
allowedDomains?: string[];
|
|
34
|
+
disableOnLowEndDevices?: Boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The level of logging to show in the device logcat stream.
|
|
39
|
+
*/
|
|
40
|
+
export enum LogLevel {
|
|
41
|
+
Verbose = "Verbose",
|
|
42
|
+
Debug = "Debug",
|
|
43
|
+
Info = "Info",
|
|
44
|
+
Warning = "Warning",
|
|
45
|
+
Error = "Error",
|
|
46
|
+
None = "None"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Initializes the Clarity SDK if the API level is supported.
|
|
51
|
+
* @param projectId [REQUIRED] The Clarity project id to send data to.
|
|
52
|
+
* @param config [OPTIONAL] The clarity config, if not provided default values are used.
|
|
53
|
+
*/
|
|
54
|
+
export function initialize(projectId: string, config?: ClarityConfig) {
|
|
55
|
+
|
|
56
|
+
if (typeof projectId !== "string" || !(typeof config === "object" || typeof config === "undefined")) {
|
|
57
|
+
throw Error("Invalid Clarity initialization arguments. Please check the docs for assitance.")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// applying default values
|
|
61
|
+
let { userId = null,
|
|
62
|
+
logLevel = LogLevel.None,
|
|
63
|
+
allowMeteredNetworkUsage = false,
|
|
64
|
+
enableWebViewCapture = true,
|
|
65
|
+
allowedDomains = ["*"],
|
|
66
|
+
disableOnLowEndDevices = false } = config ?? {};
|
|
67
|
+
|
|
35
68
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
36
69
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
37
70
|
return;
|
|
@@ -42,7 +75,7 @@ export function initialize(
|
|
|
42
75
|
return;
|
|
43
76
|
}
|
|
44
77
|
|
|
45
|
-
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains);
|
|
78
|
+
Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices);
|
|
46
79
|
}
|
|
47
80
|
|
|
48
81
|
/**
|
|
@@ -70,28 +103,52 @@ export function setCustomUserId(customUserId: string) {
|
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
106
|
+
* Sets a custom session id that can be used to identify the session.
|
|
107
|
+
* <p>
|
|
108
|
+
* Note: custom session id cannot be null or empty, or consists only of whitespaces.
|
|
109
|
+
* </p>
|
|
110
|
+
* @param customSessionId The custom session id to set.
|
|
76
111
|
*/
|
|
77
|
-
export function
|
|
112
|
+
export function setCustomSessionId(customSessionId: string) {
|
|
78
113
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
79
114
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (Clarity === null) {
|
|
119
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Clarity.setCustomSessionId(customSessionId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets a custom tag for the current session.
|
|
128
|
+
* @param key The tag key to set.
|
|
129
|
+
* @param value The tag value to set.
|
|
130
|
+
*/
|
|
131
|
+
export function setCustomTag(key: string, value: string) {
|
|
132
|
+
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
133
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
134
|
+
return;
|
|
83
135
|
}
|
|
84
136
|
|
|
85
137
|
if (Clarity === null) {
|
|
86
138
|
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
87
|
-
return
|
|
88
|
-
resolve("Undefined");
|
|
89
|
-
});
|
|
139
|
+
return;
|
|
90
140
|
}
|
|
91
141
|
|
|
92
|
-
|
|
142
|
+
Clarity.setCustomTag(key, value);
|
|
93
143
|
}
|
|
94
144
|
|
|
145
|
+
/**
|
|
146
|
+
* For React Native applications only, this function is used to set the current screen name
|
|
147
|
+
* in case the ReactNative Navigation package is used.
|
|
148
|
+
* This will allow you to split and analyze your data on the screen names.
|
|
149
|
+
* You can it set to `null` to remove the latest set value.
|
|
150
|
+
* @param screenName The current screen name to set.
|
|
151
|
+
*/
|
|
95
152
|
export function setCurrentScreenName(screenName: string) {
|
|
96
153
|
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
97
154
|
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
@@ -105,3 +162,26 @@ export function setCurrentScreenName(screenName: string) {
|
|
|
105
162
|
|
|
106
163
|
Clarity.setCurrentScreenName(screenName);
|
|
107
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Returns the active session id. This can be used to correlate the Clarity session with other
|
|
168
|
+
* analytics tools that the developer may be using.
|
|
169
|
+
* @returns a promise that resolves to the current session id.
|
|
170
|
+
*/
|
|
171
|
+
export function getCurrentSessionId(): Promise<string> {
|
|
172
|
+
if (!SupportedPlatforms.includes(Platform.OS)) {
|
|
173
|
+
console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
|
|
174
|
+
return new Promise((resolve) => {
|
|
175
|
+
resolve("Undefined");
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (Clarity === null) {
|
|
180
|
+
console.error("Clarity did not initialize properly.", LINKING_ERROR);
|
|
181
|
+
return new Promise((resolve) => {
|
|
182
|
+
resolve("Undefined");
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return Clarity.getCurrentSessionId();
|
|
187
|
+
}
|