Skip to content

Commit 0e1a788

Browse files
**WIP** method getSessionDetails() added (#194)
* method getSessionDetails() added * add isSearchAgentOpen method * minor updates * Fixed user identity link * Update user-identity.mdx set identifier without session token * Update search.mdx add bind hotkey example * Update search.mdx * Update user-identity.mdx * Update method descriptions for consistency * Update search.mdx * Update user-identity.mdx * Update search.mdx * Update user-identity.mdx Remove frontend id method --------- Co-authored-by: Atul-Butola <137884145+Atul-Butola@users.noreply.github.com> Co-authored-by: Atul-Butola <atul.butola@devrev.ai>
1 parent 9d1659b commit 0e1a788

File tree

2 files changed

+70
-11
lines changed

2 files changed

+70
-11
lines changed

fern/docs/pages/plug-sdk/web/methods.mdx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ Passing `false` closes the chat widget.
6161
window.plugSDK.toggleWidget(true);
6262
```
6363

64+
## Check widget status
65+
66+
Use `isWidgetOpen` to determine whether your chat widget is currently open or closed.
67+
68+
```jsx
69+
window.plugSDK.isWidgetOpen
70+
```
71+
72+
This returns `true` if the chat widget is open and `false` if it is closed.
73+
6474
## Take action from PLuG chat events
6575

6676
This method allows you to listen for events from the PLuG widget. Below are the available values for `PAYLOAD_TYPE`.
@@ -82,16 +92,6 @@ useEffect(() => {
8292
}, []);
8393
```
8494

85-
## Check widget status
86-
87-
Use `isWidgetOpen` to determine whether your chat widget is currently open or closed.
88-
89-
```jsx
90-
window.plugSDK.isWidgetOpen
91-
```
92-
93-
This returns true if the chat widget is open and false if it is closed.
94-
9595
## Start conversation
9696

9797
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.
@@ -146,6 +146,16 @@ If no input is provided, the method toggles the search bar: opening it if it's c
146146
window.plugSDK.toggleSearchAgent(true);
147147
```
148148

149+
## Check Search Agent status
150+
151+
Use `isSearchAgentOpen` to determine whether the search agent is currently open or closed.
152+
153+
```jsx
154+
window.plugSDK.isSearchAgentOpen
155+
```
156+
157+
This returns `true` if the search agent is open and `false` if it is closed.
158+
149159
## Prefill search query in search agent
150160

151161
Use the `prefillSearchQuery` method to prefill a search query when opening and initializing the search agent.
@@ -165,9 +175,17 @@ window.plugSDK.addSessionProperties({
165175
});
166176
```
167177

178+
## Get session details
179+
180+
You can use the `getSessionDetails` method to fetch the session ID and tab ID of currently ongoing session. These details can then be passed across different domains to maintain the journey as a single, continuous session.
181+
182+
```jsx
183+
const { sessionId, tabId } = window.plugSDK.getSessionDetails();
184+
```
185+
168186
## Track events
169187

170-
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).
188+
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](./user-identity).
171189

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

fern/docs/pages/plug-sdk/web/search.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,44 @@ You should now have the PLuG search widget installed on your website. Facing som
7070
Once the widget is installed on your website, every user who visits your website is considered an anonymous user. Anonymous users are the users that come to your site and haven't yet logged in or shared any information.
7171

7272
After integrating the PLuG widget, you can personalize and contextualize customer engagement. Learn how to [identify your customers](./user-identity) and update their information.
73+
74+
## Bind a hotkey to toggle search agent
75+
76+
You can bind the `toggleSearchAgent` method to a hotkey, such as `Cmd + K` (or `Ctrl + K` for Windows), to toggle the search agent. Here's an example implementation:
77+
78+
<Tabs>
79+
<Tab title="Setup">
80+
```html
81+
<script>
82+
// Bind Cmd+K (or Ctrl+K) to toggle the search agent
83+
document.addEventListener("keydown", function (event) {
84+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
85+
event.preventDefault(); // Prevent default behavior
86+
window.plugSDK.toggleSearchAgent();
87+
}
88+
});
89+
</script>
90+
```
91+
</Tab>
92+
93+
<Tab title="Setup for React">
94+
```jsx
95+
useEffect(() => {
96+
const handleKeyDown = event => {
97+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
98+
event.preventDefault(); // Prevent default behavior
99+
window.plugSDK.toggleSearchAgent();
100+
}
101+
};
102+
// Attach the event listener
103+
document.addEventListener("keydown", handleKeyDown);
104+
// Clean up the event listener on unmount
105+
return () => {
106+
document.removeEventListener("keydown", handleKeyDown);
107+
};
108+
}, []);
109+
```
110+
</Tab>
111+
</Tabs>
112+
113+
You can modify the keydown event listener to bind it to other keys, or key combinations, or use any other user events based on your application’s needs.

0 commit comments

Comments
 (0)