Skip to content

Commit 529cce0

Browse files
kunal-mohta-99bc-devrevAtul-Butolagithub-actions[bot]
authored
PLuG user identification docs improvements (#279)
* PLuG user identification docs improvements * address review comments * diagram font * Revert "diagram font" This reverts commit 5af9512. * diagram font * Update fern/docs/pages/sdks/web/user-identity.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update fern/docs/pages/sdks/web/user-identity.mdx Co-authored-by: Ben Colborn <[email protected]> * update font --------- Co-authored-by: Ben Colborn <[email protected]> Co-authored-by: Atul-Butola <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4f9307e commit 529cce0

File tree

1 file changed

+89
-5
lines changed

1 file changed

+89
-5
lines changed

fern/docs/pages/sdks/web/user-identity.mdx

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@ For users who are logged into your website, you can identify them in PLuG to ena
44

55
To implement user identification, you need to generate a session token for each user who visits your website. This token is created using your application access token combined with customer information, and must be generated on your backend to keep the application token secure.
66

7+
```mermaid
8+
---
9+
config:
10+
theme: 'base'
11+
themeVariables:
12+
fontFamily: 'Segoe UI'
13+
---
14+
sequenceDiagram
15+
%%{init: {
16+
'theme': 'base',
17+
'themeVariables': {
18+
'fontFamily': 'Segoe UI',
19+
'signalColor': '#7d7f7c',
20+
'signalTextColor': '#7d7f7c'
21+
}}}%%
22+
participant User as Your User
23+
participant Frontend as Your Frontend
24+
participant Backend as Your Backend
25+
participant DevRev as DevRev's Backend
26+
27+
User->>Frontend: (1) User is known<br/>(via Signup, Login)
28+
Frontend->>Backend: (2) Send user details
29+
Backend->>DevRev: (3) auth-tokens.create API call
30+
DevRev-->>Backend: (4) Return RevUser Session Token
31+
Backend-->>Frontend: (5) Return Session Token
32+
Frontend->>Frontend: (6) Call plugSDK.init() with token
33+
```
34+
735
## Generate an application access token
836

937
1. In DevRev, go to **Settings > Support > PLuG Tokens** through the settings icon on the top-left corner.
@@ -159,11 +187,12 @@ While initializing the PLuG widget you pass the session token for DevRev to iden
159187
const sessionToken = '<SESSION_TOKEN>'
160188
<script type="text/javascript" src="https://plug-platform.devrev.ai/static/plug.js"></script>
161189
<script>
162-
(() => {
163-
window.plugSDK.init({
164-
app_id: '<your_unique_app_id>',
165-
session_token: sessionToken
166-
})})();
190+
(() => {
191+
window.plugSDK.init({
192+
app_id: '<your_unique_app_id>',
193+
session_token: sessionToken
194+
})
195+
})();
167196
</script>
168197
```
169198

@@ -208,3 +237,58 @@ window.plugSDK.updateIdentity({
208237
}
209238
})
210239
```
240+
<Callout intent="note">
241+
Note that the `updateIdentity` method cannot be used to update the `user_ref` of the user. In order to change the identity of the user completely to a new one, you need to re-initialize PLuG. See the [Changing the user identity](#changing-the-user-identity) section for more details.
242+
</Callout>
243+
244+
## Changing the user identity
245+
246+
As described in the above sections, to identify a user, you need to initialize the PLuG SDK with the relevant user information. PLuG can only be initialized once per page load.
247+
248+
In most cases, this works as expected—user identification typically happens after login or signup, which causes a page reload and clears any previous PLuG instance.
249+
250+
However, if your application needs to update the user identity without a full page refresh, you need to explicitly delete the existing PLuG instance before initializing it again with the new user information.
251+
252+
```jsx
253+
// Delete the existing PLuG instance if it exists
254+
if (window.plugSDK.isPlugInitialized) {
255+
window.plugSDK.shutdown();
256+
}
257+
258+
// Re-initialize PLuG
259+
window.plugSDK.init({
260+
app_id: appId,
261+
262+
// With session token
263+
session_token: sessionToken,
264+
265+
// Or without session token
266+
identity: {},
267+
});
268+
```
269+
If you're using the PLuG SDK for recording user sessions, calling the `shutdown()` method will stop the ongoing session recording. Re-initializing with the `init()` method will then start a new session recording. To avoid losing continuity, you can pass the details of the ongoing session recording when re-initializing PLuG.
270+
```jsx
271+
// Get the ongoing session details
272+
const { sessionId, tabId } = window.plugSDK.getSessionDetails();
273+
274+
if (window.plugSDK.isPlugInitialized) {
275+
window.plugSDK.shutdown();
276+
}
277+
window.plugSDK.init({
278+
app_id: appId,
279+
280+
// Pass the session details
281+
session_recording_options: {
282+
sessionDetails: {
283+
sessionId: sessionId,
284+
tabId: tabId,
285+
},
286+
},
287+
288+
// With session token
289+
session_token: sessionToken,
290+
// Or without session token
291+
identity: {},
292+
});
293+
```
294+

0 commit comments

Comments
 (0)