Features

Identification

To access certain features of the DevRev SDK, user identification is required.

The identification function should be placed appropriately in your app after the user logs in. If you have the user information available at app launch, call the function after the DevRev.configure(context, appID) method.

The Identity structure allows for custom fields in the user, organization, and account traits. These fields must be configured through the DevRev app before they can be utilized. For more information, refer to Object customization.

Identify an anonymous user

The anonymous identification method allows you to create an anonymous user with an optional user identifier, ensuring that no other data is stored or associated with the user.

1DevRev.identifyAnonymousUser(
2 userId: String
3)

Identify an unverified user

The unverified identification method identifies users with a unique identifier, but it does not verify their identity with the DevRev backend.

1DevRev.identifyUnverifiedUser(
2 identity: Identity
3)

The function accepts the DevRev.Identity structure, with the user identifier (userID) as the only required property, all other properties are optional.

For example:

1// Identify an unverified user using their email address as the user identifier.
2DevRev.identifyUnverifiedUser(Identity(userId = "user@example.org"))

Identify a verified user

The verified identification method is used to identify users with an identifier unique to your system within the DevRev platform. The verification is done through a token exchange process between you and the DevRev backend.

The steps to identify a verified user are as follows:

  1. Generate an AAT for your system (preferably through your backend).
  2. Exchange your AAT for a session token for each user of your system.
  3. Pass the user identifier and the exchanged session token to the DevRev.identifyVerifiedUser(userId: String, sessionToken: String) method.

For security reasons, it is strongly recommended that the token exchange is executed on your backend to prevent exposing your application access token (AAT).

Generate an AAT

  1. Open the DevRev web app at https://app.devrev.ai and go to the Settings page.
  2. Open the PLuG Tokens page.
  3. Under the Application access tokens panel, click New token and copy the token that’s displayed.

Ensure that you copy the generated application access token, as you cannot view it again.

Exchange your AAT for a session token

To proceed with identifying the user, you need to exchange your AAT for a session token. This step helps you identify a user of your own system within the DevRev platform.

Here is a simple example of an API request to the DevRev backend to exchange your AAT for a session token:

Make sure that you replace the <AAT> and <YOUR_USER_ID> with the actual values.

$curl \
>--location 'https://api.devrev.ai/auth-tokens.create' \
>--header 'accept: application/json, text/plain, */*' \
>--header 'content-type: application/json' \
>--header 'authorization: <AAT>' \
>--data '{
> "rev_info": {
> "user_ref": "<YOUR_USER_ID>"
> }
>}'

The response of the API call contains a session token that you can use with the verified identification method in your app.

As a good practice, your app should retrieve the exchanged session token from your backend at app launch or any relevant app lifecycle event.

Identify the verified user

Pass the user identifier and the exchanged session token to the verified identification method:

1DevRev.identifyVerifiedUser(userId: String, sessionToken: String)

Updating the user

To update a user’s information, use the following method:

1DevRev.updateUser(
2 identity: Identity
3)

The function accepts the DevRev.Identity ojbect.

The userID property cannot be updated.

Logout

You can perform a logout of the current user by calling the following method:

1DevRev.logout(context: Context, deviceId: String)

The user is logged out by clearing their credentials, as well as unregistering the device from receiving push notifications, and stopping the session recording.

Identity model

The Identity class is used to provide user, organization, and account information when identifying users or updating their details. This class is used primarily with the identifyUnverifiedUser(identity: Identity) and updateUser(identity: Identity) methods.

Properties

The Identity class contains the following properties:

PropertyTypeRequiredDescription
userIDStringA unique identifier for the user
organizationIDString?An identifier for the user’s organization
accountIDString?An identifier for the user’s account
userTraitsUserTraits?Additional information about the user
organizationTraitsOrganizationTraits?Additional information about the organization
accountTraitsAccountTraits?Additional information about the account

The custom fields properties defined as part of the user, organization and account traits, must be configured in the DevRev web app before they can be used. See Object customization for more information.

User traits

The UserTraits class contains detailed information about the user:

All properties in UserTraits are optional.

PropertyTypeDescription
displayNameString?The displayed name of the user
emailString?The user’s email address
fullNameString?The user’s full name
userDescriptionString?A description of the user
phoneNumbers[String]?Array of the user’s phone numbers
customFields[String: Any]?Dictionary of custom fields configured in DevRev
Organization traits

The OrganizationTraits class contains detailed information about the organization:

