Skip to content

Update methods.mdx #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Oct 10, 2024
Merged
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
38c00b9
Update methods.mdx
Atul-Butola Aug 29, 2024
283eacf
Update methods.mdx
Atul-Butola Aug 29, 2024
ffc5047
Update methods.mdx
Atul-Butola Aug 29, 2024
b3f6a30
Update methods.mdx
Atul-Butola Aug 29, 2024
1b7b88c
Update methods.mdx
Atul-Butola Sep 9, 2024
abeba81
Update methods.mdx
Atul-Butola Sep 9, 2024
3bf6d3d
Update methods.mdx
Atul-Butola Sep 9, 2024
dc9ece0
Update methods.mdx
Atul-Butola Sep 9, 2024
7ce8f73
Update methods.mdx
Atul-Butola Sep 9, 2024
288a9d0
Merge branch 'main' into SDK-methods
Atul-Butola Sep 13, 2024
3cd5fd6
Update methods.mdx
Atul-Butola Sep 13, 2024
72dd608
Update methods.mdx
Atul-Butola Sep 13, 2024
5c70088
Update methods.mdx
nikhiltidke101 Sep 13, 2024
d743484
Update methods.mdx
bc-devrev Sep 13, 2024
5b7e8d4
fixed spelling and capitalization
bc-devrev Sep 13, 2024
60736a4
Fern upgrade
bc-devrev Sep 13, 2024
d781684
tagged code phrase
bc-devrev Sep 13, 2024
a5698c7
Revert "Fern upgrade"
bc-devrev Sep 16, 2024
679d52e
Update methods.mdx
Atul-Butola Sep 17, 2024
3c02c23
Merge branch 'main' into SDK-methods
bc-devrev Sep 17, 2024
f27f417
Update methods.mdx
Atul-Butola Sep 23, 2024
351c61c
Merge branch 'main' into SDK-methods
Atul-Butola Sep 23, 2024
cc60401
Update methods.mdx
Atul-Butola Sep 23, 2024
ff6cf2b
Update methods.mdx
Atul-Butola Sep 23, 2024
4a50d23
Update methods.mdx
Atul-Butola Sep 23, 2024
6ffbc33
Update methods.mdx
Atul-Butola Sep 23, 2024
83b1474
Update methods.mdx
Atul-Butola Oct 1, 2024
f391a66
Merge branch 'main' into SDK-methods
Atul-Butola Oct 1, 2024
5ec043e
Update methods.mdx
Atul-Butola Oct 1, 2024
a37274c
Update methods.mdx
Atul-Butola Oct 1, 2024
0a333fd
Update methods.mdx
Atul-Butola Oct 9, 2024
7e0309b
Update methods.mdx
Atul-Butola Oct 9, 2024
4dea131
Update methods.mdx
Atul-Butola Oct 9, 2024
a003537
Update methods.mdx
Atul-Butola Oct 9, 2024
e818634
Update methods.mdx
Atul-Butola Oct 9, 2024
84c7a72
Update methods.mdx
Atul-Butola Oct 9, 2024
31c1e84
Merge branch 'main' into SDK-methods
Atul-Butola Oct 9, 2024
faa801a
Update methods.mdx
Atul-Butola Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 135 additions & 82 deletions fern/docs/pages/plug-sdk/methods.mdx
Original file line number Diff line number Diff line change
@@ -1,146 +1,199 @@
Our PLuG widget SDK is a powerful tool to further enhance our widget on your website or application. With our SDK, you are empowered to create a dynamic and personalized user experience. Let's get started.
The PLuG SDK is a robust tool designed to elevate your website or application by enhancing our widget’s capabilities. With our SDK, you can integrate our feature-rich widget, creating a dynamic and personalized user experience.

## Methods

- `plugSDK.init()` Initialize the PLuG chat widget.
## Initialize SDK

- `plugSDK.initSearchAgent()` Initialize PLuG search agent.
To get started with the PLuG SDK on your website, call the `init()` method. This method is essential for enabling the SDK’s functionality, including session recording, the chat widget, and the search agent. Initialization is required before you can perform any other actions using the PLuG SDK.

- `plugSDK.shutdown()` End the user session which is currently initialized in PLuG widget.
```jsx
useEffect(() => {
window.plugSDK.init({
app_id: <your_unique_app_id>,
});
}, []);
```
The `init()` method can accept multiple inputs, which are explained below:

