A session variable is a temporary piece of information that captures user-specific details, such as name, email, or phone number, while they’re using the chat or flow in your website.
It helps the Business Messaging widget remember who the user is and personalize their experience during that visit.
How do Session Variables work?
1. Session initiation
When a user accesses a web application, the server creates a new session and assigns a unique Session ID. This ID is sent to the client’s browser.
2. Data storage
As the user interacts with the application, specific information (e.g., username, preferences) is stored in session variables on the server, associated with the user’s Session ID.
3. Data retrieval
During subsequent requests, the server uses the Session ID to retrieve the corresponding session variables.
4. Session termination
Sessions can end due to user logout, session timeout, or closing of the browser. Upon termination, the server discards the session variables.
Sample format for sessionVariableValues
[
{
name: 'UserName',
value: 'John'
},
{
name: 'id',
value: '6320834868293'
}
]
1. Passing Session Variable during initial rendering
Define the session variables inside widgetProps when rendering the widget for the first time.
ZOHOIM.widgetProps = {
sessionVariableValues:sessionVariable
};
2. Updating Session Variables after initial render
If session data changes during the interaction, you can update it using the triggerEvent method
const { triggerEvent } = window.ZOHOIM || {};
const args = {
sessionVariableValues: sessionVariable
};
triggerEvent('setVariable',args);