Docs

Embedding Amerta AI forms

How to put an Amerta AI form on any website: the embed script or a plain iframe, your own CSS, extra values, resize and lead events, and tracking.

Put an Amerta AI form on any website in an iframe, style it with your own CSS, pass extra values into it and react when it is sent. Every enquiry lands in Amerta AI as a lead with its ad source.

Before you start

You need three values from your Amerta AI account. They make up the form's address:

https://amerta.ai/form/{domain}/{form-id}/{locale}/
  • Domain: your account's form domain.
  • Form ID: the number of the form you want to show.
  • Locale: the language of the form, such as en or ar.

There are two ways to embed it, and both can use the events:

Way What it does
The embed script (recommended) Builds the iframe for you and passes the visitor's ad source and click IDs automatically.
A plain iframe (full control) You write the iframe and its address yourself. Tracking values are yours to pass.
Events (both) Resize the iframe to the form and fire your lead events when it is sent.

Embed with the script

Add a container where the form should appear, your form's settings, then the script. Replace the three values in the address.

<!-- where the form appears: give it a starting height -->
<div id="amerta-form" style="height:600px"></div>

<script>
  window._indentme = window._indentme || [];
  function indentme() { _indentme.push(arguments); }
  indentme('form', {
    selector: '#amerta-form',
    action: 'https://amerta.ai/form/{domain}/{form-id}/en',
    css: 'https://www.example.com/css/amerta-form.css',
    submit_label: 'Submit',
    params: { field_14: 'Botox' }
  });
</script>
<script async src="https://storage.googleapis.com/fixed/js/indentme.js"></script>

The script also saves the visitor's ad source and click IDs on every page it runs on. Put it in the site's shared footer, not only the contact page, so a visitor who lands on another page first keeps their source. On pages without a form, the two script parts without indentme('form', …) are enough.

Several forms on one page: give each its own container and call indentme('form', …) once per form, before the script tag.

Height: the iframe fills its container. Give the container a starting height, then add the listener from Resize and lead events so it grows to fit the form.

Embed a plain iframe

Point an iframe at the form's address and add the options as query parameters. URL-encode each value.

<iframe
  id="amerta-form"
  src="https://amerta.ai/form/{domain}/{form-id}/en/?css=https%3A%2F%2Fwww.example.com%2Fcss%2Famerta-form.css&submit_label=Submit&utm_source=google&utm_campaign=spring"
  style="width:100%;height:600px;border:0"
  title="Contact form"></iframe>

Or build the address in JavaScript, which handles the encoding:

var url = new URL('https://amerta.ai/form/{domain}/{form-id}/en/');
url.searchParams.set('css', 'https://www.example.com/css/amerta-form.css');
url.searchParams.set('submit_label', 'Submit');
url.searchParams.set('utm_source', 'google');
// extra values: see "Passing extra values"
url.searchParams.set('data', btoa('clid=gclid-abc123|14=Botox'));

document.getElementById('amerta-form').src = url.toString();

With a plain iframe nothing is tracked for you: read the UTMs and click IDs from your own page's address or cookies and pass them as shown in Passing extra values.

Options

The same options work in the script's settings and as query parameters of the iframe address.

Script setting Iframe parameter What it does
selector (none) CSS selector of the container the iframe is placed in. Script only, required.
action (the address) The form's address: https://amerta.ai/form/{domain}/{form-id}/{locale}. Required.
css css Link to your stylesheet, loaded inside the form. Several files: separate them with commas. Must be a public https link.
js js Link to a script that runs inside the form. Several: separate them with commas.
submit_label submit_label Text of the submit button, instead of the form's own.
(automatic) utm_source, utm_medium, utm_campaign, utm_term, utm_content The lead's ad source. The script passes the saved ones itself.
params data Extra values: field prefill and tracking. See below.

Passing extra values

Use extra values to fill a field in advance (a service chosen on the page, a hidden "page" field) or to pass tracking values yourself.

With the script: params

params: {
  field_14: 'Botox',          // fills the field named field_14
  field_20: 'Dubai Marina',
  clid: 'gclid-abc123',       // replaces the tracked Google click ID
  referer: 'https://partner.com/'
}

With a plain iframe: data

Join the values as name=value pairs separated by a vertical bar, Base64-encode the result with btoa() and pass it as data. Field names drop the field_ prefix: 14=Botox fills field_14.

var pairs = [
  '14=Botox',
  'clid=gclid-abc123',
  'fbclid=fbclid-IwAR0x|fbp-fb.1.1712345678.123',
  'referer=https://www.google.com/'
];
url.searchParams.set('data', btoa(pairs.join('|')));
Value Format Example
A field Field number, or the field's name or id. Selects and checkboxes take the option value; multi-selects take values separated by commas. 14=Botox
clid Google click ID with its type in front: gclid-, gbraid- or wbraid- clid=gclid-abc123
fbclid Meta values, each with its type in front (fbclid-, fbc-, fbp-), joined by a vertical bar, as in the code above fbclid=fbclid-IwAR0x…
referer The page the visitor came from referer=https://www.google.com/

