Android SDK Installation

SDK Initialization


Android SDK supports API levels 29-34 inclusive. Applications that with API levels 19-28 inclusive will build successfully but data will not be sent to Clarity.

Install the Clarity SDK in order to track how users interact with your app. The Clarity Android SDK is available on a MavenCentral. It can take up to 2 hours to start seeing data.

Step 1

Add mavenCentral() to your project repositories. Add the dependency to your module build.gradle script.

Note: latest version could be found here.

repositories {

dependencies {
   implementation ''

Step 2

Add the following code to your startup activity only:


override fun onCreate(savedInstanceState: Bundle?) {
   val config = ClarityConfig("<ProjectId>")
   Clarity.initialize(applicationContext, config)

Or if you're using Java


protected void onCreate(@Nullable Bundle savedInstanceState) {
   ClarityConfig config = new ClarityConfig(
    null, // Default user id
    false, // Disallow metered network usage
    true, // Enable web view capturing
    Collections.singletonList("*"), // Allowed domains
    Collections.emptyList(), // Allowed activities
    Collections.emptyList(), // Disallowed activities (ignore activities)
    false, // Disable on low-end devices
    null // Maximum allowed daily network usage in MB (null = unlimited)

   Clarity.initialize(getApplicationContext(), config);


You need to invoke this function only once during your startup activity. If you have multiple startup activities, you can either call it within a custom application class or duplicate the call in each startup activity.

If you want to late initialize Clarity after the activity onCreate function is called, you can use a different initialization function that takes the current activity as a parameter:

Clarity.initialize(currentActivity, config)


  • This function has to be called on the main thread.
  • If you use a custom WorkManager initializer, Clarity initialization must take place after the WorkManager initializer. Otherwise, Clarity won't function properly.

Step 3

Once you integrated Clarity with your application, ensure the following if you want to test it on a device or an emulator:

  1. Your device/emulator is connected to the internet.
  2. Your device/emulator Android version is within the supported range 29-34 inclusive.
  3. On your first run, you might need to set the log level to Verbose to get the Clarity logs. These logs could help identifying any initialization errors, if present.

Allow approximately 2 hours for the data to appear in your Clarity project on the Clarity website.

Configuration options

class ClarityConfig(
   val projectId: String,
   val userId: String? = null,
   val logLevel: LogLevel = LogLevel.None,
   val allowMeteredNetworkUsage: Boolean = false,
   val enableWebViewCapture: Boolean = true,
   val allowedDomains: String? = listOf("*"),
   val allowedActivities: List<String> = listOf(),
   val disallowedActivities: List<String> = listOf(),
   val disableOnLowEndDevices: Boolean = false,
   val maximumDailyNetworkUsageInMB: Long? = null

Project ID

Distinct project ID from Clarity. You can find it in the Settings Page.

User ID

The current user's identifier. The user ID remains persistent across sessions on the same device. If there's no user ID, a randomly generated one is used.

  • User ID must be a base-36 string and smaller than the upper limit of 1Z141Z4.
  • If an invalid user ID is provided, a randomly generated ID is used and the invalid user ID is added as the CustomUserID parameter.
  • If an invalid user ID is provided and the user sets the CustomUserID, the invalid user ID is ignored.


CustomUserID has no format restrictions.

Log Level

The level of logging to show in the device's Logcat stream. By default, the SDK logs nothing.

Allow Metered Network Usage

Allows uploading session data to the servers on device metered network. By default, the SDK starts uploading sessions on unmetered networks only.

Enable WebView Capture

Allows Clarity to capture the web views DOM content for recording and heatmap reconstruction.

Allowed Domains

The accepted domains for Clarity to track and capture their DOM content. If it contains * as an element, all domains visited in a session are captured.

Allowed Activities

If disallowed activities list is empty, Clarity only captures activities defined in this list. If both lists are empty, then Clarity captures all screens.

Disallowed Activities

The list of activities to prevent Clarity from capturing them entirely. If this list isn't empty, then the allowed activities list is disregarded.

Disable on Low-End Devices

When enabled, Clarity doesn't capture any data for the low-end devices.

Maximum daily network usage

Once configured, Clarity only sends data to a specified daily limit (in megabytes). Clarity activates lean mode for future sessions within the same day once the limit is reached. In lean mode, only user interactions with the application are recorded, and session playback is dropped. Setting this option to null allows Clarity to transmit all captured data. This limit applies to both metered and unmetered networks.










Clarity capturing is paused.


maskView(View view)


view View

The view instance to mask.



The view was added to the masked views.


unmaskView(View view)


view View

The view instance to unmask.



The view was added to the unmasked views.


setCustomUserId(String customUserId)


customUserId String

The custom user ID to associate with this session. This value can't be null or empty, or consists only of whitespace.



The custom user ID was successfully registered.


  • The custom user ID value can be used to filter and search sessions on the Clarity dashboard.
  • Unlike the userID, the custom userID value has fewer restrictions.
  • We recommend not to set any PII values inside this field.


setCustomSessionId(String customSessionId)


customSessionId String

The custom session ID to associate with this session. This value can't be null or empty, or consists only of whitespace.



The custom session ID was successfully registered.


The custom session ID value can be used to filter and search sessions on the Clarity dashboard.





The current active session ID. If there's no active session, it returns null.


  • The retrieved ID can be used to correlate Clarity sessions with other telemetry services you might be using.
  • Initially, this function might return null until the Clarity session begins.


setCustomTag(String key, String value)

Sets a custom tag for the current session.


key String

The custom tag key. This value can't be null or empty, or consists only of whitespace.

value String

The custom tag value. This value can't be null or empty, or consists only of whitespace.



The custom tag was successfully set.


  • The custom tag can be used to filter and search for sessions on the Clarity dashboard.
  • We recommend not to set any PII values inside this field.

Implementation Notes

  • In case you'd like to associate a name with your fragment for filtering on the Clarity dashboard, assign a certain tag ( to the topmost/root view within your fragment view tree:

    view.setTag(, "SettingFragment")

  • The invocation of View masking APIs should occur in the onCreate() of the activity that hosts the targeted view.


Remember to update your terms & conditions (if any) for your app users after integrating Clarity with your mobile app.


For more answers, refer to FAQ.

Next steps

IP blocking


Visit Clarity