How can I listen to JavaScript events posted from embeds?

Malcolm! embeds fire events on user interactions such as when someone first reads an FAQ, completes a Workflow or performs a search. These events can be picked up on your web page for you to perform custom actions - for example creating an event for your Analytics.

How can I listen to these events?

The Malcolm! embed JavaScript library comes with some simple interfaces for listening to events.

The first event attached to the window is mapiready. This event is fired when the mapi.js library has finished loading and all embeds are rendered.

window.addEventListener('mapiready', function() {
  // window.mapi is ready

To register embed event listeners use the embed.on function. If you know the ID of the embed you can use mapi.findEmbed to return a Promise containing an embed Object in the response.

mapi.findEmbed('xxxxxxxxxx').then(function(embed) {
  // Register listeners here

Alternatively you can loop through the mapi.embeds array and register listeners that way.

mapi.embeds.forEach(function(embed) {
  // Register listeners here

Here's an example to register a listener for the event faq-read for embed ID xxxxxxxxxx.

window.addEventListener('mapiready', function() {
  mapi.findEmbed('xxxxxxxxxx').then(function(embed) {
    embed.on('faq-read', function(data) {
      // Do something with data

What events are available?

Different events are fired from the different embeds. Use the table below to check which events are available.

Event Inline Overlay Widget
close - ✔︎ ✔︎
closed - ✔︎ ✔︎
faq-feedback-received ✔︎ ✔︎ ✔︎
faq-read ✔︎ ✔︎ ✔︎
loaded ✔︎ - -
open - ✔︎ ✔︎
opened - ✔︎ ✔︎
search ✔︎ ✔︎ ✔︎
workflow-completed ✔︎ ✔︎ ✔︎
workflow-feedback-received ✔︎ ✔︎ ✔︎
workflow-started ✔︎ ✔︎ ✔︎
Did this help you?
100% found this useful
Thank you for submitting your feedback.

Upgrade your content

Want to give your users a graphical run-down of how your products or services work? Malcolm! Agency Services can help

Learn more

Hey there!

Malcolm! is brought to you by a passionate and dedicated team - we love all things customer support related! Find out more about us here

Find out more