All properties in OrganizationTraits are optional.

PropertyTypeDescription
displayNameString?The displayed name of the organization
domainString?The organization’s domain
organizationDescriptionString?A description of the organization
phoneNumbers[String]?Array of the organization’s phone numbers
tierString?The organization’s tier or plan level
customFields[String: Any]?Dictionary of custom fields configured in DevRev
Account traits

The AccountTraits class contains detailed information about the account:

All properties in AccountTraits are optional.

PropertyTypeDescription
displayNameString?The displayed name of the account
domains[String]?Array of domains associated with the account
accountDescriptionString?A description of the account
phoneNumbers[String]?Array of the account’s phone numbers
websites[String]?Array of websites associated with the account
tierString?The account’s tier or plan level
customFields[String: Any]?Dictionary of custom fields configured in DevRev

PLuG support chat

Once user identification is complete, you can start using the chat (conversations) dialog supported by our DevRev SDK. To open the chat dialog, your application should use the showSupport API, as shown in the following example:

1DevRev.showSupport(context: Context)

Create a new conversation

You have the ability to create a new conversation from within your app. The method shows the support chat screen and creates a new conversation at the same time.

1DevRev.createSupportConversation(context: Context)

Support button

The DevRev SDK also provides a support button, which can be integrated into your application. To include it on the current screen, add the following code to your XML layout:

1<ai.devrev.sdk.plug.view.PlugFloatingActionButton
2 android:id="@+id/plug_fab"
3 android:layout_width="wrap_content"
4 android:layout_height="wrap_content"
5 android:layout_margin="24dp"
6 app:layout_constraintBottom_toBottomOf="parent"
7 app:layout_constraintEnd_toEndOf="parent" />

The support button can be customized using default parameters, enabling you to tailor its appearance to your application’s design:

1android:src="@your_drawable_here"
2android:backgroundTint="@your_background_color"

The DevRev SDK provides a mechanism to handle links opened from within any screen that is part of the DevRev SDK.

You can fully customize the link handling behavior by setting the specialized in-app link handler. That way you can decide what should happen when a link is opened from within the app.

1DevRev.setInAppLinkHandler(handler: (String) -> Unit)

You can further customize the behavior by setting the setShouldDismissModalsOnOpenLink boolean flag. This flag controls whether the DevRev SDK should dismiss the top-most modal screen when a link is opened.

1DevRev.setShouldDismissModalsOnOpenLink(value: boolean)

For example:

1DevRev.setInAppLinkHandler { link ->
2 // Do something here
3}
4
5DevRev.setShouldDismissModalsOnOpenLink(false)

Dynamic theme configuration

The DevRev SDK allows you to configure the theme dynamically based on the system appearance, or use the theme configured on the DevRev portal. By default, the theme is dynamic and follows the system appearance.

1DevRev.setShouldPreferSystemTheme(value: Boolean)

Analytics

The DevRev SDK allows you to send custom analytic events by using a name and a string dictionary. You can track these events using the following function:

1DevRev.trackEvent(name: String, properties: HashMap<String, String>)

For example:

1DevRev.trackEvent(name = "open-message-screen", properties = {"id": "message-1337"})

Session analytics

The DevRev SDK provides observability features to help you understand how your users are interacting with your app.

Opt in or out

Session analytics features are opted-in by default, enabling them from the start. However, you can opt-out using the following method:

1DevRev.stopAllMonitoring()

To opt back in, use the following method:

1DevRev.resumeAllMonitoring()

You can check whether session monitoring has been enabled by using this property:

1DevRev.isMonitoringEnabled

This feature will only store a monitoring permission flag, it will not provide any UI or dialog.

Session recording

You can enable session recording to capture user interactions with your app.

The session recording feature is opt-out and is enabled by default.

Here are the available methods to help you control the session recording feature:

MethodAction
DevRev.startRecording()Starts the session recording.
DevRev.stopRecording()Ends the session recording and uploads it to the portal.
DevRev.pauseRecording()Pauses the ongoing session recording.
DevRev.resumeRecording()Resumes a paused session recording.
DevRev.processAllOnDemandSessions()Stops the ongoing user recording and sends all on-demand sessions along with the current recording.

Using this property returns the status of the session recording:

1DevRev.isRecording

To check if on-demand sessions are enabled, use:

1DevRev.areOnDemandSessionsEnabled

Session properties

You can add custom properties to the session recording to help you understand the context of the session. The properties are defined as a dictionary of string values.

