@devrev/sdk-react-native

中文文档
2.3.12发布于 2026/10/23Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 3.1万

DevRev SDK, used for integrating DevRev services into your React Native app.

原始使用文档
文档目录19 节
  1. Quickstart
  2. Requirements
  3. Installation
  4. Set up the DevRev SDK
  5. Features
  6. Identification
  7. Identity model
  8. Support chat
  9. In-app link handling
  10. In-app link callback
  11. Dynamic theme configuration
  12. Analytics
  13. Session analytics
  14. Push notifications
  15. Sample app (without framework)
  16. Sample app (Expo)
  17. Troubleshooting
  18. ProGuard (Android only)
  19. Migration Guide

DevRev SDK for React Native and Expo

DevRev SDK, used for integrating DevRev services into your React Native and Expo apps.

Quickstart

Requirements

  • React Native 0.79.0 or later.
  • For Expo apps, Expo 50.0.0 or later.
  • Android: minimum API level 24.
  • iOS: minimum deployment target 15.1.

Installation

To install the DevRev SDK, run the following command:

npm install @devrev/sdk-react-native

Expo

  1. To install the DevRev SDK, run the following command:
    npx expo install @devrev/sdk-react-native-expo-plugin
    
  2. Configure the Expo config plugin in your app.json or app.config.js:
    {
      "expo": {
        "plugins": [
          "@devrev/sdk-react-native-expo-plugin"
        ]
      }
    }
    
  3. Rebuild your app:
    npx expo prebuild --clean
    

Set up the DevRev SDK

  1. Open the DevRev web app at https://app.devrev.ai and go to the Settings page.
  2. Under PLuG settings copy the value under Your unique App ID.
  3. Configure the DevRev SDK in your app using the obtained credentials.

[!WARNING] The DevRev SDK must be configured before you can use any of its features.

The SDK becomes ready for use once the configuration API is executed.

DevRev.configure(appID)

To provide a feature configuration during setup, call the overload that accepts it:

DevRev.configure(appID, featureConfiguration)

For default behavior, call the simpler form:

DevRev.configure('abcdefg12345')

To customize behavior such as frame capture, auto-start recording, or theme preferences, pass a full FeatureConfiguration object:

DevRev.configure('abcdefg12345', {
  enableFrameCapture: false,
  autoStartRecording: false,
  prefersDialogMode: false,
  alwaysUseRemoteConfig: true,
  supportWidgetTheme: {
    prefersSystemTheme: true,
  },
  enableSupportChatStreaming: true,
  supportWidgetArticleSearchFilters: articleSearchFilters,
});

Update the feature configuration

You can adjust the feature configuration without reconfiguring the SDK. Pass a full FeatureConfiguration object (all properties are required):

DevRev.updateFeatureConfiguration({
  enableFrameCapture: true,
  autoStartRecording: true,
  prefersDialogMode: false,
  alwaysUseRemoteConfig: true,
  supportWidgetTheme: {
    prefersSystemTheme: true,
  },
  enableSupportChatStreaming: true,
  supportWidgetArticleSearchFilters: articleSearchFilters,
});

Feature configuration reference

FeatureConfiguration controls how the SDK behaves both during initial setup and when calling DevRev.updateFeatureConfiguration(...). All properties are required when providing a feature configuration.

PropertyTypeDefaultDescription
enableFrameCapturebooleantrueEnables the screen capture pipeline used by session replay.
autoStartRecordingbooleantrueAutomatically starts recording after the SDK finishes remote configuration.
prefersDialogModebooleanfalsePrefer dialog mode for the support UI (Android only).
alwaysUseRemoteConfigbooleantrueAlways use remote config.
supportWidgetThemeSupportWidgetTheme—Controls the appearance of the in-app support widget, including dynamic theme behavior.
enableSupportChatStreamingboolean?falseWhen true, enables real-time AI agent response streaming in PLuG conversations (WebSocket streaming, optimistic UI, animated text).
supportWidgetArticleSearchFiltersArticleSearchFilters?—Optional filters for PLuG article search (widget and CMDK). Applied automatically when the support widget is ready.
Support widget theme options

