react-native-clarity 1.0.1 → 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 CHANGED
@@ -11,20 +11,25 @@ npm install react-native-clarity
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- import { initialize, setCustomUserId, getCurrentSessionId, setCurrentScreenName, setCustomTag } from 'react-native-clarity';
14
+ import {LogLevel, initialize, setCustomUserId, setCustomSessionId, setCustomTag, setCurrentScreenName, getCurrentSessionId } from 'react-native-clarity';
15
15
 
16
16
  // Initialize Clarity.
17
- initialize("<ProjectId>");
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("react@native.com");
25
+ setCustomUserId("<CustomUserId>");
26
+
27
+ // Set custom session id.
28
+ setCustomSessionId("<CustomSessionId>");
21
29
 
22
30
  // Set custom tag.
23
31
  setCustomTag("key", "value");
24
32
 
25
- // Get current session id to correlate with other tools.
26
- getCurrentSessionId().then((id) => {...});
27
-
28
33
  // Setting the current screen name when using React Navigation
29
34
  import { ..., useFocusEffect } from '@react-navigation/native';
30
35
 
@@ -39,33 +44,46 @@ const HomeScreen = ({...}) => {
39
44
  );
40
45
  ...
41
46
  };
47
+
48
+ // Get current session id to correlate with other tools.
49
+ getCurrentSessionId().then((id) => {...});
42
50
  ```
43
51
 
44
52
  ### Initialization arguments
45
53
 
46
- ```js
54
+ ```ts
47
55
  /**
48
- * Initializes the Clarity plugin with the provided parameters.
49
- *
50
- * @param projectId The Clarity project id to send data to.
51
- * @param userId A custom identifier for the current user. If passed as undefined, the user id
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
52
67
  * will be auto generated. The user id in general is sticky across sessions.
53
68
  * The provided user id must follow these conditions:
54
69
  * 1. Cannot be an empty string.
55
70
  * 2. Should be base36 and smaller than "1Z141Z4".
56
- * @param logLevel The level of logging to show in the device logcat stream ("Verbose", "Debug", "Info", "Warning", "Error", "None").
57
- * @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
58
- * @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
59
- * @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.
60
75
  * If it contains "*" as an element, all domains will be captured.
76
+ * @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
61
77
  */
62
- function initialize(
63
- projectId: string,
64
- userId?: string,
65
- logLevel: string = "None",
66
- allowMeteredNetworkUsage: boolean = false,
67
- enableWebViewCapture: boolean = true,
68
- allowedDomains: string[] = ["*"])
78
+
79
+ interface ClarityConfig {
80
+ userId?: string | null;
81
+ logLevel?: LogLevel;
82
+ allowMeteredNetworkUsage?: boolean;
83
+ enableWebViewCapture?: boolean;
84
+ allowedDomains?: string[];
85
+ disableOnLowEndDevices?: Boolean;
86
+ }
69
87
  ```
70
88
 
71
89
  ## License
@@ -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:1.3.3"
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))
@@ -42,13 +48,13 @@ class ClarityModule(reactContext: ReactApplicationContext) :
42
48
  }
43
49
 
44
50
  @ReactMethod