|Input parameter |Description |Values |
|---|---|---|
|`app_id` |This is the unique identifier for your PLuG SDK. This is a mandatory parameter. |String |
|`disable_plug_chat_window` |The chat widget is enabled by default. Use this option if you want to disable the chat widget. |Boolean (True or False) |
|`enable_default_launcher` |Show/hide the default PLuG widget launcher. |Boolean (True or False) |
|`session_recording_key` |This key identifies your session recording account and is required to enable the PLuG SDK session recording features. |String |
|`enable_session_recording` |This instructs the widget to determine whether to start the session recording. |Boolean (True or False) |
|`session_token` |This unique token identifies the user interacting with your app. |String |
|`primary_text_color` |This determines the launcher color, button text for new tickets and conversations, conversation user text, and more. It should be a valid hex code, such as #f0f0f0. |String |
|`session_recording_options` |Options for recording observability sessions. |To view the values, see [Session recording options](https://devrev.ai/docs/plug/session-recording) |
|`accent_color` |The accent color of the PLuG affects the launcher, new ticket and conversation buttons, conversation user text, and more. |String |
|`custom_launcher_selector` |A CSS selector string is used to match the element to which the widget will be attached. You can also set this selector from the PLuG settings on app.devrev.ai. If both sources are set, this value will be considered the definitive source. |Boolean (True or False) |
|`spacing` |Padding from the launcher: This padding can also be set in the plug settings on app.devrev.ai. If a value is specified in both places, this value will be considered the definitive source. Bottom: Padding from the bottom of the launcher. Side: Spacing from the sides of the launcher |object `{bottom: string; side: string;}` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [EkLine] reported by reviewdog 🐶

Suggestions:

  • Use 'DevRev' instead of 'devrev'. (EK25050)
  • Where possible, do not structure sentences in future tense. Use present tense instead. (EK00005)

Suggested change
|`custom_launcher_selector` |A CSS selector string is used to match the element to which the widget will be attached. You can also set this selector from the PLuG settings on app.devrev.ai. If both sources are set, this value will be considered the definitive source. |Boolean (True or False) |
|`custom_launcher_selector` |A CSS selector string is used to match the element to which the widget attaches. You can also set this selector from the PLuG settings on app.DevRev.ai. If both sources are set, this value is considered the definitive source. |Boolean (True or False) |

|`theme` |The color scheme for the launcher and widget. |light or dark |
|`widget_alignment` |The PLuG widget can be positioned on either the left or right side of the launcher. You can also adjust the widget alignment through the plug settings at app.devrev.ai. If alignment settings are configured in both places, the value from app.devrev.ai will override the launcher setting. |left or right |

<Callout intent="note">
When React is in Strict mode, you may receive a warning about `window.plugSDK.init()` being called multiple times. These warnings do not affect the widget's installation or functionality.
</Callout>

- `plugSDK.toggleWidget()` Open/close the chat widget.
## Toggle widget theme

- `plugSDK.toggleSearchAgent()` Open/close the search agent.
The toggle theme method lets you dynamically adjust the PLuG SDK’s theme, even after the widget has been initialized. This feature allows for real-time theme changes based on your users' preferences.

- `plugSDK.onEvent()` Perform specific actions based on the payload type received from the PLuG widget.
The method accepts the input options: `light` and `dark`.

- `plugSDK.toggleTheme('light/dark')` Toggle PLuG widget theme.
```jsx
window.plugSDK.toggleTheme('light | dark');
```

- `plugSDK.toggleWidget(true, 'create_conversation', {startConversationContent: 'Hi',});` Start a conversation.
The parameter is optional; calling `toggleTheme()` will switch between the current themes. Specifying a theme as a parameter allows you to toggle directly to that specific theme.

- `plugSDK.prefillSearchQuery(query:"string")` Prefill the search input of the search agent.
<Callout intent="note">
The theme specified in this method takes precedence over the theme configured in the PLuG settings in your DevRev app.
</Callout>

## Initialize chat
## Toggle widget

Calling the `init()` method initializes the PLuG chat widget on your website. Initializing the PLuG widget is necessary for you to perform any other actions on the PLuG widget SDK.
The `toggleWidget` method allows you to control the visibility of the PLuG chat widget.

```jsx
useEffect(() => {
window.plugSDK.init({
app_id: <your_unique_app_id>,
});
}, []);
```
Passing input = true opens the chat widget.

<Callout intent="info">
When React is using `Strict` mode, you might get a warning message from `window.plugSDK.init()` being called multiple times. These errors won't impact the installation and functioning of the widget.
</Callout>
Passing input = false closes the chat widget.

## Initialize search
```jsx
window.plugSDK.toggleWidget(true);
```

Calling the `initSearchAgent()` method initializes the PLuG Search agent on your website. Initializing search is necessary for you to perform any other actions on the PLuG widget SDK.
## Take action from PLuG chat events

This method allows you to listen for events from the PLuG widget. Below are the available `PAYLOAD_TYPES`.
- `ON_PLUG_WIDGET_CLOSED`: Triggered when the PLuG widget is closed.
- `ON_PLUG_WIDGET_OPENED`: Triggered when the PLuG widget is opened.
- `ON_PLUG_WIDGET_READY`: Triggered when the PLuG widget is ready.
- `ON_PLUG_WIDGET_UNREAD_COUNT_CHANGE`: Triggered when the user receives a new message. You can also track the number of unread messages and display them to the user.
- `ON_CONVERSATION_START`: Indicates that the user has started a new conversation.
- `ON_SEARCH_AGENT_QUERY`: Indicates that a new search query has been made in the PLuG search agent.
- `ON_OBSERVABILITY_READY`: Triggered when the session analytics capabilities of PLuG are initialized.

```jsx
useEffect(() => {
window.plugSDK.init({
app_id: '<your_unique_app_id>',
disable_plug_chat_window: true,
});

window.plugSDK.onEvent((payload) => {
if (payload.type === 'ON_PLUG_WIDGET_READY') {
window.plugSDK.initSearchAgent();
if (payload.type === PAYLOAD_TYPE) {
//Your logic goes here
}
});
}, []);
```

## Shutdown the widget
## Check widget status

The `shutdown()` method is helpful when you want to end the user session which is currently initialized in the PLuG widget. You can use this method to clear your users' conversations and tickets when they log out of your application.
Use `isWidgetOpen` to determine whether your chat widget is currently open or closed.

```jsx
await window.plugSDK.shutdown();
window.plugSDK.isWidgetOpen
```

After calling the `shutdown()` method, you can call the `init()` method to reinitialize PLuG widget on your website if you wish to showcase the PLuG widget again in the logged out version of your application.
This returns true if the chat widget is open and false if it is closed.

<Callout intent="info">
Once the `shutdown()` method is called, all the other functionality in the widget such as session recording or Nudges is also be stopped. You need to reinitialize the widget again to have these features active.
</Callout>

<iframe src="https://codesandbox.io/embed/shutdown-plug-sdk-sstn8g?fontsize=14&hidenavigation=1&theme=dark"
style={{width:'100%', height:'600px', border:'0', borderRadius: '4px', overflow:'hidden',}}
title="Toggle_Plug_with_Button"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
## Start conversation

## Open or close the widget
The `startConversationContent` method opens the PLuG widget directly to the conversation creation view. It replicates the action of clicking the **Send us a message** button, launching the widget to the conversation initiation screen.

To control whether the PLuG widget launcher screen is open, you should use either the `togglewidget()` method with a boolean value or the `toggleSearchAgent()` method, depending on which PLuG instance you are using.
This method also accepts an optional input parameter to pre-fill a message on the conversation creation screen, providing your users with a prompt to start a conversation with your team.

```jsx
window.plugSDK.toggleWidget(true);
window.plugSDK.toggleSearchAgent(true);
plugSDK.toggleWidget(true, 'create_conversation', {
startConversationContent: 'Hi',
});
```

<iframe src="https://codesandbox.io/embed/toggle-plug-with-button-nnkmk3?fontsize=14&hidenavigation=1&module=%2Fsrc%2FTogglePlug.js&theme=dark&view=preview&hidedevtools=1"
style={{width:'100%', height:'600px', border:'0', borderRadius: '4px', overflow:'hidden',}}
title="Toggle_Plug_with_Button"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
## Shutdown

## Take actions from events
The `shutdown()` method is used to end the current user session in the PLuG widget. It allows you to clear users' conversations and tickets when they log out of your application.

This method can be used to listen to events coming from the PLuG widget. The following are the different `PAYLOAD_TYPES`.
```jsx
await window.plugSDK.shutdown();
```
After calling the `shutdown()` method, you can use the `init()` method to reinitialize the PLuG widget on your website if you want to display it again in the logged-out version of your application.

- `ON_PLUG_WIDGET_CLOSED` The PLuG widget is closed.
<Callout intent="note">
Once the `shutdown()` method is called, all other widget functionalities, such as session recording and Nudges, will also be stopped. You will need to reinitialize the widget to reactivate these features.
</Callout>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [EkLine] reported by reviewdog 🐶

Suggestions:

    Where possible, do not structure sentences in future tense. Use present tense instead. (EK00005)

Suggested change
Once the `shutdown()` method is called, all other widget functionalities, such as session recording and Nudges, will also be stopped. You will need to reinitialize the widget to reactivate these features.
Once the `shutdown()` method is called, all other widget functionalities, such as session recording and Nudges, also stop. You need to reinitialize the widget to reactivate these features.


- `ON_PLUG_WIDGET_OPENED` The PLuG widget is opened.
## Initialize the search agent

- `ON_PLUG_WIDGET_READY` The PLuG widget is ready.
-
- `ON_PLUG_WIDGET_UNREAD_COUNT_CHANGE` The user receives a new message to their PLuG. You can also listen to the number of unread messages and display that to your user.
Calling the `initSearchAgent()` method sets up the PLuG search agent on your website. This initialization is required before performing any other actions with the PLuG widget SDK.

```jsx
useEffect(() => {
window.plugSDK.init({
app_id: '<your_unique_app_id>',
disable_plug_chat_window: true,
});

window.plugSDK.onEvent((payload) => {
if (payload.type === PAYLOAD_TYPE) {
//Your logic goes here
if (payload.type === 'ON_PLUG_WIDGET_READY') {
window.plugSDK.initSearchAgent();
}
});
}, []);
```

<iframe src="https://codesandbox.io/embed/events-rendered-7rhzj7?fontsize=14&hidenavigation=1&module=%2Fsrc%2FOnEvents.js&theme=dark&view=preview&hidedevtools=1"
style={{width:'100%', height:'600px', border:'0', borderRadius: '4px', overflow:'hidden',}}
title="Events_Rendered"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
## Toggle search agent

## Toggle theme
The `toggleSearchAgent` method allows you to control the visibility of the search agent.

The toggle theme method allows you to dynamically modify the PLuG SDK's theme, even after initializing the PLuG widget. This functionality enables real-time adjustments to the PLuG widget's theme based on diverse themes preferred by your users.
If no input is provided, the method toggles the search bar: opening it if it's closed, and closing it if it's open.

The method accepts two inputs: `light` and `dark`.
```jsx
window.plugSDK.toggleTheme('light | dark');
window.plugSDK.toggleSearchAgent(true);
```
The parameter is optional; calling `toggleTheme()` toggles the current theme, and specifying a theme as a parameter allows toggling for that specific theme.

## Start conversation
## Prefill search query in search agent

Use the `prefillSearchQuery` method to prefill a search query when opening and initializing the search agent.

This method is utilized to open the PLuG widget with the conversation creation view activated. It essentially replicates the action of clicking the **Send us a message** button, launching the widget directly to the conversation initiation screen.
```jsx
window.plugSDK.prefillSearchQuery("search_query");
```

## Add session properties

The method also accepts an optional input parameter, allowing you to pre-fill a message in the conversation creation screen. This provides your users with a prompt to initiate a conversation with your team.
The `addSessionProperties` method is used to add properties to the session in the form of a key-value map.

```jsx
plugSDK.toggleWidget(true, 'create_conversation', {
startConversationContent: 'Hi',
});
window.plugSDK.addSessionProperties({
city: 'Bengaluru',
region: 'us-east'
});
```

## Track events

To track user events using PLuG, utilize the `trackEvent` method available in the PLuG SDK. This method automatically links the event to the active user profile within the widget. For more details on user identification within the PLuG widget, refer to [Identify your users with PLuG](https://devrev.ai/docs/plug/identify-web-user).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [EkLine] reported by reviewdog 🐶

Confirm the link. The URL 'https://devrev.ai/docs/plug/identify-web-user' seems inaccessible with error code 404. It might be incorrect or improperly formatted. (EK20001)

```jsx
window.plugSDK.trackEvent(event_name, properties)
```

Looking for something more? Reach out to us through our own PLuG widget in the bottom right of this screen and we would be happy to assist you.
Sample code:

```jsx
// Sample code for the trackEvent method:
var properties = {
"name" : "John Doe",
"plan" : "Starter",
"payment_method" : "Credit Card",
"expiry_date" : "2024-12-12"
}
window.plugSDK.trackEvent("signed_up",properties)
```

To learn more about tracking events, visit [Track events](/plug-sdk/track-events).

## Restart session recording

The `restartSessionRecording` method is used to restart session recording.

```jsx
window.plugSDK.restartSessionRecording();
```
Loading