Category

How to Add a Clear Session Option to the BoldChat 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.

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.

    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

  3. Appearance → Advanced Customization → Custom JS → Add Custom JS

    Option_to_Add_Custom_JS_Code_in_the_Appearance_Tab_of_a_Live_Chat.png

  4. Paste the code and click Add

    Page_for_Adding_a_Custom_JS_Code_when_Configuring_a_Live_Chat_Widget.png

  5. Click Update to save the widget

    Update_Feature_in_the_Live_Chat_Settings.png

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 (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"]);
  }
}

Related Article

Live Chat Widget JavaScript API Guide

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