45
- fun getCurrentSessionId(promise: Promise) {
46
- promise.resolve(Clarity.getCurrentSessionId())
51
+ fun setCustomSessionId(customSessionId: String, promise: Promise) {
52
+ promise.resolve(Clarity.setCustomSessionId(customSessionId))
47
53
  }
48
54
 
49
55
  @ReactMethod
50
- fun setCurrentScreenName(screenName: String?, promise: Promise) {
51
- promise.resolve(Clarity.setCurrentScreenName(screenName))
56
+ fun getCurrentSessionId(promise: Promise) {
57
+ promise.resolve(Clarity.getCurrentSessionId())
52
58
  }
53
59
 
54
60
  @ReactMethod
@@ -56,6 +62,11 @@ class ClarityModule(reactContext: ReactApplicationContext) :
56
62
  promise.resolve(Clarity.setCustomTag(key, value))
57
63
  }
58
64
 
65
+ @ReactMethod
66
+ fun setCurrentScreenName(screenName: String?, promise: Promise) {
67
+ promise.resolve(Clarity.setCurrentScreenName(screenName))
68
+ }
69
+
59
70
  private fun readableArrayToList(arr: ReadableArray): List<String> {
60
71
  val ret = mutableListOf<String>()
61
72
 
@@ -3,9 +3,11 @@
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;
9
11
  exports.setCustomTag = setCustomTag;
10
12
  exports.setCustomUserId = setCustomUserId;
11
13
  var _reactNative = require("react-native");
@@ -16,25 +18,52 @@ const Clarity = _reactNative.NativeModules.Clarity;
16
18
  const SupportedPlatforms = ['android'];
17
19
 
18
20
  /**
19
- * Initializes the Clarity plugin with the provided parameters.
21
+ * The configuration that will be used to customize the Clarity behaviour.
20
22
  *
21
- * @param projectId The Clarity project id to send data to.
22
- * @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
23
24
  * will be auto generated. The user id in general is sticky across sessions.
24
25
  * The provided user id must follow these conditions:
25
26
  * 1. Cannot be an empty string.
26
27
  * 2. Should be base36 and smaller than "1Z141Z4".
27
- * @param logLevel The level of logging to show in the device logcat stream ("Verbose", "Debug", "Info", "Warning", "Error", "None").
28
- * @param allowMeteredNetworkUsage Allows uploading session data to the servers on device metered network.
29
- * @param enableWebViewCapture Allows Clarity to capture the web views DOM content.
30
- * @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.
31
32
  * If it contains "*" as an element, all domains will be captured.
33
+ * @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
32
34
  */
33
- function initialize(projectId, userId) {
34
- let logLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "None";
35
- let allowMeteredNetworkUsage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
36
- let enableWebViewCapture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
37
- let allowedDomains = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ["*"];
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 ?? {};
38
67
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
39
68
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
40
69
  return;
@@ -43,7 +72,7 @@ function initialize(projectId, userId) {
43
72
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
44
73
  return;
45
74
  }
46
- Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains);
75
+ Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices);
47
76
  }
48
77
 
49
78
  /**
@@ -69,26 +98,30 @@ function setCustomUserId(customUserId) {
69
98
  }
70
99
 
71
100
  /**
72
- * Returns the active session id. This can be used to correlate the Clarity session with other
73
- * analytics tools that the developer may be using.
74
- * @returns a promise that resolves to the current session id.
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.
75
106
  */
76
- function getCurrentSessionId() {
107
+ function setCustomSessionId(customSessionId) {
77
108
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
78
109
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
79
- return new Promise(resolve => {
80
- resolve("Undefined");
81
- });
110
+ return;
82
111
  }
83
112
  if (Clarity === null) {
84
113
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
85
- return new Promise(resolve => {
86
- resolve("Undefined");
87
- });
114
+ return;
88
115
  }
89
- return Clarity.getCurrentSessionId();
116
+ Clarity.setCustomSessionId(customSessionId);
90
117
  }
91
- function setCurrentScreenName(screenName) {
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) {
92
125
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
93
126
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
94
127
  return;
@@ -97,9 +130,17 @@ function setCurrentScreenName(screenName) {
97
130
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
98
131
  return;
99
132
  }
100
- Clarity.setCurrentScreenName(screenName);
133
+ Clarity.setCustomTag(key, value);
101
134
  }
