Browse and search developers
Embed SDK
Embed SDK overview
What the Formit embed SDK does, where embed.js is served from, how it loads a form in an iframe, and how embed ids differ from form ids.
On this page
The Formit embed SDK is a small JavaScript file, embed.js, that puts a published Formit form on any web page. It does not contain the form itself. It reads an embed id from your page, fetches that embed’s settings from the Formit API, and loads the live form in an iframe using one of six display modes.
Where the script is served from
In production the script is served from https://embed.formitai.com/embed.js. The snippet the app gives you adds a version query (currently ?v=7) so that copying a fresh snippet bypasses old cached copies. The file is served with Cache-Control: public, max-age=60 and Access-Control-Allow-Origin: *, so pages using an older snippet pick up script updates within about a minute.
Embed ids are not form ids
A form can have several embeds. Each embed is a saved configuration with a name, a display mode and design settings, and it has its own id. The snippet uses this embed id, not the form id. The two are different values, and pasting a form id into data-formit-embed does not work.
| Embed id | Form id | |
|---|---|---|
| Where you get it | The Get the code dialog for an embed under Share > Embed in a web page | The form’s public link and the builder |
| Used in | data-formit-embed and the FormitEmbed.create* functions | Public form URLs, webhook payloads (form_id) |
| Controls | Mode, size, launcher style, URL parameter handling | The questions and the published version |
Mode and design settings are read from the server each time the page loads. When you change an embed and click Apply changes, sites already using that embed id show the new settings on their next page load, with no snippet change.
How it works
- The script defines
window.FormitEmbedand scans the page for elements withdata-formit-embed. - For each one, it requests the public embed configuration from the Formit API at
/api/v1/public/embeds/<embedId>. This returns the embed id, the form id, the mode, the config and the form’s public URL. - It builds the iframe URL from the public URL, adding display parameters and any URL parameters you configured, then renders the iframe for the mode.
- Inside the iframe, the form sends
postMessageevents (ready, submit, close, height, question) that the SDK passes to your callbacks.
The form itself loads from Formit’s public form host (form.formitai.com), or from your organization’s branded subdomain if you have set one. The iframe is created with allow="camera; microphone; clipboard-write" and lazy loading.
Requirements and limits
- The form must be published. For an unpublished form the configuration request returns 404 and the element shows "Unable to load form embed."
- If your site uses a Content Security Policy, allow
embed.formitai.comas a script source, the Formit API origin forconnect-src, and the form host forframe-src. Check the browser network panel for the exact origins your page uses. - On hosts other than
localhost,embed.jsalso loads the Microsoft Clarity tag (www.clarity.ms) on the host page for embed analytics. Account for this in your CSP and consent setup. - Embed errors are reported to the Formit API so the team can see failed mounts.
Related
Can't find what you need?