Why prefill
If you already know who the visitor is — because they filled out a form, or they're logged in — you can pass that straight to the widget so they don't have to type it again. Matching fields are pre-populated, and if every required field is already filled the pre-chat form is skipped entirely.
The common case: hand off a form submission
A visitor enters their email in your own page's form; when they open chat, it's already there:
<form id="lead-form">
<input type="email" name="email" required />
<button type="submit">Talk to us</button>
</form>
<script src="https://api.glimpze.io/functions/v1/widget-loader?id=YOUR_WIDGET_ID&mode=api" async defer></script>
<script>
document.getElementById('lead-form').addEventListener('submit', (event) => {
event.preventDefault();
const email = event.target.elements.email.value;
// Prefill, then open the widget straight into chat.
GlimpzeWidget.open({ prefillFields: { email } });
});
</script>Set defaults once for the whole page
If you know the visitor at page load (e.g. a signed-in user), set the values once with configure(). Every later open() reuses them.
GlimpzeWidget.configure({
prefillFields: {
name: currentUser.fullName,
email: currentUser.email,
plan: currentUser.plan, // a custom field
},
});How prefillFields maps to your form
prefillFields is a flat object keyed by your field names — the same names returned by getFields(). Two names are special:
| Key | Goes to | Notes |
|---|---|---|
name | Visitor identity | Must be a string. |
email | Visitor identity | Must be a string. |
| anything else | Visitor custom data | Prefills the form field whose name matches; also stored as visitor metadata. |
GlimpzeWidget.open({
prefillFields: {
name: 'Jane Doe',
email: 'jane@acme.com',
company: 'Acme Inc', // matches a "company" form field
plan: 'enterprise', // matches a "plan" form field
},
});Keys that don't match any field still get stored as visitor custom data, and the SDK logs a console.warn listing the valid field names — handy for catching typos. Use getFields() to discover exactly which fields a widget has.
Good to know
visitorInfo / customData still work. prefillFields is sugar over the two lower-level keys. visitorInfo: { name, email } and customData: { ... } are still accepted and take precedence if you pass both.