102
- function setCustomTag(key, value) {
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
+ */
143
+ function setCurrentScreenName(screenName) {
103
144
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
104
145
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
105
146
  return;
@@ -108,6 +149,27 @@ function setCustomTag(key, value) {
108
149
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
109
150
  return;
110
151
  }
111
- Clarity.setCustomTag(key, value);
152
+ Clarity.setCurrentScreenName(screenName);
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();
112
174
  }
113
175
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Clarity","NativeModules","SupportedPlatforms","initialize","projectId","userId","logLevel","arguments","length","undefined","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","includes","Platform","OS","console","warn","join","error","setCustomUserId","customUserId","getCurrentSessionId","Promise","resolve","setCurrentScreenName","screenName","setCustomTag","key","value"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,+EAA8E;AAC/E;AACA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,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAACyB,oBAAoB,CAACC,UAAU,CAAC;AAC1C;AAEO,SAASC,YAAYA,CAACC,GAAW,EAAEC,KAAa,EAAE;EACvD,IAAI,CAAC3B,kBAAkB,CAACW,QAAQ,CAACC,qBAAQ,CAACC,EAAE,CAAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGf,kBAAkB,CAACgB,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF;EACF;EAEA,IAAIlB,OAAO,KAAK,IAAI,EAAE;IACpBgB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEpB,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAAC2B,YAAY,CAACC,GAAG,EAAEC,KAAK,CAAC;AAClC"}
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,OAAR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AAQ,CAACC,EAAE,CAAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGlB,kBAAkB,CAACmB,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF;EACF;EAEA,IAAIrB,OAAO,KAAK,IAAI,EAAE;IACpBmB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEvB,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAAC8B,oBAAoB,CAACC,UAAU,CAAC;AAC1C;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,mBAAmBA,CAAA,EAAoB;EACrD,IAAI,CAAC9B,kBAAkB,CAACc,QAAQ,CAACC,qBAAQ,CAACC,EAAE,CAAC,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"}
@@ -6,25 +6,53 @@ const Clarity = NativeModules.Clarity;
6
6
  const SupportedPlatforms = ['android'];
7
7
 
