- Table of contents
- Requirements
- Integration
- Setting up the DevRev SDK
- Features
- Sample app
- FAQ
- Android Studio 2022.1.1 or later
- Android Gradle Plugin version 7.4 or later
- Gradle version 7.6 or later
- Minimum Android SDK 24
- Kotlin
Add the following dependencies to your app's build.gradle.kts
file to get the latest version of our SDK:
dependencies {
implementation("ai.devrev.sdk:devrev-sdk:<version>")
}
- Groovy
Add the following dependencies to your app's build.gradle
file to get the latest version of our SDK:
dependencies {
implementation 'ai.devrev.sdk:devrev-sdk:<version>'
}
Our SDK is hosted on mavenCentral, so to gain access to it, just include the mavenCentral to your root's build.gradle.kts
(Kotlin) or build.gradle
(Groovy) file.
repositories {
mavenCentral()
}
After this step, it should be possible to import and use the DevRev SDK in your Android application.
After adding the lines about in your build.gradle.kts
Kotlin or build.gradle
Groovy script you should be able to import and use the DevRev SDK.
Important
The SDK must be configured before you can use any of its features.
Once you have the credentials, you can configure the DevRev SDK in your app. The SDK will be ready to use once you have called the configuration method:
- Kotlin
DevRev.configure(context: Context, appId: String)
- Java
DevRev.INSTANCE.configure(Context context, String appId);
To configure the SDK, you need to call the following method inside your Application
class:
Note
In case you do not have a custom Application
class, you have to extend one like in the following example:
- Kotlin
import ai.devrev.sdk.DevRev
class FooApplication : Application() {
override fun onCreate() {
super.onCreate()
DevRev.configure(
context = this,
appId = "<APP_ID>"
)
}
}
- Java
import ai.devrev.sdk.DevRev;
public class FooApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
DevRev.INSTANCE.configure(
this,
"<APP_ID>"
);
}
}
In the onCreate
method in your Application
, you need to configure the DevRev SDK with the required parameters. Here you need to use the credentials that we have created before.
Moreover, the custom application should be defined in AndroidManifest.xml
like in the following example:
<application
android:name=".FooApplication">
</application>
Certain features of the DevRev SDK require a user identification. There are two methods to identify your users:
- Anonymous users: Creates an anonymous user with an optional user identifier, no other data is stored or associated with the user.
- Unverified users: Identifies the user with a unique identifier, but does not verify the user's identity with the DevRev backend.
Important
The user, organization and account traits in the Identity
structure also support custom fields, which need to be configured in the DevRev web app before they can be used. For more information, see Object customization.
The anonymous identification method is used to create an anonymous user with a random user identifier.
- Kotlin
DevRev.identifyAnonymousUser(
userId: String
)
- Java
DevRev.INSTANCE.identifyAnonymousUser(
String userId
);
The unverified identification method is used to identify the user with a unique identifier, but does not verify the user's identity with the DevRev backend.
- Kotlin
DevRev.identifyUnverifiedUser(
identity: Identity
)
- Java
DevRev.INSTANCE.identifyUnverifiedUser(
Identity identity
);
The function accepts the Identity
object, with the user identifier (userId
) as the only required property, all other properties are optional.
- Kotlin
// Identify an anonymous user without a user identifier.
DevRev.identifyAnonymousUser("abcd1234")
// Identify an unverified user with its email address an user identifier.
DevRev.identifyUnverifiedUser(Identity(userId = "[email protected]"))
- Java
// Identify an anonymous user without a user identifier.
DevRev.INSTANCE.identifyAnonymousUser("abcd1234");
// Identify an unverified user with its email address an user identifier.
DevRev.identifyUnverifiedUser(
new Identity("[email protected]", null, null, null, null, null)
);
The identification function should be placed at the appropriate place in your app after you login your user. If you have the user information at app launch, call the function after the DevRev.configure(context, appID)
method.
You can update the user's information using the following method:
- Kotlin
DevRev.updateUser(
identity: Identity
)
- Java
DevRev.INSTANCE.updateUser(
Identity identity
);
The function accepts the DevRev.Identity
ojbect.
Important
The userID
property can not be updated.
After completing user identification, it is possible to start using the chat (conversations) dialog supported by our DevRev SDK.
In order to open the chat dialog, application should use showSupport
API, as demonstrated in the following example:
- Kotlin
DevRev.showSupport(context: Context)
- Java
DevRevExtKt.showSupport(DevRev.INSTANCE, context);
DevRev SDK also exposes the support button, which can be added to your application. Including it in the current screen requires adding the following code in your XML layout:
<ai.devrev.sdk.plug.view.PlugFloatingActionButton
android:id="@+id/plug_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
The support button can also accept default parameters like
android:src="@your_drawable_here"
and/or
android:backgroundTint="@your_background_color"
so that you can customize it to your own needs. The button will show up on your screen. The button will show up on your screen. Please check the following screenshot to visualize how the support button is expected to look in our application:
At this point, it should be possible to run the app and use all the functionalities of the DevRev PLuG SDK. Pressing the support button would navigate user to the chat.
The DevRev SDK supports sending custom analytic events using a name and a string hashmap.
You can track them using the following function:
- Kotlin
DevRev.trackEvent(name: String, properties: HashMap<String, String>)
- Java
DevRevAnalyticsExtKt.trackEvent(DevRev instance, String name, HashMap<String, String> properties);
- Kotlin
DevRev.trackEvent(name = "open-message-screen", properties = {"id": "foo-bar-1337"})
- Java
DevRevAnalyticsExtKt.trackEvent(DevRev.INSTANCE, "open-message-screen", new HashMap<>().put("id", "foo-bar-1337"));
The DevRev SDK provides observability features to help you understand how your users are interacting with your app.
The end user can give the consent to opt in/out of the observability feature.
- Kotlin
DevRev.stopAllMonitoring()
- Java
DevRevObservabilityExtKt.stopAllMonitoring(DevRev.INSTANCE);
This method stops and deletes the current session recording and also disables the session recording by our SDK for this user in the future.
- Kotlin
DevRev.resumeAllMonitoring()
- Java
DevRevObservabilityExtKt.resumeAllMonitoring(DevRev.INSTANCE);
If the user was disabled for session recording by using the stopAllMonitoring() method, you can use this method to enable recording at runtime.
Note
This feature will only store a monitoring permission flag, it will not provide any UI or dialog.
You can enable session recording to record user interactions with your app.
Caution
The session recording feature is opt-out and is enabled by default.
The session recording feature has a number of methods to help you control the recording:
Kotlin | Java | Action |
---|---|---|
DevRev.startRecording() | DevRevObservabilityExtKt.startRecording(DevRev.INSTANCE, context); | Starts the session recording. |
DevRev.stopRecording() | DevRevObservabilityExtKt.stopRecording(DevRev.INSTANCE); | Stops the session recording and uploads it to the portal. |
DevRev.pauseRecording() | DevRevObservabilityExtKt.pauseRecording(DevRev.INSTANCE); | Pauses the ongoing session recording. |
DevRev.resumeRecording() | DevRevObservabilityExtKt.resumeRecording(DevRev.INSTANCE); | Resumes a paused session recording. |
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.
- Kotlin
DevRev.addSessionProperties(properties: HashMap<String, Any>)
- Java
DevRevObservabilityExtKt.addSessionProperties(DevRev.INSTANCE, HashMap<String, Object> properties);
You also have the ability to clear the session properties in scenarios like user logout or when the session ends.
- Kotlin
DevRev.clearSessionProperties()
- Java
DevRevObservabilityExtKt.clearSessionProperties(DevRev.INSTANCE);
As part of the observability features, the DevRev SDK provides a timer mechanism to help you measure the time spent on a specific task. Events such as response time, loading time, or any other time-based event can be measured using the timer.
The mechanism works using balanced start and stop methods that both accept a timer name and an optional dictionary of properties.
Start a timer using the method:
- Kotlin
DevRev.startTimer(name: String, properties: HashMap<String, String>)
- Java
DevRevObservabilityExtKt.startTimer(DevRev.INSTANCE, String name, HashMap<String, String> properties);
And balance it with the stop method:
- Kotlin
DevRev.endTimer(name: String, properties: HashMap<String, String>)
- Java
DevRevObservabilityExtKt.endTimer(DevRev.INSTANCE, String name, HashMap<String, String> properties);
- Kotlin
DevRev.startTimer("response-time", properties: {"id": "foo-bar-1337"})
// Perform the task that you want to measure.
DevRev.endTimer("response-time", properties: {"id": "foo-bar-1337"})
- Java
DevRevObservabilityExtKt.startTimer(DevRev.INSTANCE, "response-time", new HashMap<String, String>().put("id", "foo-bar-1337"));
// Perform the task that you want to measure.
DevRevObservabilityExtKt.endTimer(DevRev.INSTANCE, "response-time", new HashMap<String, String>().put("id", "foo-bar-1337"));
The DevRev SDK provides automatic screen tracking to help you understand how users are navigating through your app. While activities are automatically tracked, you can also manually track screens/fragments using the following method:
- Kotlin
DevRev.trackScreenName(screenName: String)
- Java
DevRevObservabilityExtKt.trackScreenName(DevRev.INSTANCE, String screenName);
- Kotlin
DevRev.trackScreenName("profile-screen")
- Java
DevRevObservabilityExtKt.trackScreenName(DevRev.INSTANCE, "profile-screen");
You can configure your app to receive push notifications from the DevRev SDK. The SDK is able to handle push notifications and perform actions based on the content of the notification.
The DevRev backend sends push notifications to your app to notify users about new messages in the PLuG support chat. In the future, the push notification support will be expanded with additional features.
Caution
TBD @Ribhu has to provide the integration guide for push notifications. In order to receive push notifications, you need to configure your DevRev organization by following the Push Notifications integration guide.
You need to make sure that your Android app is configured to receive push notifications. You can follow the Firebase documentation to set up your app to receive push notifications.
Important
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 provides a method to register your device for receiving push notifications. You can call the following method to register for push notifications:
- Kotlin
DevRev.registerDeviceToken(
context: Context,
deviceToken: String,
deviceId: String
)
- Java
DevRev.INSTANCE.registerDeviceToken(
Context context,
String deviceToken,
String deviceId
);
The method requires a device identifier, which is persistent across device restarts and app launches. This can be a Firebase installation ID, Android ID, or an identifier unique to your system.
To obtain the device token for Firebase Cloud Messaging:
- Use the
FirebaseMessaging
object. - Call the
firebaseMessaging.token.await()
method. - This method will generate and return the device token.
val firebaseMessaging = FirebaseMessaging.getInstance()
val token = firebaseMessaging.token.await()
// Use the token as needed
In cases when your app no longer wants to receive push notifications, you can unregister the device from receiving them. The method to unregister the device is:
- Kotlin
DevRev.unregisterDevice(
context: Context,
deviceId: String
)
- Java
DevRev.INSTANCE.unregisterDevice(
Context context,
String deviceId
);
The method requires the device identifier, which is the same as the one used for registering the device.
The DevRev SDK currently doesn't supports automatic handling of push notifications. The message payload received in the notification needs to be passed to the SDK to automatically open the PLuG chat and handle navigation internally.
- Kotlin
DevRev.processPushNotification(
context: Context,
userInfo: String
)
- Java
DevRev.INSTANCE.processPushNotification(
Context context,
String userInfo
);
In order to extract the notification payload:
- In Firebase Cloud Messaging (FCM), when a push notification is received, it triggers the
onMessageReceived
function in yourFirebaseMessagingService
class. - This function receives a
RemoteMessage
object as a parameter, which contains the notification data. - The
RemoteMessage
object has a property called data, which is a map containing key-value pairs of the notification payload. - To extract a specific piece of data from the payload, you can use the key to access the value in the data map.
- In this case, to get the "message" from the payload, you would use:
- Kotlin
val message = remoteMessage.data["message"]
- Java
String messageData = remoteMessage.getData().get("message");
- Kotlin
class MyFirebaseMessagingService: FirebaseMessagingService {
// ...
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// ...
val messageData = remoteMessage.data["message"]
DevRev.processPushNotification(messageData)
}
}
- Java
public class MyFirebaseMessagingService extends FirebaseMessagingService {
// ...
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
String messageData = remoteMessage.getData().get("message");
DevRev.processPushNotification(messageData);
}
}
The sample app showcasing both the functionality and the XML implementation has been provided as part of this repository. The users are kindly encouraged to run the sample app before integrating DevRev SDK in the destination application.
Note
The sample is yet to be updated with the latest version of the SDK. Stay Tuned!
In case of any issues with the integration of the DevRev SDK, please verify that the dependency is correctly set in the project. In addition, please make sure that mavenCentral
is reachable from the IDE and that the DevRev PluG SDK version of choice was correctly detected.
In case the showSupport()
function or XML button are not responding, make sure the user has been identified beforehand.
Please check that the app ID (appId
) is correctly configured in your application or sample app.