react-native-clarity 1.0.1 → 2.1.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
@@ -8,64 +8,101 @@ A ReactNative plugin that allows integrating Clarity with your application.
8
8
  npm install react-native-clarity
9
9
  ```
10
10
 
11
+ **Note**: The Clarity package depends on native code to run, therefore you have to ship a new build after integrating the package.
12
+
11
13
  ## Usage
12
14
 
13
15
  ```js
14
- import { initialize, setCustomUserId, getCurrentSessionId, setCurrentScreenName, setCustomTag } from 'react-native-clarity';
16
+ import { LogLevel, initialize, setCustomUserId, setCustomSessionId, setCustomTag, setCurrentScreenName, getCurrentSessionId } from 'react-native-clarity';
15
17
 
16
18
  // Initialize Clarity.
17
- initialize("<ProjectId>");
19
+ const clarityConfig = {
20
+ logLevel: LogLevel.Verbose,
21
+ allowMeteredNetworkUsage: true
22
+ };
23
+
24
+ initialize('<ProjectId>', clarityConfig);
18
25
 
19
26
  // Set custom user id.
20
- setCustomUserId("react@native.com");
27
+ setCustomUserId("<CustomUserId>");
28
+
29
+ // Set custom session id.
30
+ setCustomSessionId("<CustomSessionId>");
21
31
 
22
32
  // Set custom tag.
23
33
  setCustomTag("key", "value");
24
34
 
25
- // Get current session id to correlate with other tools.
26
- getCurrentSessionId().then((id) => {...});
27
-
28
35
  // Setting the current screen name when using React Navigation
29
- import { ..., useFocusEffect } from '@react-navigation/native';
36
+ import { NavigationContainer useNavigationContainerRef } from '@react-navigation/native';
30
37
 
31
38
  const HomeScreen = ({...}) => {
32
- useFocusEffect(
33
- React.useCallback(() => {
34
- setCurrentScreenName("Home");
35
-
36
- // To clear the current screen name when the screen goes out of focus:
37
- return () => { setCurrentScreenName(undefined); }
38
- }, [])
39
+ const navigationRef = useNavigationContainerRef();
40
+ const routeNameRef = React.useRef();
41
+
42
+ return (
43
+ <NavigationContainer
44
+ ref={navigationRef}
45
+ onReady={() => {
46
+ routeNameRef.current = navigationRef.getCurrentRoute().name;
47
+ setCurrentScreenName(routeNameRef.current);
48
+ }}
49
+ onStateChange={() => {
50
+ const previousRouteName = routeNameRef.current;
51
+ const currentRouteName = navigationRef.getCurrentRoute().name;
52
+
53
+ if (previousRouteName !== currentRouteName) {
54
+ routeNameRef.current = currentRouteName;
55
+ setCurrentScreenName(currentRouteName);
56
+ }
57
+ }}
58
+ >
59
+ {/* ... */}
60
+ </NavigationContainer>
39
61
  );
40
- ...
41
62
  };
63
+
64
+ // Get current session id to correlate with other tools.
65
+ getCurrentSessionId().then((id) => {...});
66
+
67
+ // Get current session url to correlate with other tools.
68
+ getCurrentSessionUrl().then((url) => {...});
42
69
  ```
43
70
 
44
71
  ### Initialization arguments
45
72
 
46
- ```js
73
+ ```ts
47
74
  /**
48
- * Initializes the Clarity plugin with the provided parameters.
75
+ * Initializes the Clarity SDK if the API level is supported.
49
76
  *
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
77
+ * @param projectId [REQUIRED] The Clarity project id to send data to.
78
+ * @param config [OPTIONAL] The clarity config, if not provided default values are used.
79
+ */
80
+ function initialize(projectId: string, config?: ClarityConfig)
81
+
82
+ /**
83
+ * The configuration that will be used to customize the Clarity behaviour.
84
+ *
85
+ * @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
52
86
  * will be auto generated. The user id in general is sticky across sessions.
53
87
  * The provided user id must follow these conditions:
54
88
  * 1. Cannot be an empty string.
55
89
  * 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.
90
+ * @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
91
+ * @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
92
+ * @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
93
+ * @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
60
94
  * If it contains "*" as an element, all domains will be captured.
95
+ * @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
61
96
  */
62
- function initialize(
63
- projectId: string,
64
- userId?: string,
65
- logLevel: string = "None",
66
- allowMeteredNetworkUsage: boolean = false,
67
- enableWebViewCapture: boolean = true,
68
- allowedDomains: string[] = ["*"])
97
+
98
+ interface ClarityConfig {
99
+ userId?: string | null;
100
+ logLevel?: LogLevel;
101
+ allowMeteredNetworkUsage?: boolean;
102
+ enableWebViewCapture?: boolean;
103
+ allowedDomains?: string[];
104
+ disableOnLowEndDevices?: Boolean;
105
+ }
69
106
  ```
70
107
 
71
108
  ## 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.1.1"
73
73
  }