SupportWidgetTheme lets you fine-tune the support UI. Use the supportWidgetTheme property inside your feature configuration.

const customTheme = {
  prefersSystemTheme: false,
  primaryTextColor: '#1F2933',
  accentColor: '#F97316',
  spacing: {
    bottom: '20px',
    side: '16px',
  },
  conversationPageOptions: {
    headerText: 'Support',
    subheaderText: 'We typically reply in a few minutes',
  },
};
PropertyTypeDefaultDescription
prefersSystemThemebooleantrueFollows the device appearance when true; otherwise uses your custom colors.
primaryTextColorstring?—Hex color string (e.g. '#000000', '#1F2933') for primary text in the support widget.
accentColorstring?—Hex color string (e.g. '#F97316', '#FF0000') applied to buttons and highlights.
spacing{ [key: string]: string }?—CSS-like spacing overrides (bottom and side keys are recognized).
conversationPageOptionsConversationPageOptions?—Customizes the conversation page header branding.
Conversation page options

ConversationPageOptions customizes the header strings shown on the support conversation page. Both fields are optional — when omitted, the server-configured defaults are used.

PropertyTypeDefaultDescription
headerTextstring?—Custom text for the conversation header.
subheaderTextstring?—Custom text for the conversation subheader. Pass a single space (' ') to render a blank subheader.

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

[!TIP] 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.

[!TIP] 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 used. For more information, refer to Object customization.

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

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.

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

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.

[!WARNING] 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.

[!WARNING] 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:

[!WARNING] 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.

[!WARNING] 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:

DevRev.identifyVerifiedUser(userID: string, sessionToken: string)

Update the user

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

DevRev.updateUser(identity: Identity)

[!WARNING] The userID property cannot be updated.

Logout

You can logout of the current user by using the following method:

DevRev.logout(deviceID: string)

Identity model

The Identity interface 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
userRefstring✅A unique identifier for the user
organizationRefstring?❌An identifier for the user's organization
accountRefstring?❌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

[!NOTE] 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:

[!NOTE] 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
descriptionstring?A description of the user
customFields{ [key: string]: any }Dictionary of custom fields configured in DevRev
Organization traits

The OrganizationTraits class contains detailed information about the organization:

[!NOTE] All properties in OrganizationTraits are optional.

PropertyTypeDescription
displayNamestring?The displayed name of the organization
domainstring?The organization's domain
descriptionstring?A description of the organization
phoneNumbersstring[]?Array of the organization's phone numbers
tierstring?The organization's tier or plan level
customFields{ [key: string]: any }Dictionary of custom fields configured in DevRev
Account traits

The AccountTraits class contains detailed information about the account:

[!NOTE] All properties in AccountTraits are optional.

PropertyTypeDescription
displayNamestring?The displayed name of the account
domainsstring[]?Array of domains associated with the account
descriptionstring?A description of the account
phoneNumbersstring[]?Array of the account's phone numbers
websitesstring[]?Array of websites associated with the account
tierstring?The account's tier or plan level
customFields{ [key: string]: any }Dictionary of custom fields configured in DevRev

Support chat

Once the 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.

DevRev.showSupport()

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

DevRev.createSupportConversation(prefillMessage?: string)

You can optionally pass a plain-text message to prefill the conversation input field:

DevRev.createSupportConversation('I need help with billing for order #12345')

In certain cases, the links opened from the support chat are opened in the app instead of a browser. You can control whether the chat modal should be dismissed after the link is opened by calling the following method:

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

[!TIP] This feature is supported only on Android.

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

DevRev.setInAppLinkHandler((url) => {
    // Perform an action here.
});

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.

DevRev.setPrefersSystemTheme(value: boolean)

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:

DevRev.trackEvent(name: string, properties?: { [key: string]: string })

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:

DevRev.stopAllMonitoring()

To opt back in, use the following method:

DevRev.resumeAllMonitoring()

