Assistant embed API
The assistant is embedded in a web page or mobile app using a JavaScript snippet like the following:
<script>
// --- begin mavenoid embedded troubleshooter ---
(function(m,a,v,e,n,o,i,d) {
n=m.createElement(a);n.async=true;n.src="https://app.mavenoid.com/embedded/embedded.js";
o=m.getElementsByTagName(a)[0];o.parentNode.insertBefore(n,o);v[e]=v[e]||[];
})(document,"script",window,"mavenoid");
// --- end mavenoid embedded troubleshooter ---
mavenoid.push({
event: "assistant-mount",
clientId: "ma_123abc_123456789abcdefghijklmnopqrstuvwxyz"
});
</script>
The last 4 lines of JavaScript, which contains mavenoid.push
, is what causes the assistant to display on the page or in the app. This mavenoid.push
call can be configured to change the behavior of the assistant by modifying the parameters that are passed into it.
Don't duplicate this embedding script. You can call
mavenoid.push
again later with a differentclientId
to replace the assistant, but you must specify all parameters you want to override in every call. Each parameter should appear no more than once, as a comma-separated list inside the curly braces in themavenoid.push
call.For example, if you want the assistant to use the "en" language rather than auto-detecting the browser's language, you should add a new
defaultLang
parameter, resulting in a call like this:
mavenoid.push({ event: "assistant-mount", clientId: "ma_123abc_123456789abcdefghijklmnopqrstuvwxyz", defaultLang: "en" });
The following parameters may be passed to the mavenoid.push
call to configure the behavior of the assistant.
Required parameters
event
string
(usually"assistant-mount"
)
What event to push to Mavenoid, and thus which action the assistant should take. For normal embedding, this should always be set to "assistant-mount"
. There are a few other options that may be useful if you are controlling the assistant with JavaScript.
These events are currently available:
assistant-mount
: Loads the assistant with the configuration specified through all other included parameters. If the assistant was already loaded, this will reload it with the new configuration.assistant-open
: Opens the assistant if it has already been loaded with aassistant-mount
event.assistant-close
: Closes the assistant if it is currently open.assistant-unmount
: Unloads the assistant from the page. To open it again, it will first need to be reloaded with anotherassistant-mount
event.
event: "assistant-mount"
clientId
string
The clientId
generated when publishing a Web assistant touchpoint.
clientId: "ma_123abc_123456789abcdefghijklmnopqrstuvwxyz"
Optional parameters
defaultLang
string
(an ISO language code)- This can also be configured in the touchpoint UI.
If specified and there is a translation available matching the provided language code, the assistant will display that translation's text. If not specified or there is no matching translation, the assistant will decide which language to use based on what is available and what the user's browser indicates. The user can also override this within the assistant and pick a different language.
defaultLang: "sv"
initFormData
Record<string, any>
- This can also be configured in the touchpoint UI.
If specified, prepopulates the specified form data keys with the specified values.
See Understand form data - How form data gets set - JavaScript for more information.
initFormData: {name: "A User", email: "[email protected]"}
initPiiFormData
Record<string, any>
This works just like initFormData
, except that the form data is marked as Personally Identifiable Information (PII) and therefore is not stored in Mavenoid's servers or included in session transcripts.
initPiiFormData: {name: "A User", email: "[email protected]"}
externalScripts
Record<string, Function>
External script functionality is currently experimental. To work with external script nodes, please reach out to your Mavenoid representative.
onClose
() => void
- This can also be configured in the touchpoint UI.
A function to run when the user clicks the assistant's close button.
The primary use case is for when the assistant is embedded in a mobile app. This function can then be used to signal the app that the webview should be closed.
/**
* One way is to navigate to a special URL and watch for it on location changes.
*/
onClose: function () { window.location.assign("close:"); }
/**
* Another way is to post a message to the webview's parent page that the assistant was closed.
*/
onClose: function () { window.postMessage("ASSISTANT_CLOSED", "%YOUR_DOMAIN%") }