Skip to content

Commit 6132570

Browse files
PLuG user identification docs improvements
1 parent e64cd49 commit 6132570

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed
97.1 KB
Loading

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

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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+
<img src="../../../img/plug-verified-user-identification.png" width="400" />
8+
79
## Generate an application access token
810

911
1. In DevRev, go to **Settings > Support > PLuG Tokens** through the settings icon on the top-left corner.
@@ -159,11 +161,12 @@ While initializing the PLuG widget you pass the session token for DevRev to iden
159161
const sessionToken = '<SESSION_TOKEN>'
160162
<script type="text/javascript" src="https://plug-platform.devrev.ai/static/plug.js"></script>
161163
<script>
162-
(() => {
163-
window.plugSDK.init({
164-
app_id: '<your_unique_app_id>',
165-
session_token: sessionToken
166-
})})();
164+
(() => {
165+
window.plugSDK.init({
166+
app_id: '<your_unique_app_id>',
167+
session_token: sessionToken
168+
})
169+
})();
167170
</script>
168171
```
169172

@@ -208,3 +211,60 @@ window.plugSDK.updateIdentity({
208211
}
209212
})
210213
```
214+
<Callout intent="note">
215+
Note that `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.
216+
</Callout>
217+
218+
## Changing the user identity
219+
220+
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.
221+
222+
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.
223+
224+
However, if your application needs to update the user identity without a full page refresh, you'll need to explicitly delete the existing PLuG instance before initializing it again with the new user information.
225+
226+
```jsx
227+
// Delete the existing PLuG instance if it exists
228+
if (window.plugSDK.isPlugInitialized) {
229+
window.plugSDK.shutdown();
230+
}
231+
232+
// Re-initialize PLuG
233+
window.plugSDK.init({
234+
app_id: appId,
235+
236+
// With session token
237+
session_token: sessionToken,
238+
239+
// Or without session token
240+
identity: {},
241+
});
242+
```
243+
<Callout intent="note">
244+
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.
245+
```jsx
246+
// Get the ongoing session details
247+
const { sessionId, tabId } = window.plugSDK.getSessionDetails();
248+
249+
if (window.plugSDK.isPlugInitialized) {
250+
window.plugSDK.shutdown();
251+
}
252+
window.plugSDK.init({
253+
app_id: appId,
254+
255+
// Pass the session details
256+
session_recording_options: {
257+
sessionDetails: {
258+
sessionId: sessionId,
259+
tabId: tabId,
260+
},
261+
},
262+
263+
// With session token
264+
session_token: sessionToken,
265+
// Or without session token
266+
identity: {},
267+
});
268+
```
269+
</Callout>
270+

0 commit comments

Comments
 (0)