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.
- Under the Application access tokens panel, 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.
Using the rev_info method, you can generate and recognize a user within the DevRev system by providing relevant user details. This method enables you to convey information systematically, ensuring alignment between your DevRev CRM and the structured data model. For information regarding terminologies, click here.
1 curl --location 'https://api.devrev.ai/auth-tokens.create' \2 --header 'accept: application/json, text/plain, */*' \3 --header 'authorization: <AAT>' \4 --header 'content-type: application/json' \5 --data-raw '{6 "rev_info": {7 "user_ref": "example@devrev.ai",8 "account_ref": "devrev.ai",9 "workspace_ref": "devrev-dev",10 "user_traits": {11 "email": "test-user@devrev.ai",12 "display_name": "Devrev Test USer",13 "phone_numbers": ["+911122334455"],14 "custom_fields": {15 "tnt__<field1_name>": "value 1"16 }17 },18 "workspace_traits": {19 "display_name": "Devrev Dev",20 "custom_fields": {}21 },22 "account_traits": {23 "display_name": "Devrev",24 "domains": [25 "devrev.ai"26 ],27 "phone_numbers": ["+919988998833"],28 "custom_fields": {29 "tnt__<field2_name>": "value x"30 }31 }32 }33 }'
Ensure that you follow the specified format when providing your phone number.
Passing custom attributes
You can create custom attributes using API.
You can pass the custom attributes that are created as shown below:
1 "custom_fields": {2 "tnt__custom_attribute_name1": <<value>>,3 "tnt__custom_attribute_name2": <<value>>,4 }
You can pass custom traits, as shown above, not only for users but also for workspaces and accounts.
If you prefer a two-level structure, where users are directly associated with an account instead of a workspace, you can provide the user_ref and details along with the account_ref and details.
Attributes for users
Attributes for workspaces
Attributes for accounts
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>