Skip to content

Commit

Permalink
Create sdk-react-native.mdx (#127)
Browse files Browse the repository at this point in the history
* Create sdk-react-native.mdx

no-work-item

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update public.yml

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-react-native.mdx

* Update sdk-intro.mdx

* Update sdk-intro.mdx
  • Loading branch information
Atul-Butola authored Dec 20, 2024
1 parent ca43173 commit f591492
Show file tree
Hide file tree
Showing 3 changed files with 310 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fern/docs/pages/plug-sdk/sdk-intro.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
The PLuG widget SDK is a powerful tool designed to further enhance our widget on your website or application. With the PLuG SDK, you can integrate DevRev's feature-rich widget, allowing you to create a dynamic and personalized user experience.

Before you dive into customization, take a quick detour to explore [methods](./methods) – they'll lay the groundwork for smooth customer interactions and effortless support using PLuG.

![plug](../../img/plug.gif)
Expand All @@ -15,4 +16,10 @@ Before you dive into customization, take a quick detour to explore [methods](./m
icon="fa-brands fa-apple"
href="/sdks/mobile/ios"
/>

<Card
title="Integrate PLuG with your React Native app"
href="/sdks/mobile/react-native"
/>

</Cards>
300 changes: 300 additions & 0 deletions fern/docs/pages/plug-sdk/sdk-react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
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:

```sh
npm 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.

<Callout intent="note">
The DevRev SDK must be configured before you can use any of its features.
</Callout>

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

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

<Callout intent="note">
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.
</Callout>

<Callout intent="note">
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](https://devrev.ai/docs/product/object-customization).
</Callout>

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.

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

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

### Update the user

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

```typescript
DevRev.updateUser(identity: Identity)
```

<Callout intent="note">
The `userID` property cannot be updated.
</Callout>

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

<Callout intent="note">
This functionality requires the SDK to be configured and the user to be identified, whether they are unverified or anonymous.
</Callout>

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

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

```typescript
DevRev.createSupportConversation()
```

### In-app link handling

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:

```typescript
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.

### In-app link callback

<Callout intent="note">
This functionality is for Android only.
</Callout>

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

```typescript
DevRevSDK.setInAppLinkHandler((url) => {
// Perform an action here.
});
```

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:

<Callout intent="note">
This functionality requires the SDK to be configured and the user to be identified, whether they are unverified or anonymous.
</Callout>

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

```typescript
DevRev.stopAllMonitoring()
```

To opt back in, use the following method:

```typescript
DevRev.resumeAllMonitoring()
```

### Session recording

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

<Callout intent="note">
The session recording feature is opt-out and is enabled by default.
</Callout>

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

| Method | Action |
|--------------------------------------------------------------------|-----------------------------------------------------------|
|`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.

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

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

```typescript
DevRev.markSensitiveViews(tags: any[])
```

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

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

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

To stop a timer, use the following method:

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

```typescript
DevRev.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](./push-notification) section.

### Register for push notifications

<Callout intent="note">
Push notifications require SDK configuration and user identification, whether unverified or anonymous, to ensure delivery to the correct user.
</Callout>

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

```typescript
DevRevSDK.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:

```typescript
DevRevSDK.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:

```typescript
DevRevSDK.processPushNotification(payload: string)
```

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

For example:

```typescript
const notificationPayload = {
// message may be nested based on the notification library
"message": {
// ... (the entire message object)
}
};
const messageJson = notificationPayload["message"];
DevRevSDK.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.

```typescript
DevRevSDK.processPushNotification(payload: string)
```

For example:

```typescript
DevRevSDK.processPushNotification(JSON.stringify(payload));
```

## License

Apache 2.0

3 changes: 3 additions & 0 deletions fern/versions/public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ navigation:
- page: iOS integration
slug: ios
path: ../docs/pages/plug-sdk/sdk-ios.mdx
- page: React Native integration
slug: react-native
path: ../docs/pages/plug-sdk/sdk-react-native.mdx
- page: Push notifications
slug: push-notification
path: ../docs/pages/plug-sdk/push-notification.mdx
Expand Down

0 comments on commit f591492

Please sign in to comment.