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(appID:) method.

If you haven’t previously identified the user, the DevRev SDK will automatically create an anonymous user for you immediately after the SDK is configured.

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.

You can select from the following methods to identify users within your application:

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(userID:)

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(_:)

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

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(_:sessionToken:) 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(_:sessionToken:)

Update the user

You can update the user’s information using the following method:

1DevRev.updateUser(_:)

This function accepts the DevRev.Identity structure.

The userID property cannot be updated.

The identification functions are asynchronous. Ensure you wrap them in a Task when calling from synchronous contexts.

Use this property to check whether the user is identified in the current session:

1DevRev.isUserIdentified

Logout

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

1DevRev.logout(deviceID:)

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

For example:

1// Identify an anonymous user without a user identifier.
2await DevRev.identifyAnonymousUser()
3
4// Identify an unverified user using their email address as the user identifier.
5await DevRev.identifyUnverifiedUser(Identity(userID: "user@example.org"))
6
7// Identify a verified user using their email address as the user identifier.
8await DevRev.identifyVerifiedUser("foo@example.org", sessionToken: "bar-1337")
9
10// Update the user's information.
11await DevRev.updateUser(Identity(organizationID: "organization-1337"))
12
13// Logout the identified user.
14await DevRev.logout(deviceID: "dvc32423")

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(_:) and updateUser(_:) 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

UIKit

The support chat feature can be shown as a modal screen from a specific view controller or the top-most one, or can be pushed onto a navigation stack. 

To show the support chat screen in your app, you can use the following overloaded method:

1DevRev.showSupport(from:isAnimated:)
  • When a UIViewController is passed as the from parameter, the screen is shown modally.

  • When a UINavigationController is passed as the from parameter, the screen is pushed onto the navigation stack.

If you want to display the support chat screen from the top-most view controller, use the following method:

1DevRev.showSupport(isAnimated:)

To create a new support conversation directly, use the following method:

1DevRev.createSupportConversation(isAnimated:)

For example:

1// Push the support chat screen to a navigation stack.
2await DevRev.showSupport(from: mainNavigationController)
3
4// Show the support chat screen modally from a specific view controller.
5await DevRev.showSupport(from: settingsViewController)
6
7// Show the support chat screen from the top-most view controller, without an animation.
8await DevRev.showSupport(isAnimated: false)
9
10// Create a new support conversation directly from the top-most view controller.
11await DevRev.createSupportConversation(isAnimated: true)

SwiftUI

To display the support chat screen in a SwiftUI app, you can use the following view:

1DevRev.supportView

New conversation closure

You can receive a callback when a new conversation is created by setting the following closure:

1DevRev.conversationCreatedCompletion

This allows your app to access the ID of the newly created conversation.

For example:

1DevRev.conversationCreatedCompletion = { conversationID in
2 print("A new conversation has been created: \(conversationID).")
3}

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.inAppLinkHandler: ((URL) -> Void)?

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

1DevRev.shouldDismissModalsOnOpenLink: Bool

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.prefersSystemTheme: Bool

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:properties:)

For example:

1await DevRev.trackEvent(name: "open-message-screen", properties: ["id": "message-1337"])

Session analytics

The DevRev SDK offers session analytics features to help you understand how users interact 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()

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.

The session recording feature includes the following methods to control the recording:

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.

You can also check the following flags for session recording:

1// Check if session recording is currently active.
2let isRecording = DevRev.isRecording
3
4// Check if session monitoring is enabled.
5let isMonitoringEnabled = DevRev.isMonitoringEnabled
6
7// Check if on-demand sessions are enabled.
8let areOnDemandSessionsEnabled = DevRev.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(_:)

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

1DevRev.clearSessionProperties()

Masking 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 additional views as sensitive using the following method:

1DevRev.markSensitiveViews(_:)

If any previously masked views need to be unmasked, you can use the following method:

1DevRev.unmarkSensitiveViews(_:)

Custom masking provider

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

You can implement your own masking logic by conforming to the DevRev.MaskLocationProviding protocol 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.setMaskingLocationProvider(_ provider: DevRev.MaskLocationProviding)A custom provider that determines which UI regions should be masked for privacy during snapshots.
DevRev.MaskLocationProvidingA protocol for providing explicit masking locations for UI snapshots.
DevRev.SnapshotMaskAn object that describes the regions of a snapshot to be masked.
DevRev.SnapshotMask.LocationAn object that describes a masked region.

For example:

1import Foundation
2import UIKit
3import DevRevSDK
4
5class MyMaskingProvider: NSObject, DevRev.MaskLocationProviding {
6 func provideSnapshotMask(_ completionHandler: @escaping (DevRev.SnapshotMask) -> Void) {
7 // Example: Mask a specific region
8 let region = CGRect(x: 10, y: 10, width: 100, height: 40)
9 let location = DevRev.SnapshotMask.Location(location: region)
10 let mask = DevRev.SnapshotMask(locations: [location], shouldSkip: false)
11 completionHandler(mask)
12 }
13}
1DevRev.setMaskingLocationProvider(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(_:properties:)

To stop a timer, use the following method:

1DevRev.endTimer(_:properties:)

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 view controllers are automatically tracked, you can manually track screens using the following method:

1DevRev.trackScreenName(_:)

For example:

1DevRev.trackScreenName("profile-screen")

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 iOS app is configured to receive push notifications. You can follow the Apple documentation for guidance on registering your app with Apple Push Notification Service (APNs).

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(_:deviceID:)

The method requires a device identifier, which can either be an identifier unique to your system or the Apple-provided Vendor Identifier (IDFV). Typically, the token registration is called from the AppDelegate.application(_:didRegisterForRemoteNotificationsWithDeviceToken:) method.

For example:

1func application(
2 _ application: UIApplication,
3 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
4) {
5 guard
6 let deviceID = UIDevice.current.identifierForVendor?.uuidString
7 else {
8 return
9 }
10
11 Task {
12 await DevRev.registerDeviceToken(
13 deviceToken,
14 deviceID: deviceID
15 )
16 }
17}

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:

1DevRev.unregisterDevice(_:)

This method requires the device identifier, which should be the same as the one used during registration. It is recommended to place this method after calling UIApplication.unregisterForRemoteNotifications() in your app.

For example:

1UIApplication.shared.unregisterForRemoteNotifications()
2
3Task {
4 guard
5 let deviceID = UIDevice.current.identifierForVendor?.uuidString
6 else {
7 return
8 }
9
10 await DevRev.unregisterDevice(deviceID)
11}

Handle push notifications

Push notifications coming to the DevRev SDK need to be handled manually. To properly handle them, implement the following method, typically in either the UNUserNotificationCenterDelegate.userNotificationCenter(_:didReceive:) or UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:):

1DevRev.processPushNotification(_:)

For convenience, this method provides two overloads that accept userInfo as either [AnyHashable: Any] or [String: any Sendable] dictionary types.

For example:

1func userNotificationCenter(
2 _ center: UNUserNotificationCenter,
3 didReceive response: UNNotificationResponse
4) async {
5 await DevRev.processPushNotification(response.notification.request.content.userInfo)
6}