Identify your users with PLuG
Once you have installed PLuG, all your users who interact with the widget are created as anonymous users in the DevRev app with a random name since there is no information about the user.
For users who are logged on to your website, you can identify them on PLuG so that they can see their past conversations. Identifying your users also enables more personalized engagement with your users.
In this flow, you have to generate a session token for every user who visits your website. The session token identifies the customer when they interact with the widget. The session token is generated using the application access token and customer information. It should be generated on your website's back end since the app token needs to be kept hidden.
You can identify logged-in users by following these steps.
Generate an application access token
- In DevRev, go to Settings > Support > PLuG Tokens through the settings icon on the top-left corner.
- Click New token and copy the token that's displayed.
Copy your access token at this step as you won’t be able to see it again.
Generate a session token
For security reasons, this call should be made from the server side so that your AAT isn't exposed.
You can generate a session token in the following ways:
- Using rev user_id:
1 curl --location 'https://api.devrev.ai/auth-tokens.create' \ --header 2 'Content-Type: application/json' \ --header 3 "Authorization: $AAT" \ --data 4 '{5 "grant_type" : "urn:devrev:params:oauth:grant-type:token-issue",6 "subject_token" : "<<subject token>>",7 "subject_token_type" : "urn:devrev:params:oauth:token-type:userinfo",8 "requested_token_type" : "urn:devrev:params:oauth:token-type:session"9 } '
- Using rev_info:
1 curl --location 'https://api.devrev.ai/auth-tokens.create' --header 'Authorization: "<<Application Access Token>>"'2 --header 'Content-Type: application/json' --data-raw3 '{4 "rev_info": {5 "user_ref": "<<123456789>>",6 "org_ref": "<<org-org>>",7 "user_traits": {8 "email": "<<user@example.org>>",9 "display_name": "<<user>>",10 "full_name": "<<User Name>>"11 },12 "org_traits": {13 "display_name": "<<example>>",14 "domain": "<<example.com>>"15 }16 }17 }'
Passing the session token
While initializing the PLuG widget you pass the session token for DevRev to identify this user and thereby make the widget more customized for the user and their context.
1 // You can generate this session token using the above API in your backend2 const sessionToken = '<SESSION_TOKEN>'3 <script type="text/javascript" src="https://plug-platform.devrev.ai/static/plug.js"></script>4 <script>5 (() => {6 window.plugSDK.init({7 app_id: '<your_unique_app_id>',8 session_token: sessionToken9 })})();10 </script>