You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/docs/pages/sdks/web/user-identity.mdx
+89-5Lines changed: 89 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,34 @@ For users who are logged into your website, you can identify them in PLuG to ena
4
4
5
5
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.
6
6
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)
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.
0 commit comments