How to Add a Clear Session Option to the BoldChat Widget
This guide shows how to add a Clear Session item to the chat widget’s More Options menu. When clicked, it resets the chat session by clearing the widget’s cache.
Requirement: For this to work, the JavaScript code shown in one of the steps below, must be added inside the Live Chat widget’s Custom JS setting (not on your website pages). The navigation path is illustrated below.
Prerequisites
-
A Live Chat widget you can Edit (or permission to Add Widget).
-
To add a clear session option to the BoldChat widget, an Agent’s role must have the permission to Manage settings.
Where to add the code (Custom JS is required)
-
Go to Admin → Chat → Live Chat
-
Open a widget
In the Live Chat list, either Edit an existing widget (⋮ → Edit) or click Add Widget to create a new one. -
Appearance → Advanced Customization → Custom JS → Add Custom JS
-
Paste the code and click Add
-
Click Update to save the widget
JavaScript to add in Custom JS
// Initialize $boldChat as an empty array if not already defined
window.$boldChat = window.$boldChat || [];
/**
* Adds the "Clear Session" option to the chat widget's More Options menu.
*/
window.$boldChat.push(["do:addOption", "Clear Session"]);
/**
* Registers an event listener for custom option clicks.
* If "Clear Session" is clicked, it clears the chat session by clearing the cache.
*/
window.$boldChat.push(["on:moreOptionClick", onMoreOptionClick]);
function onMoreOptionClick(item) {
// Check if the clicked option is "Clear Session"
if (item.name === "Clear Session") {
// Clear the chat session
window.$boldChat.push(["do:clearSession"]);
}
}
Command reference
do:addOption— Adds Clear Session to the More Options menu.on:moreOptionClick— Listens for selections of custom options.do:clearSession— Clears cache and resets the chat session.
Result in the Customer Portal
Frequently Asked Questions (FAQs)
1)Where do I add the code so the “Clear Session” option appears in the customer‑facing Live Chat widget?
A: In the widget’s Custom JS. Go to Admin → Chat → Live Chat → (Edit an existing widget or Add Widget) → Appearance → Advanced Customization → Custom JS → Add Custom JS, paste the code, click Add, then Update.
2) What code adds the “Clear Session” option in the customer‑facing Live Chat widget?
window.$boldChat = window.$boldChat || [];
window.$boldChat.push(["do:addOption", "Clear Session"]);
window.$boldChat.push(["on:moreOptionClick", onMoreOptionClick]);
function onMoreOptionClick(item){
if (item.name === "Clear Session") {
window.$boldChat.push(["do:clearSession"]);
}
}