Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Advanced Usage

Multiple Widget Instances

You can open multiple widget instances simultaneously, each with different configurations:

const supportWidget = await MailAgent.open({
  bottom: "20px",
  right: "20px",
  width: "350px",
  height: "500px"
});

const feedbackWidget = await MailAgent.open({
  path: "/feedback",
  bottom: "20px",
  left: "20px",
  width: "350px",
  height: "400px"
});

Dynamic User Switching

If your application supports multiple users or accounts, load the script once and pass different user IDs when opening:

Analytics Integration

Pass a distinctId to associate widget analytics with your own user tracking:

This ID is forwarded to MailAgent's analytics with each chat message so widget sessions can be correlated with your own user metrics. Values that look like email addresses are redacted before they are stored.

What the widget collects

The widget records anonymous usage events: loading, opening and closing, messages sent, response times, suggestion and link clicks, email-escalation form use, and errors. It never records message text, file contents or form input, does not use cookies (an anonymous ID is kept in the widget's own localStorage), and does not record sessions or capture clicks automatically. Events are attributed to your MailAgent account and to your site's domain.

Programmatic Messaging

Use widget.send() to trigger contextual conversations based on user actions in your app:

Lifecycle Management

The widget handle gives you control over the widget lifecycle:

The unmount() method plays a fade-out animation before removing the iframe. The widget handle becomes invalid after unmounting.

Chat Persistence

The widget automatically persists chat history in the browser using localForage. Messages are stored for 24 hours and will be restored if the user reopens the widget within that window.

This means:

  • Users can close and reopen the widget without losing context.

  • Refreshing the page preserves the conversation.

  • After 24 hours, the chat history is automatically cleared.

Feedback Page

The widget includes a built-in feedback page at the /feedback route:

Language Detection

The widget automatically detects the user's browser language (navigator.language) and sends it with each message. The AI assistant will respond in the same language when possible. 22+ languages are supported, including:

English, Spanish, French, German, Arabic, Chinese, Japanese, Korean, Portuguese, Russian, Italian, Dutch, Polish, Turkish, Vietnamese, Thai, Indonesian, Hindi, Bengali, Swedish, Danish, and Norwegian.

Last updated