74
74
 
75
75
  if (isNewArchitectureEnabled()) {
@@ -1,7 +1,7 @@
1
1
  #make sure these are acutally used
2
2
  Clarity_kotlinVersion=1.7.0
3
3
  Clarity_minSdkVersion=21
4
- Clarity_targetSdkVersion=33
5
- Clarity_compileSdkVersion=33
4
+ Clarity_targetSdkVersion=34
5
+ Clarity_compileSdkVersion=34
6
6
  Clarity_ndkversion=21.4.7075529
7
7
  android.useAndroidX=true
@@ -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,21 +47,32 @@ 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))
52
68
  }
53
69
 
54
70
  @ReactMethod
55
- fun setCustomTag(key: String?, value: String?, promise: Promise) {
56
- promise.resolve(Clarity.setCustomTag(key, value))
71
+ fun getCurrentSessionUrl(promise: Promise) {
72
+ promise.resolve(Clarity.getCurrentSessionUrl())
57
73
  }
58
74
 
75
+
59
76
  private fun readableArrayToList(arr: ReadableArray): List<String> {
60
77
  val ret = mutableListOf<String>()
61
78
 
@@ -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;
8
+ exports.getCurrentSessionUrl = getCurrentSessionUrl;
7
9
  exports.initialize = initialize;
8
10
  exports.setCurrentScreenName = setCurrentScreenName;
11
+ exports.setCustomSessionId = setCustomSessionId;
9
12
  exports.setCustomTag = setCustomTag;
10
13
  exports.setCustomUserId = setCustomUserId;
11
14
  var _reactNative = require("react-native");
@@ -16,25 +19,52 @@ const Clarity = _reactNative.NativeModules.Clarity;
16
19
  const SupportedPlatforms = ['android'];
17
20
 
18
21
  /**
19
- * Initializes the Clarity plugin with the provided parameters.
22
+ * The configuration that will be used to customize the Clarity behaviour.
20
23
  *
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
24
+ * @param userId [OPTIONAL default = null] A custom identifier for the current user. If passed as null, the user id
23
25
  * will be auto generated. The user id in general is sticky across sessions.
24
26
  * The provided user id must follow these conditions:
25
27
  * 1. Cannot be an empty string.
26
28
  * 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.
29
+ * @param logLevel [OPTIONAL default = LogLevel.None] The level of logging to show in the device logcat stream.
30
+ * @param allowMeteredNetworkUsage [OPTIONAL default = false] Allows uploading session data to the servers on device metered network.
31
+ * @param enableWebViewCapture [OPTIONAL default = true] Allows Clarity to capture the web views DOM content.
32
+ * @param allowedDomains [OPTIONAL default = ["*"]] The whitelisted domains to allow Clarity to capture their DOM content.
31
33
  * If it contains "*" as an element, all domains will be captured.
34
+ * @param disableOnLowEndDevices [OPTIONAL default = false] Disable Clarity on low-end devices.
32
35
  */
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] : ["*"];
36
+ /**
37
+ * The level of logging to show in the device logcat stream.
38
+ */
39
+ let LogLevel = /*#__PURE__*/function (LogLevel) {
40
+ LogLevel["Verbose"] = "Verbose";
41
+ LogLevel["Debug"] = "Debug";
42
+ LogLevel["Info"] = "Info";
43
+ LogLevel["Warning"] = "Warning";
44
+ LogLevel["Error"] = "Error";
45
+ LogLevel["None"] = "None";
46
+ return LogLevel;
47
+ }({});
48
+ /**
49
+ * Initializes the Clarity SDK if the API level is supported.
50
+ * @param projectId [REQUIRED] The Clarity project id to send data to.
51
+ * @param config [OPTIONAL] The clarity config, if not provided default values are used.
52
+ */
53
+ exports.LogLevel = LogLevel;
54
+ function initialize(projectId, config) {
55
+ if (typeof projectId !== "string" || !(typeof config === "object" || typeof config === "undefined")) {
56
+ throw Error("Invalid Clarity initialization arguments. Please check the docs for assitance.");
57
+ }
58
+
59
+ // applying default values
60
+ let {
61
+ userId = null,
62
+ logLevel = LogLevel.None,
63
+ allowMeteredNetworkUsage = false,
64
+ enableWebViewCapture = true,
65
+ allowedDomains = ["*"],
66
+ disableOnLowEndDevices = false
67
+ } = config ?? {};
38
68
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
39
69
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
40
70
  return;
@@ -43,7 +73,7 @@ function initialize(projectId, userId) {
43
73
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
44
74
  return;
45
75
  }
46
- Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains);
76
+ Clarity.initialize(projectId, userId, logLevel, allowMeteredNetworkUsage, enableWebViewCapture, allowedDomains, disableOnLowEndDevices);
47
77
  }