Session recording

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

[!NOTE] 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()Stops 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.

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.

DevRev.addSessionProperties(properties: { [key: string]: string })

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

DevRev.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 password text fields are automatically masked.

While the auto-masking feature is sufficient for most situations, you can manually mark additional views as sensitive using the following method:

DevRev.markSensitiveViews(tags: any[])

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

DevRev.unmarkSensitiveViews(tags: any[])

For example:

import * as DevRev from '@devrev/sdk-react-native';
import { View, Text, findNodeHandle } from "react-native";
import { useRef, useEffect } from "react";

const YourComponent = () => {
  const sensitiveViewRef = useRef(null);
  const insensitiveViewRef = useRef(null);

  useEffect(() => {
    // Mark sensitive view
    const sensitiveId = findNodeHandle(sensitiveViewRef.current);
    if (sensitiveId) {
      DevRev.markSensitiveViews([sensitiveId]);
    }

    // Unmark insensitive view
    const insensitiveId = findNodeHandle(insensitiveViewRef.current);
    if (insensitiveId) {
      DevRev.unmarkSensitiveViews([insensitiveId]);
    }
  }, []);

  return (
    <View>
      <View ref={sensitiveViewRef}>
        <Text>Sensitive content (masked in recordings)</Text>
      </View>
      <View ref={insensitiveViewRef}>
        <Text>Insensitive content (visible in recordings)</Text>
      </View>
    </View>
  );
};

export default YourComponent;

Mask elements inside web views

To mark elements as sensitive inside a web view (WebView), apply the devrev-mask CSS class. To unmark them, use devrev-unmask.

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

User interaction tracking

The DevRev SDK automatically tracks user interactions such as taps, swipes, and scrolls. However, in some cases you may want to disable this tracking to prevent sensitive user actions from being recorded.

To temporarily disable user interaction tracking, use the following method:

DevRev.pauseUserInteractionTracking()

To resume user interaction tracking, use the following method:

DevRev.resumeUserInteractionTracking()

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 uses 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:

DevRev.startTimer(name: string, properties: { [key: string]: string })

To stop a timer, use the following method:

DevRev.endTimer(name: string, properties: { [key: string]: string })

Capture errors

You can report a handled error from a catch block using the captureError function.

This ensures that even if the error is handled in your app, it will still be logged for diagnostics.

DevRev.captureError(
    error: Error | string,
    tag: string
)

Example:

try {
} catch (error) {
    DevRev.captureError(
        error,
        'network-failure'
    );
}

Example with Error:

try {
    throw new Error('Something went wrong');
} catch (error) {
    DevRev.captureError(error, 'custom-error');
}

Track screens

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

DevRev.trackScreenName(name: string)

Manage screen transitions (Android only)

The DevRev SDK allows tracking of screen transitions to understand the user navigation within your app. You can manually update the state using the following methods:

// Mark the transition as started.
DevRev.setInScreenTransitioning(true)

// Mark the transition as ended.
DevRev.setInScreenTransitioning(false)

Push notifications

You can configure your app to receive push notifications from the DevRev SDK. The SDK is able 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 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

[!TIP] Push notifications require that the SDK has been configured and the user has been identified, 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:

DevRev.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:

DevRev.unregisterDevice(deviceID: string)

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

Handle 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:

DevRev.processPushNotification(payload: string)

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

For example:

const notificationPayload = {
    // message may be nested based on the notification library
    "message": {
        // ... (the entire message object)
    }
};
const messageJson = notificationPayload["message"];
DevRev.processPushNotification(JSON.stringify(messageJson));
iOS

On iOS, the AppDelegate must be updated to intercept notification clicks and forward the payload to the SDK.

In didFinishLaunchingWithOptions, set the UNUserNotificationCenter delegate:

UNUserNotificationCenter.current().delegate = self

Implement userNotificationCenter(_:didReceive:) to pass the notification payload to the SDK:

func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse
) async {
    await DevRev.processPushNotification(
        response.notification.request.content.userInfo
    )
}

