Inject User Data
Learn how to pass data to the widget
Intro
You can pass 2 types of data to Molin:
- User data (e.g. your customer’s email, name, ID, their most recent order, etc) which will be made available in the dashboard (on the Inbox page) for your agents to see
- Custom instructions for the AI to follow (these will be used in addition to the instructions configured via our dashboard)
How to pass data
You will pass data through the Molin AI widget. The widget is either installed automatically (if your platform uses our plugin, e.g. Shopify, UNAS, Shoprenter) or it is embedded manually (if you use a custom platform). It looks like this:
Automatic injection
Simply include your data in a <script>
tag, placed anywhere inside the <head></head>
section of your website:
When the widget is loaded, it will automatically read the data from window.molinSettings
.
Inject directly into the component
If you manually render the custom components <molin-shop-ai>
or <molin-shop-ai-chat>
, you can pass in the data as an attribute:
Alternatively, you can assign data programmatically:
Both attributes x-user-data
and x-prompt-ext
are of type string
. Please see below the data format section.
Data formats
User data
You must pass user data as a stringified JSON object. Only primitve types are allowed, no nested objects or arrays.
The user data must satisfy this TypeScript type:
And this valibot schema:
Custom instructions
You must pass custom instructions as a string, in plain text or markdown.
The minimum length is 1 character and the maximum is 1000 characters.
Data persistence
Molin’s client side widget remembers the most recently active conversation. If you inject user data, it will be remembered for the duration of the conversation. Therefore, it is important to reset the widget when the user logs out:
Security
Data handling
You must understand how each piece of data is handled by Molin:
- User data (
x-user-data
) is stored in our database and is visible to your agents in the dashboard. It is encrypted at rest and in transit. It is not shown to the LLM we use to generate AI responses. Check the members of your team to ensure they have the necessary permissions to view this data. - Custom instructions (
x-prompt-ext
) are shown to the LLM we use to generate AI responses. Assume that they are visible to the user in their entirety, even if the AI is usually smart enough to only disclose the specific information the user is asking for.
Protection against session reuse
You must ensure that you reset the widget when the user logs out. This is to prevent the next user from seeing the previous user’s data when continuing the conversation. See Data persistence.