48
78
 
49
79
  /**
@@ -69,26 +99,30 @@ function setCustomUserId(customUserId) {
69
99
  }
70
100
 
71
101
  /**
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.
102
+ * Sets a custom session id that can be used to identify the session.
103
+ * <p>
104
+ * Note: custom session id cannot be null or empty, or consists only of whitespaces.
105
+ * </p>
106
+ * @param customSessionId The custom session id to set.
75
107
  */
76
- function getCurrentSessionId() {
108
+ function setCustomSessionId(customSessionId) {
77
109
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
78
110
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
79
- return new Promise(resolve => {
80
- resolve("Undefined");
81
- });
111
+ return;
82
112
  }
83
113
  if (Clarity === null) {
84
114
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
85
- return new Promise(resolve => {
86
- resolve("Undefined");
87
- });
115
+ return;
88
116
  }
89
- return Clarity.getCurrentSessionId();
117
+ Clarity.setCustomSessionId(customSessionId);
90
118
  }
91
- function setCurrentScreenName(screenName) {
119
+
120
+ /**
121
+ * Sets a custom tag for the current session.
122
+ * @param key The tag key to set.
123
+ * @param value The tag value to set.
124
+ */
125
+ function setCustomTag(key, value) {
92
126
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
93
127
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
94
128
  return;
@@ -97,9 +131,17 @@ function setCurrentScreenName(screenName) {
97
131
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
98
132
  return;
99
133
  }
100
- Clarity.setCurrentScreenName(screenName);
134
+ Clarity.setCustomTag(key, value);
101
135
  }
102
- function setCustomTag(key, value) {
136
+
137
+ /**
138
+ * For React Native applications only, this function is used to set the current screen name
139
+ * in case the ReactNative Navigation package is used.
140
+ * This will allow you to split and analyze your data on the screen names.
141
+ * You can it set to `null` to remove the latest set value.
142
+ * @param screenName The current screen name to set.
143
+ */
144
+ function setCurrentScreenName(screenName) {
103
145
  if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
104
146
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
105
147
  return;
@@ -108,6 +150,41 @@ function setCustomTag(key, value) {
108
150
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
109
151
  return;
110
152
  }
111
- Clarity.setCustomTag(key, value);
153
+ Clarity.setCurrentScreenName(screenName);
154
+ }
155
+
156
+ /**
157
+ * Returns the active session id. This can be used to correlate the Clarity session with other
158
+ * analytics tools that the developer may be using.
159
+ * @returns a promise that resolves to the current session id.
160
+ */
161
+ function getCurrentSessionId() {
162
+ if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
163
+ console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
164
+ return Promise.resolve("Undefined");
165
+ }
166
+ if (Clarity === null) {
167
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
168
+ return Promise.resolve("Undefined");
169
+ }
170
+ return Clarity.getCurrentSessionId();
171
+ }
172
+
173
+ /**
174
+ * Returns the active session url. This can be used to correlate the Clarity session with other
175
+ * analytics tools that the developer may be using.
176
+ *
177
+ * @returns a promise that resolves to the current session url if there is an active one.
178
+ */
179
+ function getCurrentSessionUrl() {
180
+ if (!SupportedPlatforms.includes(_reactNative.Platform.OS)) {
181
+ console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
182
+ return Promise.resolve("Undefined");
183
+ }
184
+ if (Clarity === null) {
185
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
186
+ return Promise.resolve("Undefined");
187
+ }
188
+ return Clarity.getCurrentSessionUrl();
112
189
  }
113
190
  //# 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,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;AACO,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,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,CAACG,UAAU,CAACC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAEI,wBAAwB,EAAEC,oBAAoB,EAAEC,cAA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AGf,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,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","getCurrentSessionUrl"],"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;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,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF,OAAOY,OAAO,CAACC,OAAO,CAAC,WAAW,CAAC;EACrC;EAEA,IAAIlC,OAAO,KAAK,IAAI,EAAE;IACpBmB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEvB,aAAa,CAAC;IACpE,OAAOkC,OAAO,CAACC,OAAO,CAAC,WAAW,CAAC;EACrC;EAEA,OAAOlC,OAAO,CAACmC,oBAAoB,CAAC,CAAC;AACvC"}
@@ -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,41 @@ 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 Promise.resolve("Undefined");
153
+ }
154
+ if (Clarity === null) {
155
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
156
+ return Promise.resolve("Undefined");
157
+ }
158
+ return Clarity.getCurrentSessionId();
159
+ }
160
+
161
+ /**
162
+ * Returns the active session url. This can be used to correlate the Clarity session with other
163
+ * analytics tools that the developer may be using.
164
+ *
165
+ * @returns a promise that resolves to the current session url if there is an active one.
166
+ */
167
+ export function getCurrentSessionUrl() {
168
+ if (!SupportedPlatforms.includes(Platform.OS)) {
169
+ console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
170
+ return Promise.resolve("Undefined");
171
+ }
172
+ if (Clarity === null) {
173
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
174
+ return Promise.resolve("Undefined");
175
+ }
176
+ return Clarity.getCurrentSessionUrl();
102
177
  }
