Skip to main content
This page covers advanced usage of the Remark SDK, providing developers with more sophisticated control over the chat widget and user experience.

Customizing your user experience with the Remark SDK

The Remark SDK can also be used to control the state of the chat widget. You may wish, for example, to temporarily close the chat widget when displaying full-screen promotions or open the chat widget when a customer clicks on a certain call-to-action on your site. You can open, close, hide, and show the chat widget using one of the options in the following code.
// To open the chat widget:
window.remark('open');
document.querySelector('remark-chat-widget').setAttribute('open', '');

// To close the chat widget:
window.remark('close');
document.querySelector('remark-chat-widget').removeAttribute('open');

// To entirely hide the chat widget:
window.remark('hide');
document.querySelector('remark-chat-widget').setAttribute('hidden', '');

// To show the chat widget again:
window.remark('show');
document.querySelector('remark-chat-widget').removeAttribute('hidden', '');

Opening the widget with options

In addition to simply opening the widget, you can pass options to control its initial state and behavior.
This is helpful when you want to start the chat from a specific context, prefill a message, or automatically send a greeting.
// Open the widget with additional context
window.remark('open', {
  from: 'category-page',
  message: 'Hi there! Can you help me find the right item?',
  mode: 'send'
});

Available options

  • from – A string identifier for where or why the widget was opened (for example, homepage, checkout, or category-page). Useful for analytics, tracking, or routing the conversation.
  • message – A string to prefill in the chat input. When paired with mode: 'send', this message will be sent automatically.
  • mode – Controls message handling. Use 'send' to send immediately or omit to just prefill the input.
This approach lets you personalize the chat experience and give your team useful context on how the conversation began.

Listening for Remark Events

The remark-chat-widget element fires a number of “remark” namespaced events. To listen to any of them, place an event listener on the remark-chat-widget element, or anywhere higher on the DOM. On the element directly
const widget = document.querySelector("remark-chat-widget");
widget.addEventListener("remark:mute-chat", () => {
  console.log("The user has toggled mute for the chat");
});
On the window
window.addEventListener("remark:mute-chat", () => {
  console.log("The user has toggled mute for the chat");
});

Listen to all Remark Events

To listen to all the events, you can use the window.remark.events.listenAll function. It takes a callback, called with every remark event. The payload received by the callback is an object: listenAll returns an object with an unsubscribe function. Calling that unsubscribe function will stop the callback from being called again.
// typescript function declaration of listenAll
declare function listenAll(cb: (payload: {event__type: string} & {[key: string]: any}) => void) => {unsubscribe(): void};

// example calling listenAll
const listener = window.remark.events.listenAll(
  ({event__type, ...detail}) => {
    console.log(`The event fired is ${event__type} with this information ${detail}`)
  }
);

// unsubscribing the listener
listener.unsubscribe();

List of Remark Events

EventDescription
remark:session-initializedThe Remark client has initialized, with basic information for our widgets
remark:open-widgetRemark chat widget has opened
remark:close-chat-from-headerCustomer has closed the chat window via the chat header button
remark:mute-chatFires when chat mutes or unmutes
remark:dismiss-floating-promptsCustomer has closed the floating prompts on the activator
remark:dismiss-unread-messageCustomer has dismissed the unread message on the activator
remark:finding-expertCustomer is waiting to be paired with an expert
remark:send-messageCustomer has sent a message
remark:select-landing-promptCustomer has selected a suggested question on the landing screen
remark:view-expert-profileCustomer is viewing the expert profile
remark:close-expert-profileCustomer has closed the expert profile
remark:view-expert-galleryCustomer is viewing the expert’s gallery
remark:submit-emailWhen the customer has submitted their email
remark:submit-nameCustomer has chosen to input their name
remark:skip-nameCustomer has chosen to skip inputting their name
remark:skip-emailCustomer has chosen to skip inputting their email
remark:skip-phoneCustomer has chosen to skip inputting their phone number
remark:submit-npsCustomer has submitted a Customer Feedback Survey
remark:edit-npsCustomer has edited a Customer Feedback Survey
remark:cancel-npsCustomer has canceled editing a Customer Feedback Survey