Forminal

Listen for Embed Events

When a form is embedded on your site, the embed script tells your page what happens inside it: the form loaded, the visitor moved to another page, the form was sent, a popup opened or closed. Each one is a browser event on window, so your own code can count it in your analytics or show the visitor what comes next. By the end of this guide you’ll have a listener on your page that logs every event. Events never include what the visitor typed; to receive the submissions, use a webhook.

Listen for events

  1. Put the form on your page with any snippet from the Embed tab of the Share panel: inline, full page, popup, floating button or slider. Every snippet loads the same embed.js, and that script sends the events.
  2. Add your own script to the page that listens on window. Each event’s data is in event.detail, and event.detail.formId always names the form, so one listener can tell several forms on a page apart.
  3. Open the page, fill in the form and send it. Your browser’s console shows each event as it happens.
const events = ['form:loaded', 'form:page', 'form:submitted', 'form:opened', 'form:closed']
for (const type of events) {
  window.addEventListener(type, (event) => console.log(type, event.detail))
}

window.addEventListener('form:submitted', (event) => {
  console.log('Form sent:', event.detail.formId)
})

You can see the same events before you write any code. In the builder, open Share » Embed and select Events on Your Page under the preview. The list starts closed; once open, it shows the last 50 events your page would get, with their details, as you click through the form in the preview.

The events

form:loaded

The form has loaded in its frame. Detail: { formId, page: 1, storesOnDevice }. storesOnDevice is false when the form has Disable User Cookies turned on, so your page knows not to keep anything about this form in the visitor’s browser either.

form:page

The visitor is now on another page of a multi-page form. Detail: { formId, page }. page starts at 1 and counts only the pages this visitor can see, so a page that logic skips isn’t counted. Because of that, it can also fire without the visitor pressing Next or Back, when an answer shows or hides an earlier page and the current page’s number changes.

form:submitted

The form was sent and the submission is saved. Detail: { formId }, on every form and every plan. It doesn’t include the answers (see Getting the answers below).

form:opened and form:closed

A popup, the corner popup from a floating button, or the slider opened or closed. Detail: { formId } when it opens, and { formId, reason } when it closes. reason is one of these:

  • button: the visitor pressed the close button.
  • overlay: the visitor clicked the dimmed page around it.
  • escape: the visitor pressed Escape.
  • submitted: it closed on its own after the form was sent.

A close your own code starts with window.FormsEmbed.closePopup(), or opening another popup over it, has no reason.

Getting the answers

Events report what happened on the form. None of them includes an answer, on any form or plan, so other scripts on your page, such as tag managers and analytics, can’t read answers from them.

To receive the submissions, add a webhook to the form. It sends each new submission to a URL you choose, from our server to yours, so the answers never pass through the page. You can still use form:submitted on the page to thank the visitor or count the conversion.

Good to know

  • Events come from embedded forms only. A visitor on the form’s own link, outside your site, sends your page nothing.
  • If a payment has to leave the frame to be confirmed, and the visitor finishes on the form’s own page, no form:submitted fires. A payment confirmed inside the frame fires it as usual.
  • Forminal stores nothing about the events. The submission is saved the same way whether or not your page listens.
  • If your page adds a form’s frame after it has loaded, call window.FormsEmbed.loadEmbeds() so the script picks it up and starts sending its events.

Frequently asked questions

Can another website read the answers from my embedded form?

No. Events never include answers, only the news that something happened, such as the form being sent. To receive the submissions, use a webhook.

Why did form:page fire when the visitor did not change page?

The page number counts only the pages the visitor can see. When an answer shows or hides an earlier page, the current page’s number changes, and the event reports the new number.

Do events work with every embed type?

Yes. Inline, full page, popup, floating button and slider all load the same script and send the same events. Only the popup, the floating button’s corner popup and the slider send form:opened and form:closed.

How do I get the submissions from an embedded form?

Add a webhook to the form. It sends each new submission, answers included, to a URL you choose on your own server.

Related feature: Embed Forms