103
178
  //# 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,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,CAACE,UAAU,CAACC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAEI,wBA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,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","resolve","getCurrentSessionUrl"],"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;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B,kBAAkB,CAACiB,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpF,OAAOY,OAAO,CAACC,OAAO,CAAC,WAAW,CAAC;EACrC;EAEA,IAAI/B,OAAO,KAAK,IAAI,EAAE;IACpBgB,OAAO,CAACG,KAAK,CAAC,sCAAsC,EAAEpB,aAAa,CAAC;IACpE,OAAO+B,OAAO,CAACC,OAAO,CAAC,WAAW,CAAC;EACrC;EAEA,OAAO/B,OAAO,CAACgC,oBAAoB,CAAC,CAAC;AACvC"}
@@ -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,39 @@ 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 | null): 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;
80
+ /**
81
+ * Returns the active session url. This can be used to correlate the Clarity session with other
82
+ * analytics tools that the developer may be using.
83
+ *
84
+ * @returns a promise that resolves to the current session url if there is an active one.
85
+ */
86
+ export declare function getCurrentSessionUrl(): Promise<string>;
36
87
  //# 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,GAAG,IAAI,QAY7D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAYrD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAYtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-clarity",
3
- "version": "1.0.1",
3
+ "version": "2.1.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,29 +103,32 @@ 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;
83
116
  }
84
117
 
85
118
  if (Clarity === null) {
86
119
  console.error("Clarity did not initialize properly.", LINKING_ERROR);
87
- return new Promise((resolve) => {
88
- resolve("Undefined");
89
- });
120
+ return;
90
121
  }
91
122
 
92
- return Clarity.getCurrentSessionId();
123
+ Clarity.setCustomSessionId(customSessionId);
93
124
  }
94
125
 
95
- export function setCurrentScreenName(screenName: string) {
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) {
96
132
  if (!SupportedPlatforms.includes(Platform.OS)) {
97
133
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
98
134
  return;
@@ -103,10 +139,17 @@ export function setCurrentScreenName(screenName: string) {
103
139
  return;
104
140
  }
105
141
 
106
- Clarity.setCurrentScreenName(screenName);
142
+ Clarity.setCustomTag(key, value);
107
143
  }
108
144
 
109
- export function setCustomTag(key: string, value: string) {
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
+ */
152
+ export function setCurrentScreenName(screenName: string | null) {
110
153
  if (!SupportedPlatforms.includes(Platform.OS)) {
111
154
  console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
112
155
  return;
@@ -117,5 +160,44 @@ export function setCustomTag(key: string, value: string) {
117
160
  return;
118
161
  }
119
162
 
120
- Clarity.setCustomTag(key, value);
163
+ Clarity.setCurrentScreenName(screenName);
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 Promise.resolve("Undefined");
175
+ }
176
+
177
+ if (Clarity === null) {
178
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
179
+ return Promise.resolve("Undefined");
180
+ }
181
+
182
+ return Clarity.getCurrentSessionId();
183
+ }
184
+
185
+ /**
186
+ * Returns the active session url. This can be used to correlate the Clarity session with other
187
+ * analytics tools that the developer may be using.
188
+ *
189
+ * @returns a promise that resolves to the current session url if there is an active one.
190
+ */
191
+ export function getCurrentSessionUrl(): Promise<string> {
192
+ if (!SupportedPlatforms.includes(Platform.OS)) {
193
+ console.warn("Clarity supports " + SupportedPlatforms.join(", ") + " only for now.");
194
+ return Promise.resolve("Undefined");
195
+ }
196
+
197
+ if (Clarity === null) {
198
+ console.error("Clarity did not initialize properly.", LINKING_ERROR);
199
+ return Promise.resolve("Undefined");
200
+ }
201
+
202
+ return Clarity.getCurrentSessionUrl();
121
203
  }