React Native integration

This section describes the process of integrating PLuG using the DevRev SDK with your React Native app.

Installation

To install the DevRev SDK, run the following command:

1npm install @devrev/sdk-react-native

Set up the DevRev SDK

In DevRev, go to Settings > PLuG Chat copy the value under Your unique App ID. After obtaining the credentials, you can configure the DevRev SDK in your app.

The DevRev SDK must be configured before you can use any of its features.

The SDK will be ready for use once you execute the following configuration method.

1DevRev.configure(appID: string)

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.

On iOS, 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:

Anonymous identification

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

Unverified identification

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

1DevRev.identifyUnverifiedUser(userID: string, organizationID?: string)

Update the user

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

1DevRev.updateUser(identity: Identity)

The userID property cannot be updated.

PLuG support chat

Once user identification is complete, you can start using the chat (conversations) dialog supported by our DevRev SDK. The support chat feature can be shown as a modal screen from the top-most screen. 

This functionality requires the SDK to be configured and the user to be identified, whether they are unverified or anonymous.

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

1DevRev.showSupport()

Creating a new support conversation

You can initiate a new support conversation directly from your app. This method displays the support chat screen and simultaneously creates a new conversation.

1DevRev.createSupportConversation()

In some instances, links opened from the support chat are displayed within the app rather than in a browser. You can manage whether the chat modal should close after a link is opened by using the following method:

1DevRev.setShouldDismissModalsOnOpenLink(value: boolean)

Setting this flag to true applies the system’s default behavior for opening links, which includes dismissing any DevRev modal screens to facilitate handling your own deep links.

This functionality is for Android only.

For scenarios where custom handling is needed, links from the support chat can be captured with the following method:

1DevRevSDK.setInAppLinkHandler((url) => {
2 // Perform an action here.
3});

If a custom handler is not defined, all external and in-app links from the support chat will open using the system’s default browser, such as Chrome.

Analytics

The DevRev SDK allows you to send custom analytic events by using a properties map. You can track these events using the following function:

This functionality requires the SDK to be configured and the user to be identified, whether they are unverified or anonymous.

1DevRev.trackEvent(name: string, properties?: Map<string, string>)

Session analytics

The DevRev SDK offers session analytics features to help you understand how users interact with your app.

Opting-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.

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 map of string values.

1DevRev.addSessionProperties(properties: Map<string, string>)

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(tags: any[])

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

1DevRev.unmarkSensitiveViews(tags: any[])

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 utilizes balanced start and stop methods, both of which accept a timer name and an optional dictionary of properties.

To start a timer, use the following method:

1DevRev.startTimer(name: string, properties: Map<string, string>)

To stop a timer, use the following method:

1DevRev.stopTimer(name: string, properties: Map<string, string>)

Screen tracking

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.trackScreen(name: string)

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 alert 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.

Register for push notifications

Push notifications require SDK configuration and user identification, whether unverified or anonymous, to ensure delivery 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:

1DevRevSDK.registerDeviceToken(deviceToken: string, deviceID: string)

On Android devices, the deviceToken should be the Firebase Cloud Messaging (FCM) token value, while on iOS devices, it should be the Apple Push Notification Service (APNS) token.

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:

1DevRevSDK.unregisterDevice(deviceID: string)

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

Processing push notifications

Android

On Android, notifications are implemented as data messages to offer flexibility. However, this means that automatic click processing isn’t available. To handle notification clicks, developers need to intercept the click event, extract the payload, and pass it to a designated method for processing. This custom approach enables tailored notification handling in Android applications.

To process the notification, use the following method:

1DevRevSDK.processPushNotification(payload: string)

Here, the message object from the notification payload should be passed to this function.

For example:

1const notificationPayload = {
2 // message may be nested based on the notification library
3 "message": {
4 // ... (the entire message object)
5 }
6};
7const messageJson = notificationPayload["message"];
8DevRevSDK.processPushNotification(JSON.stringify(messageJson));

iOS

On iOS devices, you must pass the received push notification payload to the DevRev SDK for processing. The SDK will then handle the notification and execute the necessary actions.

1DevRevSDK.processPushNotification(payload: string)

For example:

1DevRevSDK.processPushNotification(JSON.stringify(payload));

License

Apache 2.0