Skip to content

Trigger the chat from your own UI ​

Dispatch a humind-open-chat custom event on window to open the chat overlay from any element on your page: a "Need help?" button in the checkout, a CTA inside a product card, a help-center tile, anywhere a visitor might want to start a conversation without going through the floating entry point.

This page applies to every integration path:

  • Shopify merchants using the Humind app: the chat is auto-injected by the theme extension, so the humind-open-chat listener is already on window site-wide. Just dispatch the event.
  • Non-Shopify merchants who embedded <humind-widget> manually: same event, same listener.
  • Hybrid Shopify setups (Shopify backend, custom storefront) where <humind-widget> is embedded by hand: same contract.

When to use this ​

The default floating entry point (bottom-right button + proactive messages) is what ships with <humind-widget> out of the box, and it's good enough for most storefronts. Reach for humind-open-chat when you want to:

  • Wire your own CTA somewhere on the page (a "Talk to an expert" button, a size-help link, a shipping-question tile).
  • Open the chat pre-filled with a specific question.
  • Open the chat with a specific product in context so the AI can ground its answers on that product.
  • Route visitors who clicked something intent-loaded (e.g., a "Gift for dad" tile) into a targeted conversation.

Prerequisites ​

<humind-widget> must already be mounted on the page. If the overlay isn't in the DOM, the event fires and goes nowhere (no listener is registered). See Install the chat.

Event contract ​

js
window.dispatchEvent(new CustomEvent('humind-open-chat', {
  detail: {
    message: 'I need help choosing a size.'
  }
}))

detail fields ​