1DevRev.addSessionProperties(properties: HashMap<String, String>)

To clear the session properties in scenarios such as user logout or when the session ends, use the following method:

1DevRev.clearSessionProperties()

Mask sensitive data

To protect sensitive data, the DevRev SDK provides an auto-masking feature that masks data before sending to the server. Input views such as text fields, text views, and web views are automatically masked.

While the auto-masking feature may be sufficient for most situations, you can manually mark/unmark additional views as sensitive.

The SDK provides two approaches to manually mask or unmask your views, using a set of predefined tags or using the API methods.

Mask using predefined tags

Use the tag method only when you don’t have any other tag already applied to your UI element.

Masking views using the predefined tags is the simplest way to mask your views, use the tag devrev-mask to mask a view and devrev-unmask to unmask a view.

  • Mark a view as masked:

    1android:tag="devrev-mask"
  • Mark a view as unmasked:

    1android:tag="devrev-unmask"

For example:

1<!-- A masked web view -->
2<WebView
3 android:id="@+id/webview1"
4 android:layout_width="fill_parent"
5 android:layout_height="200dp"
6 android:background="@android:color/transparent"
7 android:tag="devrev-mask" />
8
9<!-- An unmasked web view -->
10<WebView
11 android:id="@+id/webview2"
12 android:layout_width="fill_parent"
13 android:layout_height="200dp"
14 android:background="@android:color/transparent"
15 android:tag="devrev-unmask" />

The tags can also be set programmatically:

  • Mark a view as masked:
    1val firstView: View = findViewById(R.id.firstView)
    2firstView.tag = "devrev-mask"
  • Mark a view as unmasked:
    1val secondView: View = findViewById(R.id.secondView)
    2secondView.tag = "devrev-unmask"

Mask using the API methods

You can also use the API methods to mask or unmask your views programmatically.

  • Mark a view as masked:
    1DevRev.markSensitiveViews(sensitiveViews: List<View>)
  • Mark a view as unmasked:
    1DevRev.unmarkSensitiveViews(sensitiveViews: List<View>)

For example:

1// Mark two views as masked.
2
3val view1 = findViewById(R.id.view1)
4val view2 = findViewById(R.id.view2)
5
6DevRev.markSensitiveViews(listOf(view1, view2))
7
8// Mark two views as unmasked.
9
10val view3 = findViewById(R.id.view3)
11val view4 = findViewById(R.id.view4)
12
13DevRev.unmarkSensitiveViews(listOf(view3, view4))

Mask Jetpack Compose views

If you want to mask any Jetpack Compose UI elements or views, you can apply a mask on it using a modifier.

1modifier = Modifier.markAsMaskedLocation("VIEW_NAME_OR_ID")

For example:

1TextField(
2 modifier = Modifier
3 .markAsMaskedLocation("myTextField")
4 .padding(horizontal = 20.dp)
5 .onGloballyPositioned { coordinates = it },
6 value = input,
7 onValueChange = { input = it }
8)

Mask elements inside web views

Masking elements inside web views (WebView) can be achieved by using the CSS class devrev-mask to mask an element and devrev-unmask to unmask an element.

  • Mark an element as masked:
    1<label class="devrev-mask">OTP: 12345</label>
  • Mark an element as unmasked:
    1<input type="text" placeholder="Enter Username" name="username" required class="devrev-unmask">

Custom masking provider

For advanced use cases, you can provide a custom masking provider to explicitly specify which regions of the UI should be masked during snapshots.

You can implement your own masking logic by creating a class that implements the MaskLocationProvider interface and setting your custom object as the masking provider. This allows you to specify explicit regions to be masked or to skip snapshots entirely.

SymbolDescription
DevRev.setMaskLocationProvider(maskLocationProvider: MaskLocationProvider)A custom provider that determines which UI regions should be masked for privacy during snapshots (this overrides any previously set provider).
MaskLocationProviderAn interface for providing explicit masking locations for UI snapshots.
SnapshotMaskAn object that describes the regions of a snapshot to be masked.
SnapshotMask.LocationAn object that describes a masked region.

For example:

1import com.userexperior.bridge.model.MaskLocationProvider
2import com.userexperior.bridge.model.SnapshotMask
3import com.userexperior.bridge.model.SnapshotMask.Location
4import ai.devrev.sdk.DevRev
5
6class MyMaskingProvider : MaskLocationProvider {
7 override fun provideSnapshotMask(): SnapshotMask {
8 val region = SnapshotMask.Location(x = 10, y = 10, width = 100, height = 40)
9 return SnapshotMask(
10 locations = listOf(region),
11 shouldSkip = false
12 )
13 }
14}
15
16DevRev.setMaskLocationProvider(MyMaskingProvider())