8
8
  /**
9
- * Initializes the Clarity plugin with the provided parameters.
9
+ * The configuration that will be used to customize the Clarity behaviour.
10
10
  *
11
- * @param projectId The Clarity project id to send data to.
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 ("Verbose", "Debug", "Info", "Warning", "Error", "None").
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
- export function initialize(projectId, userId) {
24
- let logLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "None";
25
- let allowMeteredNetworkUsage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
26
- let enableWebViewCapture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
27
- let allowedDomains = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ["*"];
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,26 +87,30 @@ export function setCustomUserId(customUserId) {
59
87
  }
60
88
 
61
89
  /**
62
- * Returns the active session id. This can be used to correlate the Clarity session with other
63
- * analytics tools that the developer may be using.
64
- * @returns a promise that resolves to the current session id.
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 getCurrentSessionId() {
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 new Promise(resolve => {
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 new Promise(resolve => {
76
- resolve("Undefined");
77
- });
103
+ return;
78
104
  }
79
- return Clarity.getCurrentSessionId();
105
+ Clarity.setCustomSessionId(customSessionId);
80
106
  }
81
- export function setCurrentScreenName(screenName) {
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) {
82
114
  if (!SupportedPlatforms.includes(Platform.OS)) {
83
115
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
84
116
  return;
@@ -87,9 +119,17 @@ export function setCurrentScreenName(screenName) {
87
119
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
88
120
  return;
89
121
  }
90
- Clarity.setCurrentScreenName(screenName);
122
+ Clarity.setCustomTag(key, value);
91
123
  }
92
- export function setCustomTag(key, value) {
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
+ */
132
+ export function setCurrentScreenName(screenName) {
93
133
  if (!SupportedPlatforms.includes(Platform.OS)) {
94
134
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
95
135
  return;
@@ -98,6 +138,27 @@ export function setCustomTag(key, value) {
98
138
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
99
139
  return;
100
140
  }
101
- Clarity.setCustomTag(key, value);
141
+ Clarity.setCurrentScreenName(screenName);
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();
102
163
  }
103
164
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","Clarity","SupportedPlatforms","initialize","projectId","userId","logLevel","arguments","length","undefined","allowMeteredNetworkUsage","enableWebViewCapture","allowedDomains","includes","OS","console","warn","join","error","setCustomUserId","customUserId","getCurrentSessionId","Promise","resolve","setCurrentScreenName","screenName","setCustomTag","key","value"],"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;AACA,OAAO,SAASC,UAAUA,CACxBC,SAAiB,EACjBC,MAAe,EAImB;EAAA,IAHlCC,QAAgB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,MAAM;EAAA,IACzBG,wBAAiC,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAAA,IACzCI,oBAA6B,GAAAJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAAA,IACpCK,cAAwB,GAAAL,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,GAAG,CAAC;EAChC,IAAI,CAACL,kBAAkB,CAACW,QAAQ,CAACd,QAAQ,CAACe,EAAE,CAAC,EAAE;IAC7CC,OAAO,CA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E,OAAO,IAAIsB,OAAO,CAAEC,OAAO,IAAK;MAC9BA,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC;EACJ;EAEA,OAAOtB,OAAO,CAACoB,mBAAmB,CAAC,CAAC;AACtC;AAEA,OAAO,SAASG,oBAAoBA,CAACC,UAAkB,EAAE;EACvD,IAAI,CAACvB,kBAAkB,CAACW,QAAQ,CAACd,QAAQ,CAACe,EAAE,CAAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGd,kBAAkB,CAACe,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF;EACF;EAEA,IAAIhB,OAAO,KAAK,IAAI,EAAE;IACpBc,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAElB,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAACuB,oBAAoB,CAACC,UAAU,CAAC;AAC1C;AAEA,OAAO,SAASC,YAAYA,CAACC,GAAW,EAAEC,KAAa,EAAE;EACvD,IAAI,CAAC1B,kBAAkB,CAACW,QAAQ,CAACd,QAAQ,CAACe,EAAE,CAAC,EAAE;IAC7CC,OAAO,CAACC,IAAI,CAAC,mBAAmB,GAAGd,kBAAkB,CAACe,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF;EACF;EAEA,IAAIhB,OAAO,KAAK,IAAI,EAAE;IACpBc,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAElB,aAAa,CAAC;IACpE;EACF;EAEAC,OAAO,CAACyB,YAAY,CAACC,GAAG,EAAEC,KAAK,CAAC;AAClC"}
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","res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AC;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
- * Initializes the Clarity plugin with the provided parameters.
2
+ * The configuration that will be used to customize the Clarity behaviour.
3
3
  *
4
- * @param projectId The Clarity project id to send data to.
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 ("Verbose", "Debug", "Info", "Warning", "Error", "None").
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 declare function initialize(projectId: string, userId?: string, logLevel?: string, allowMeteredNetworkUsage?: boolean, enableWebViewCapture?: boolean, allowedDomains?: string[]): void;
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,12 +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
- export declare function setCustomTag(key: string, value: string): void;
36
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,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,GAAE,MAAe,EACzB,wBAAwB,GAAE,OAAe,EACzC,oBAAoB,GAAE,OAAc,EACpC,cAAc,GAAE,MAAM,EAAU,QAYjC;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,QAYnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAgBrD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,QAYtD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAYtD"}
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": "1.0.1",
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
- * Initializes the Clarity plugin with the provided parameters.
14
+ * The configuration that will be used to customize the Clarity behaviour.
15
15
  *
16
- * @param projectId The Clarity project id to send data to.
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 ("Verbose", "Debug", "Info", "Warning", "Error", "None").
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 function initialize(
29
- projectId: string,
30
- userId?: string,
31
- logLevel: string = "None",
32
- allowMeteredNetworkUsage: boolean = false,
33
- enableWebViewCapture: boolean = true,
34
- allowedDomains: string[] = ["*"]) {
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
- * Returns the active session id. This can be used to correlate the Clarity session with other
74
- * analytics tools that the developer may be using.
75
- * @returns a promise that resolves to the current session id.
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 getCurrentSessionId(): Promise<string> {
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 new Promise((resolve) => {
81
- resolve("Undefined");
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 new Promise((resolve) => {
88
- resolve("Undefined");
89
- });
139
+ return;
90
140
  }
91
141
 
92
- return Clarity.getCurrentSessionId();
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.");
@@ -106,16 +163,25 @@ export function setCurrentScreenName(screenName: string) {
106
163
  Clarity.setCurrentScreenName(screenName);
107
164
  }
108
165
 
109
- export function setCustomTag(key: string, value: string) {
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> {
110
172
  if (!SupportedPlatforms.includes(Platform.OS)) {
111
173
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
112
- return;
174
+ return new Promise((resolve) => {
175
+ resolve("Undefined");
176
+ });
113
177
  }
114
178
 
115
179
  if (Clarity === null) {
116
180
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
117
- return;
181
+ return new Promise((resolve) => {
182
+ resolve("Undefined");
183
+ });
118
184
  }
119
185
 
120
- Clarity.setCustomTag(key, value);
186
+ return Clarity.getCurrentSessionId();
121
187
  }