FieldTypePurpose
messagestringOptional. The message to send as if the visitor had typed it. The chat opens and immediately starts a reply. Omit to just open the overlay idle.
productIdstringOptional. A Shopify GID (gid://shopify/Product/12345) or your internal Humind product ID. Loads a product context bar at the top of the chat and lets the AI ground answers on that specific product.
entryPointstringOptional. A name for the button that opened the chat (hero-search), so your dashboard tells your buttons apart. See Name your buttons.

Examples ​

Open with a pre-filled message ​

html
<button id="size-help">Need help with sizing?</button>

<script>
  document.getElementById('size-help').addEventListener('click', () => {
    window.dispatchEvent(new CustomEvent('humind-open-chat', {
      detail: { message: 'Can you help me pick a size?' }
    }))
  })
</script>

Open with a product context ​

On a product card or list, pass the product ID so the conversation is grounded on that product.

html
<article data-product-id="gid://shopify/Product/12345">
  <button class="ask-about-this">Ask about this product</button>
</article>

<script>
  document.querySelectorAll('.ask-about-this').forEach(btn => {
    btn.addEventListener('click', e => {
      const card = e.target.closest('[data-product-id]')
      window.dispatchEvent(new CustomEvent('humind-open-chat', {
        detail: {
          message: 'Tell me more about this product.',
          productId: card.dataset.productId
        }
      }))
    })
  })
</script>

Open idle (no pre-filled message) ​

js
window.dispatchEvent(new CustomEvent('humind-open-chat'))

Name your buttons in the statistics ​

Without a name, the conversations started from your own buttons show as Not recorded in the dashboard's entry points. Give each button a name with entryPoint:

js
window.dispatchEvent(new CustomEvent('humind-open-chat', {
  detail: {
    message: 'A family trip in April',
    entryPoint: 'hero-search'
  }
}))

The conversations are then counted under Button on your site, one line per name, in the entry points of Analytics and in its entry-point filter. The name also shows in the Trigger line of each conversation.

  • The name is yours to choose, one per button. It is stored in lowercase, with accents removed and anything else turned into hyphens, 40 characters at most: Hero search becomes hero-search.
  • It also works when the chat opens idle: the name is kept for the message the visitor then types.
  • Keep the names stable: renaming a button starts a new line in the statistics.

Close the chat ​

Dispatch a humind-close-chat event to programmatically close the overlay. Useful if you've wired your own "close" button somewhere on the page, or if you want the chat to dismiss itself after a visitor completes an action elsewhere on the site.

js
window.dispatchEvent(new CustomEvent('humind-close-chat'))

No detail payload is read: the event is a fire-and-forget signal. If the overlay is already closed, the event is a no-op.

Open the booking ​

Dispatch a humind-open-appointment event to open the chat on its Appointment tab, for a "Book an appointment" button anywhere on your site. Pass a Humind store ID to open the booking on that store; without one, the visitor picks the store.

js
window.dispatchEvent(new CustomEvent('humind-open-appointment', {
  detail: { storeId: 'YOUR_STORE_ID' } // optional
}))

The Appointment tab must be enabled on your assistant; without it, the chat simply opens. On Shopify, the Appointment button app block does this for you: a button you style in the theme editor (icon only, icon and text, or text only, colors, shape, size, alignment), with an optional store ID.

No code needed: add ?humind=<action> to any URL of your site where the chat is installed, and the chat opens on that action when the page loads. Use it for links you send or print: an order confirmation email, a newsletter, an SMS, a QR code in a store.

https://www.your-store.com/?humind=order-tracking
ValueWhat happens
chatOpens the chat.
order-trackingOpens the chat and asks where the order is, in the chat's language. The assistant then shows its order lookup form. Requires order tracking to be enabled on your assistant. A visitor with a conversation in progress gets the question in that conversation.
appointmentOpens the Appointment tab.
storesOpens the Stores tab (the store locator).
helpOpens the Help tab.

Two optional parameters refine an action:

ParameterWithPurpose
humind_orderorder-trackingThe order number, to prefill the request: ?humind=order-tracking&humind_order=1042. An optional leading #, then up to 24 letters, digits, - and _.
humind_storeappointmentA Humind store ID, to open the booking on that store: ?humind=appointment&humind_store=YOUR_STORE_ID.

Good to know:

  • The order number is not enough to show an order. Unless they are signed in to their customer account on your store, the visitor still confirms the email of the order in the lookup form. Never put an email address in the link: the parameter does not exist, and URLs end up in analytics tools and browser histories.
  • Only the actions listed above run. There is no parameter for a free message, so nobody can craft a link that makes a visitor say something else. To open the chat on your own message, dispatch humind-open-chat from your code.
  • Once per tab. Reloading the page, or browsing on with the same action in the URL, does not open the chat again.
  • A tab that is turned off on your assistant (Appointment, Stores, Help): the chat simply opens.
  • The parameter combines with yours (?utm_source=email&humind=stores), on any page. Your URL is never modified.

Gotchas ​

  • Use window.dispatchEvent, not document.dispatchEvent. The listener is registered on window. Dispatching on document does nothing. See Troubleshooting → humind-open-chat fires but the overlay ignores it.
  • Don't duplicate <humind-widget> on the page. Only one overlay should exist. The other widgets (<humind-gift-finder>, <humind-product-questions>, <humind-quiz>) already dispatch humind-open-chat when a visitor interacts with them, and they expect a single <humind-widget> instance to catch it.
  • The chat service must be reachable. If the backend or embed.thehumind.com CDN is down, the overlay shows a fallback "unavailable" state. Your CTA still fires cleanly; nothing breaks on your side.

Tracking chat opens in your analytics ​

Using GTM / GA4?

You don't need a listener: the widget already pushes its full event stream (opens, messages, add-to-cart, handoffs…) straight into window.dataLayer. See GA4 / GTM analytics.

window is the source of truth for chat-open events. If you want to forward them to GA4, Segment, Mixpanel, or any other analytics pipeline, add your own listener:

js
window.addEventListener('humind-open-chat', e => {
  analytics.track('chat_opened', {
    productId: e.detail?.productId,
    hasPrefilledMessage: Boolean(e.detail?.message)
  })
})

This catches both your own CTAs and the floating entry point: every path that opens the chat goes through this event.

Other events the chat listens to ​

The overlay also listens for two events emitted by other Humind widgets. You don't need to dispatch these yourself: they're documented here in case you see them in devtools or want to listen for them in your own analytics.

  • humind-quiz-completed: dispatched by <humind-quiz> when a visitor finishes a quiz. The chat overlay listens for it and may use it to refine context. You don't need to listen or dispatch this yourself.
  • humind-continue-thread: dispatched by <humind-quiz> when a visitor clicks "Continue in chat" at the end of a quiz. Hands the quiz context off to the chat.

Both are emitted by the quiz widget, not fired by merchants. If you need to open the chat from your own code, use humind-open-chat.

Released under the proprietary Humind license.