Setting a new provider overrides any previously set masking location provider.

Timers

The DevRev SDK offers a timer mechanism to measure the time spent on specific tasks, allowing you to track events such as response time, loading time, or any other duration-based metrics.

The mechanism works using balanced start and stop methods that both accept a timer name and an optional dictionary of properties.

To start a timer, use the following method:

1DevRev.startTimer(name: String, properties: HashMap<String, String>)

To stop a timer, use the following method:

1DevRev.endTimer(name: String, properties: HashMap<String, String>)

For example:

1DevRev.startTimer("response-time", properties: {"id": "task-1337"})
2
3// Perform the task that you want to measure.
4
5DevRev.endTimer("response-time", properties: {"id": "task-1337"})

Track screens

The DevRev SDK offers automatic screen tracking to help you understand how users navigate through your app. Although activities and fragments are automatically tracked, you can manually track screens using the following method:

1DevRev.trackScreenName(screenName: String)

For example:

1DevRev.trackScreenName("profile-screen")

Manage screen transitions

The DevRev SDK allows tracking of screen transitions to understand the user navigation within your app. You can check if a screen transition is in progress and manually update the state using the following methods:

Check if the screen is transitioning

1val isTransitioning = DevRev.isInScreenTransitioning

Set screen transitioning state

1// Mark the transition as started.
2DevRev.setInScreenTransitioning(true)
3
4// Mark the transition as ended.
5DevRev.setInScreenTransitioning(false)

Push notifications

You can configure your app to receive push notifications from the DevRev SDK. The SDK is designed to handle push notifications and execute actions based on the notification’s content.

The DevRev backend sends push notifications to your app to notify users about new messages in the PLuG support chat.

Configuration

To receive push notifications, you need to configure your DevRev organization by following the instructions in the push notifications section.

You need to ensure that your Android app is configured to receive push notifications. To set it up, follow the Firebase documentation.

Register for push notifications

Push notifications require that the SDK has been configured and the user has been identified (unverified and anonymous users). The user identification is required to send the push notification to the correct user.

The DevRev SDK offers a method to register your device for receiving push notifications. You can register for push notifications using the following method:

1DevRev.registerDeviceToken(
2 context: Context,
3 deviceToken: String,
4 deviceId: String
5)

The method requires a device identifier that persists across device restarts and app launches. This could be a Firebase installation ID, Android ID, or a unique system identifier. To obtain the device token for Firebase Cloud Messaging, follow these steps:

  1. Use the FirebaseMessaging object.
  2. Call the firebaseMessaging.token.await() method.

This method generates and returns the device token.

1val firebaseMessaging = FirebaseMessaging.getInstance()
2val token = firebaseMessaging.token.await()
3// Use the token as needed

Unregister from push notifications

If your app no longer needs to receive push notifications, you can unregister the device.

Use the following method to unregister the device:

The method requires the device identifier, which should be the same as the one used when registering the device.

1DevRev.unregisterDevice(
2 context: Context,
3 deviceId: String
4)

The method requires the device identifier, which should be the same as the one used when registering the device.

Handle push notifications

The DevRev SDK currently does not support automatic handling of push notifications. To open the PLuG chat and manage navigation internally, you must pass the message payload received in the notification to the SDK.

1DevRev.processPushNotification(
2 context: Context,
3 userInfo: String
4)

To extract the notification payload, do the following:

  1. In Firebase Cloud Messaging (FCM), when a push notification is received, it triggers the onMessageReceived function in your FirebaseMessagingService class.
  2. This function receives a RemoteMessage object as a parameter, which contains the notification data.
  3. The RemoteMessage object has a data property, which is a map containing key-value pairs of the notification payload.
  4. To extract a specific piece of data from the payload, use the key to access the value in the data map.
  5. To retrieve the “message” from the payload:
1val message = remoteMessage.data["message"]

For example:

1class MyFirebaseMessagingService: FirebaseMessagingService {
2 // ...
3
4 override fun onMessageReceived(remoteMessage: RemoteMessage) {
5 // ...
6 val messageData = remoteMessage.data["message"]
7 DevRev.processPushNotification(messageData)
8 }
9}