Values with special characters: btoa() only accepts Latin characters. For Arabic or other text, encode first: btoa(unescape(encodeURIComponent(text))). Values can't contain a vertical bar or =, except inside fbclid as shown.

Resize and lead events

The form talks to your page with postMessage. It sends two kinds of message, both from https://amerta.ai, whichever way you embedded it:

When Message
Its height changes An object: { type: "iframeHeight", height: 812, form: { public_id: 245 } }
It is sent A JSON string: '{"status":"success","form_id":245,"submission_id":"…"}'

Add this listener once per page. It resizes the form and fires the Google, Meta and Tag Manager lead events. #amerta-form is the container (script) or the iframe itself (plain iframe).

<script>
window.addEventListener('message', function (event) {
  if (event.origin !== 'https://amerta.ai') return;
  var data = event.data;
  if (typeof data === 'string') { try { data = JSON.parse(data); } catch (e) { return; } }
  var box = document.querySelector('#amerta-form');
  if (!data || !box) return;

  // the form's height: resize it
  if (data.type === 'iframeHeight') {
    box.style.height = Math.ceil(data.height) + 'px';
    return;
  }

  // the form was sent: the lead events
  if (data.status === 'success') {
    if (typeof gtag === 'function') gtag('event', 'generate_lead', { form_id: data.form_id });
    if (typeof fbq === 'function') fbq('track', 'Lead', {}, { eventID: data.submission_id });
    window.dataLayer = window.dataLayer || [];
    dataLayer.push({ event: 'amerta_lead', form_id: data.form_id });
    // optional: window.location.href = '/thank-you/';
  }
});
</script>

Several forms on a page: find the right one by form ID: data.form.public_id for heights, data.form_id for submissions. Put the ID on each container, for example data-form-id="245", and select it with document.querySelector('[data-form-id="' + id + '"]').

Styling the form

Your CSS runs inside the form, so style the form's own classes. The page around the iframe doesn't affect the form.

Class Element
.sb-form-container Wraps the whole form. Also has .sb-form-language-en or .sb-form-language-ar.
.sb-fields-container Holds all the fields.
.sb-fieldset One field with its label and error. Also .sb-fieldset-{type}, by field type.
.sb-field The input, select or textarea. Also .sb-field-{type}.
.sb-phone-cc-wrapper Phone field: country code select and number side by side.
.sb-button-submit The submit button. Gets .loading while sending and .error after a failed send.
.sb-error Error messages under a field or the form.

A starting point for light, borderless fields with a dark submit button:

html, body { background: transparent; }
.sb-form-container { font-family: system-ui, sans-serif; color: #1c2340; }

.sb-field {
  width: 100%;
  padding: 18px 20px;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, .6);
  font-size: 16px;
}
.sb-field:focus { outline: 2px solid #1c2350; outline-offset: -2px; }
textarea.sb-field { min-height: 180px; }

.sb-button-submit {
  padding: 18px 48px;
  border: 0;
  background: #1c2350;
  color: #fff;
  font-size: 18px;
  letter-spacing: .15em;
  text-transform: uppercase;
  cursor: pointer;
}
.sb-error { color: #b3261e; font-size: 13px; }

To find any other element, open the form's address in a browser, right-click the element and choose Inspect. Modern browsers show the page behind a transparent form; only very old ones need allowtransparency on the iframe.

Tracking

With the embed script there is nothing to set up: it saves these on the visitor's first page and passes them to the form. With a plain iframe, pass them yourself with utm_* and data.

Source Saved from Kept for
UTM source, medium, campaign, term, content utm_* in the address. A new campaign replaces the old one. 60 days
Google click ID gclid, gbraid or wbraid 90 days
Meta click ID and browser ID fbclid in the address, otherwise Meta's _fbc and _fbp cookies 90 days
Referrer The first outside site the visitor came from 90 days

Keep the parameters: redirects and link shorteners in front of landing pages must pass the query string through, or the ad source is lost. Use Google Ads auto-tagging and keep Meta's fbclid on.

Test before going live

  1. Open the page with test parameters, such as ?utm_source=test&utm_campaign=embed&gclid=abc123.
  2. Check the form shows your styles and has no inner scrollbar. If it is cut off, the resize listener is missing.
  3. Send a test enquiry.
  4. In Amerta AI, open the new lead. It should show UTM Source test, UTM Campaign embed and Click ID gclid-abc123.
  5. In Meta Events Manager → Test events, or Google Tag Assistant, check the Lead event fired once.

Questions about your form domain or field numbers: ask your Amerta AI account manager.