Category

How to Add a Clear Session Option to the Live Chat Widget

Updated:

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.

Use Cases

  • Let customers start a fresh chat session when troubleshooting issues.
  • Clear cached chat data to resolve widget-related problems.
  • Reset conversations before sharing a device with another user.
  • Allow visitors to quickly restart chats without refreshing the page.
  • Improve support experiences by starting new conversations with a clean session.
  • Give customers self-service control through a Clear Session option in the chat widget menu.
  • Reduce confusion caused by outdated chat history or cached information.

Prerequisites

  • A Live Chat widget you can Edit (or permission to Add Widget).
  • To add a clear session option to the live chat widget, an Agent’s role must have the permission to Manage settings.

    Permission_to_manage_settings_in_BoldDesk.png

Where to Add the Code (Custom JS is Required)

  1. Go to Admin → Chat → Live Chat

  2. Open a widget
    In the Live Chat list, either Edit an existing widget (⋮ → Edit) or click Add Widget to create a new one.

    ![Live_Chat_Page_4.png](https://support.bolddesk.com/kb/agent/attachment/article/19734/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxMDAwIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5ib2xkZGVzay5jb20ifQ.qGFn3UmwAdr1YfsuY5h_XurvCq0ympIJ2tgB2uyuc4M)
    
  3. Appearance → Advanced Customization → Custom JS → Add Custom JS

    ![Custom JS.png](https://support.bolddesk.com/kb/agent/attachment/article/19734/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjcwOTUzIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5ib2xkZGVzay5jb20ifQ.VJCe7qPYKPUNm4bMff_A9NHXth3ZuCi_7TaXkHb9W4c)
    
  4. Paste the code and click Add

    ![Page_for_Adding_a_Custom_JS_Code_when_Configuring_a_Live_Chat_Widget.png](https://support.bolddesk.com/kb/agent/attachment/article/19734/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxMDAzIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5ib2xkZGVzay5jb20ifQ.5PvAXIpzn2-YQN84yGWw12HDiWq6kA5RZb1hAAseV_g)
    
  5. Click Update to save the widget

    ![Update_Feature_in_the_Live_Chat_Settings.png](https://support.bolddesk.com/kb/agent/attachment/article/19734/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxMDA0Iiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5ib2xkZGVzay5jb20ifQ.JCTxqyKYpcNupLBTyAIa9xz1F-4H_ROS-MeQZVpfAXw)
    

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

Feature_to_Clear_a_Chat_Session_in_the_Customer_Portal.png

Frequently Asked Questions

  1. Where do I add the code so “Clear Session” appears in the customer-facing widget?
    Add the code in the widget editor: Admin → Chat → Live Chat → (Edit/Add Widget) → Appearance → Advanced Customization → Custom JS → Add Custom JS, then click 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"]);
      }
    }
    
  3. What does do:addOption do?
    do:addOption adds a custom menu item (in this guide, Clear Session) to the widget’s More Options menu.

  4. How does the widget detect that the visitor clicked Clear Session?
    The widget calls the callback registered via on:moreOptionClick, and the code checks item.name === "Clear Session".

  5. What does do:clearSession do?
    do:clearSession clears the widget cache and resets the chat session.

  6. What permission is required to configure this?
    The agent role must have Manage Settings enabled in the admin module.

Related Articles

  1. BoldDesk Live Chat Widget JavaScript API Guide
  2. How to Clear a Chat Session in BoldDesk
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied
Access denied
Access denied

No articles or sections found
No articles or sections found