Skip to main content

addEventSubscriber(eventHandler)

Captures CommandBar events to be handled in your code / stored in your database. Ask the CommandBar team if you're interested in this feature.

tip

If you are on the Enterprise plan, our analytics integrations can automatically set this up for you!

Example

// The function that handles CommandBar events
const myHandler = (eventName, eventData) => {
sendToSegment({ name: eventName, ...eventData });
};

// Subscribe to CommandBar events
const unsubPromise = window.CommandBar.addEventSubscriber(myHandler);

// Later, call the function returned by the promise
// to unsubscribe your handler from CommandBar events.
unsubPromise.then((unsub) => unsub());

Method parameters

eventHandler Required

function

A function for handling events generated by CommandBar. It should have the following signature:

eventHandler Properties

eventName Required

string

The name of the event type. Here are the different event types:

  • "opened": Bar open
  • "closed": Bar close. When the bar is closed with input text, it triggers both a closed event and a deadend. Executions do not trigger closed events.
  • "abandoned_search": A deadend
  • "command_suggestion": A command suggestion
  • "command_execution": A command execution
  • "no_results_for_query": When a user's search returns no results (commands or records)
  • "nudge_shown": When a nudge gets shown
  • "nudge_clicked": When a nudge gets clicked
  • "nudge_snoozed": When a nudge gets snoozed
  • "nudge_completed": When a product tour gets completed
  • "survey_response": When a survery gets submitted
  • "nudge_dismissed": When a nudge's close button is clicked
  • "preview_shown": When a preview gets shown (hovered over by the user)
  • "questlist_shown": When a Checklist gets shown. // Questlist is the previous term for Checklist
  • "questlist_engagement": When a Checklist gets engaged with by the user.
  • "questlist_item_engagement": When a Checklist item gets engaged with by the user.
  • "preview_engagement": When a preview gets engaged with by the user (e.g., the user scrolls).
  • "shortcut_edited": When a user assigns or edits a command's shortcut
  • "help_hub_opened": When HelpHub is opened.
  • "help_hub_closed": When HelpHub is closed.
  • "help_hub_minimized": When HelpHub is expanded.
  • "help_hub_unminimized": When HelpHub is collapsed.
  • "help_hub_engagement": When a search is executed in HelpHub.
  • "help_hub_doc_opened": When a help document is opened in HelpHub.
  • "help_hub_doc_closed": When a help document is closed in HelpHub.
  • "help_hub_doc_engagement": When an engagement is made in a HelpHub document (e.g. link clicked).
  • "no_chat_response": When AI chat cannot find an answer to a question.
  • "client_error": An error encountered by CommandBar

Note that we will likely add more eventNames in the future, so your code should be robust to receiving events with an unknown eventName.

eventData Required

object

Event attributes (will differ based on the type of event). In addition to the data below, any eventData you pass to boot() will be added to each event. Each data object includes its event type as a property.