JavaScript embed
One script tag and one div. ContactUsIQ renders the form with your theme, loads Turnstile, submits by fetch and shows an inline thank-you.
Sample: samples/js-embed (index.html for the form, widget.html for the feedback widget, README).
The snippet
<div id="contactusiq-form"></div>
<script src="https://api.contactusiq.com/f/au_xxxxxxx/embed.js"
data-target="#contactusiq-form" async defer></script>GET /f/{formPublicId}/embed.js returns a script that renders the form with the workspace's chosen theme, loads Turnstile with the key configured on the form, submits by fetch with Accept: application/json and shows an inline thank-you with the reference id. It is cached at the edge.
Fields, labels, required rules and the Turnstile key all come from the form definition, so edits in the dashboard appear on the site without a deploy. No Turnstile site key is needed in the page.
Steps
- Put the
divwhere the form should appear and thescripttag after it (or anywhere on the page). - Replace
au_xxxxxxxwith your form id. - Keep
data-targetpointing at thediv, or omit it to render where the script tag sits. - Deploy on the verified domain.
Content Security Policy
If the site sets a CSP, allow:
script-src https://api.contactusiq.com https://challenges.cloudflare.com
frame-src https://challenges.cloudflare.com
connect-src https://api.contactusiq.comThe embed script is served with Subresource Integrity hashes.
Behaviour
- Loads deferred and never blocks the host page if it fails to load.
- Sets no cookies of its own.
- On
429shows the wait time fromRetry-After; on400shows the field named in the error. - The same script family serves the feedback widget (
widget.js), which adds intent, rating and page context.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
The div stays empty | Wrong form id (404 in the Network tab), the form is unpublished, or a CSP blocks api.contactusiq.com. |
Submit returns 200 but nothing arrives | Origin mismatch: the page is not on a verified domain of the form. Test on the real domain or add the staging domain to the workspace. |
| Turnstile fails inside the embed | The Turnstile widget in Cloudflare does not list this domain, or the key on the form is wrong. |
Provide a fallback
Add a noscript paragraph with an email address or a link to a plain HTML version for visitors without JavaScript, or use the plain HTML form instead, which needs none.