Sample app (without framework)

A sample app with use cases for the DevRev SDK for React Native has been provided as a part of our public repository. To set up and run the sample app, follow these steps:

  1. Go to the sample directory:
    cd sample/react-native
    
  2. Install the dependencies:
    yarn install
    
  3. For iOS, run:
    pod install --project-directory=ios --repo-update
    
  4. Start the React Native development server:
    npx react-native start
    
  5. Run the app on Android using:
    npx react-native run-android
    
    or open the android directory in Android Studio and run the app from there.
  6. Run the app on iOS using:
    npx react-native run-ios
    
    or open ios/DevRevSDKSampleRN.xcworkspace in Xcode and run the app from there.

Sample app (Expo)

A sample app with use cases for the DevRev SDK for Expo has been provided as a part of our public repository. To set up and run the sample app, follow these steps:

  1. Go to the sample directory:
    cd sample/expo
    
  2. Install the dependencies:
    yarn install
    
  3. Run clean and prebuild:
    npx expo prebuild --clean
    
  4. Run the app on Android using:
    npx expo run:android
    
    OR open the android directory in Android Studio and run the app.
  5. Run the app on iOS:
    npx expo run:ios
    
    OR open ios/DevRevSDKSample.xcworkspace in Xcode and run the app.

Troubleshooting

  • Issue: Support chat doesn't show. Solution: Ensure you have correctly called one of the identification methods: DevRev.identifyUnverifiedUser(...) or DevRev.identifyVerifiedUser(...).

  • Issue: Not receiving push notifications. Solution: Ensure that your app is configured to receive push notifications and that your device is registered with the DevRev SDK.

ProGuard (Android only)

When trying to build your app for Android with ProGuard enabled, refer to these common issues and their solutions.

[!NOTE] You can always refer to the Android ProGuard documentation for more information.

  • Issue: Missing class com.google.android.play.core.splitcompat.SplitCompatApplication. Solution: Add the following line to your proguard-rules.pro file:

    -dontwarn com.google.android.play.core.**
    
  • Issue: Missing class issue due to transitive Flutter dependencies. Solution: Add the following lines to your proguard-rules.pro file:

    -keep class io.flutter.** { *; }
    -keep class io.flutter.plugins.** { *; }
    -keep class GeneratedPluginRegistrant { *; }
    
  • Issue: Missing class org.s1f4j.impl.StaticLoggerBinder. Solution: Add the following line to your proguard-rules.pro file:

    -dontwarn org.slf4j.impl.StaticLoggerBinder
    

Migration Guide

If you are migrating from the legacy UserExperior SDK to the new DevRev SDK, please refer to the Migration Guide for detailed instructions and feature equivalence.

版本与发布记录

@devrev/sdk-react-native 共发布 45 个版本,首次发布于 2024/07/08;过去 12 个月发布了 19 个版本。

版本发布日期距今
2.3.12latest2026/10/2320 天前
2.3.112026/10/1329 天前
2.3.102026/09/042 个月前
2.3.92026/08/212 个月前
2.3.82026/08/053 个月前
2.3.72026/07/024 个月前

关于 @devrev/sdk-react-native 的常见问题

@devrev/sdk-react-native 是什么?

DevRev SDK, used for integrating DevRev services into your React Native app.

如何安装 @devrev/sdk-react-native?

在项目目录运行 npm install @devrev/sdk-react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-native(>=0.79.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devrev/sdk-react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devrev/sdk-react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@devrev/sdk-react-native 可以商用吗?

@devrev/sdk-react-native 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@devrev/sdk-react-native 的下载量有多少?

根据 npm 官方下载统计,@devrev/sdk-react-native 在 2026/10/12 – 2026/11/10 这 30 天内被下载 31,116 次,日均约 1,037 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devrev/sdk-react-native 还在维护吗?

最新版本 2.3.12 发布于 2026/10/23(20 天前);至今共发布 45 个版本,其中过去 12 个月发布了 19 个;首次发布于 2024/07/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。