Browse and search developers

Embed SDK

Embed options and events

Reference for the embed configuration fields, the data-formit-embed attribute, the window.FormitEmbed JavaScript API, its handle methods and callbacks.

On this page
  1. Data attributes
  2. Embed configuration (set in the app)
  3. JavaScript API
  4. Events and callbacks

Formit embeds are configured in two places. Display settings are saved on the embed in the app and fetched at runtime. Behaviour on your page, such as callbacks and where to mount, is set through the window.FormitEmbed JavaScript API.

Data attributes

AttributeRequiredDescription
data-formit-embedYesThe embed id. Elements with this attribute are mounted when the script loads and by FormitEmbed.init().

The SDK sets data-formit-mounted on elements it has mounted. Treat it as internal state and do not set it yourself.

Embed configuration (set in the app)

These fields are stored on the embed and returned by the public configuration endpoint. You edit them in Share, not in your HTML.

FieldType and rangeUsed by
width, unitnumber, px or %Standard. unit applies to width only.
heightnumber, pxStandard (starting height in auto mode)
heightModefixed or autoStandard
fullscreenMobilebooleanStandard. The SDK also applies it to slider, popover and side tab iframes, but the app shows the toggle only for Standard and Full page.
hideHeadersbooleanAll modes
autoFocusbooleanAll modes
backgroundTransparency0 to 100All modes
readUrlParamsbooleanAll modes
customParamValueslist of { key, value }All modes
positionleft, right or bottomSlider, Popover, Side tab
sliderWidthnumber, pxSlider. The SDK also uses it for the side tab panel width (200 to 1200px), which the app does not show for side tab.
popupSizelarge, medium or smallPopup
buttonTextup to 100 charactersPopup, Slider, Side tab
buttonColorcolour stringPopup, Slider, Popover, Side tab
buttonFontSize10 to 48Popup, Slider
buttonBorderRadius0 to 100 (%)Popup, Slider
buttonAsTextbooleanPopup, Slider
popoverIconUrlimage URL or nullPopover, Side tab
greetingEnabled, greetingMessageboolean, up to 50 charactersPopover
notificationDotbooleanPopover
hideForDays0 to 365Popover

URL parameters

The SDK adds customParamValues to the form URL as query parameters. When readUrlParams is on (the default), it also copies every query parameter from the host page URL, and those win over custom values with the same key. Use this to pass campaign data such as utm_source into hidden fields. The SDK sets its own parameters (embed, hideHeaders, autoFocus, hostViewport, embedPosition and bgTransparency) first and URL parameters are applied after them, so do not use those names for your own values.

JavaScript API

FunctionReturnsDescription
FormitEmbed.init(root?)voidMounts every unmounted [data-formit-embed] element inside root (default document). Runs automatically when the script loads.
FormitEmbed.mount(element, callbacks?)Promise<void>Mounts one element that has data-formit-embed. Accepts autoResize and the callbacks below. Does nothing if the element is already mounted, and rejects if the configuration cannot be loaded.
FormitEmbed.createWidget(embedId, options?)handleSets data-formit-embed on the container, mounts it and returns a handle.
createPopup, createSlider, createPopover, createSidetabhandleSame as createWidget.
FormitEmbed.createEmbed(embedId, mode, options?)handleSame, with a mode argument such as popup or POPUP.

Options for create functions

OptionTypeDescription
containerHTMLElement or CSS selectorWhere to mount. Throws if a selector matches nothing. Without it, a new div is appended to body.
autoResizebooleanResize the iframe to the form’s height even when the embed’s height mode is fixed. Full page ignores it.
onReady, onSubmit, onClose, onQuestionChanged, onHeightChangedfunctionsCallbacks, described below.
onStartedfunctionCalled when you call handle.open().

Handle methods

MethodEffect
open()Opens the popover or side tab, or clicks the popup or slider launcher. Only works after the configuration has loaded.
close()Closes the panel, removes any open Formit popup, slider or full page overlay on the page, and calls onClose.
toggle()Opens if closed, closes if open.
refresh()Remounts the embed and fetches the configuration again.
unmount()Removes the embed from the container (and its full page overlay, if any).

Events and callbacks

Callbacks are driven by messages from the form iframe. Elements mounted automatically from the snippet have no callbacks. To receive events, mount with FormitEmbed.mount() or a create function.

CallbackArgumentWhen it fires
onReadynoneThe form inside the iframe has loaded.
onSubmit{ formId, formVersionId }A response was submitted successfully. Not sent when the form redirects to another URL after submit.
onClosenoneRight after a successful submit, when a visitor closes a popup, slider, popover or side tab, or when you call close().
onQuestionChanged{ questionId, index, fieldType }The visitor moved to another question.
onHeightChangedheight (number, px)The form’s content height changed.

Ready?

Build your first AI form in minutes.

No credit card. Generate from a prompt, enable follow-ups, and publish a link or embed the same day.