Guide

How to track form submissions in Umami on WordPress

Umami does not know when a WordPress form was sent. You tell it, with an event. The reliable way is to wait for the form plugin's own success signal, so failed attempts are not counted.

Last updated

Short answer

To track form submissions in Umami on WordPress, send an Umami event when the form plugin reports a successful submission. Each plugin announces success with a JavaScript event, such as wpcf7mailsent in Contact Form 7. Listen for it and call umami.track('form_submit'). Putting data-umami-event on the submit button is quicker, but it counts clicks, not submissions. Connect for Umami does this without code.

Three ways to track a form, compared

data-umami-event on the buttonJavaScript on the success eventConnect for Umami
Counts only successful submissionsNoYesYes
Works without writing codePartlyNoYes
Tells forms apartBy the names you type inBy form IDBy form name, form ID and plugin
Forms that reload the page instead of using AJAXClicks are still countedNot covered by the snippets belowYes

Approach 1: data-umami-event on the submit button

Umami records a click on any element that has a data-umami-event attribute. Extra data-umami-event-* attributes are sent with it as event data, always as text.

A submit button that Umami counts clicks on
<button type="submit" data-umami-event="contact_form_click" data-umami-event-form="Contact">Send</button>

This is a click counter. It fires when the button is pressed, including when the form then shows a validation error or the message is never sent. Form plugins also build the submit button for you and often give you no place to add an attribute, so in practice this suits forms whose HTML you write yourself.

Approach 2: send an Umami event when the form plugin reports success

The six form plugins below each announce a successful submission in JavaScript. Listen for that announcement, then call umami.track.

  1. Find your form plugin's success event

    Use the table below. Each plugin has its own event, and some only fire for forms that submit with AJAX.

  2. Copy the matching snippet

    Each snippet further down sends form_submit with the plugin and the form ID. Add details of your own if you like, but never send what was typed into the form.

  3. Add the JavaScript to WordPress

    Load it with wp_add_inline_script() or a code-snippets plugin, as shown after the snippets.

  4. Test a failed and a successful submission

    In a private browser window, submit the form with a required field left empty, then submit it properly. Only the second attempt should appear as form_submit under Events in Umami.

The success event of each form plugin

Form pluginEventHow it is announcedNotes
Contact Form 7wpcf7mailsentDOM event that bubbles up to documentForm ID in event.detail.contactFormId
Gravity Formsgform_confirmation_loadedjQuery event on documentOnly AJAX-enabled forms that show a confirmation message
WPFormswpformsAjaxSubmitSuccessjQuery event on the formOnly when AJAX form submission is enabled for the form
Elementor Formssubmit_successjQuery event on the formPart of Elementor Pro
Fluent Formsfluentform_submission_successjQuery event on document.bodyThe form is passed in the second argument
Ninja FormsnfFormSubmitResponsejQuery event on documentFires for every server response, so check it for errors
Contact Form 7
// Contact Form 7: wpcf7mailsent fires when the message has been sent.
document.addEventListener('wpcf7mailsent', function (event) {
	if (!window.umami) return; // Tracker blocked or not loaded.
	umami.track('form_submit', { plugin: 'contact-form-7', form_id: String(event.detail.contactFormId) });
});
Gravity Forms (AJAX forms only)
// Gravity Forms: gform_confirmation_loaded fires when an AJAX form shows its confirmation.
jQuery(document).on('gform_confirmation_loaded', function (event, formId) {
	if (!window.umami) return; // Tracker blocked or not loaded.
	umami.track('form_submit', { plugin: 'gravity-forms', form_id: String(formId) });
});
WPForms (AJAX form submission enabled)
// WPForms: wpformsAjaxSubmitSuccess fires on the form after a successful AJAX submission.
jQuery(document).on('wpformsAjaxSubmitSuccess', function (event) {
	if (!window.umami) return; // Tracker blocked or not loaded.
	umami.track('form_submit', { plugin: 'wpforms', form_id: event.target.getAttribute('data-formid') || '' });
});
Elementor Forms (Elementor Pro)
// Elementor Forms: submit_success fires on the form after a successful submission.
jQuery(document).on('submit_success', function (event) {
	var form = event.target;
	if (!window.umami || !form.matches || !form.matches('.elementor-form')) return;
	var id = form.querySelector('[name="form_id"]');
	umami.track('form_submit', { plugin: 'elementor', form: form.getAttribute('name') || '', form_id: id ? id.value : '' });
});
Fluent Forms
// Fluent Forms: fluentform_submission_success fires on document.body after a successful submission.
jQuery(document.body).on('fluentform_submission_success', function (event, data) {
	if (!window.umami) return; // Tracker blocked or not loaded.
	var form = data && data.form ? data.form[0] : null;
	umami.track('form_submit', { plugin: 'fluent-forms', form_id: form ? form.getAttribute('data-form_id') || '' : '' });
});
Ninja Forms
// Ninja Forms: nfFormSubmitResponse fires on document for every server response,
// so count only the responses that came back without errors.
jQuery(document).on('nfFormSubmitResponse', function (event, data) {
	var errors = (data && data.response && data.response.errors) || {};
	if (!window.umami || !data || Object.keys(errors).length) return;
	umami.track('form_submit', { plugin: 'ninja-forms', form_id: String(data.id) });
});

How to add the JavaScript to WordPress safely

Do not paste the code into a theme file that an update can overwrite. Two safe places:

  • A code-snippets plugin. Create a JavaScript snippet for the front end and set it to load in the footer, so it runs after jQuery and after the page body exists.
  • wp_add_inline_script() in a child theme's functions.php, as below. The code is attached to a script handle that depends on jQuery, so WordPress loads jQuery first and prints your code in the footer.

Five of the six snippets listen for jQuery events, because that is how those plugins announce a submission. The Contact Form 7 snippet needs no jQuery.

functions.php: load a snippet with wp_add_inline_script()
add_action( 'wp_enqueue_scripts', function () {
	// A handle with no file of its own: it only carries the inline code.
	// The jquery dependency makes WordPress load jQuery first.
	wp_register_script( 'umami-form-events', false, array( 'jquery' ), null, true );
	wp_enqueue_script( 'umami-form-events' );

	// Put the snippet for your form plugin between the two JS markers.
	$js = <<<'JS'
document.addEventListener('wpcf7mailsent', function (event) {
	if (!window.umami) return; // Tracker blocked or not loaded.
	umami.track('form_submit', { plugin: 'contact-form-7', form_id: String(event.detail.contactFormId) });
});
JS;

	wp_add_inline_script( 'umami-form-events', $js );
} );

The no-code way: Connect for Umami

  1. Switch on form tracking

    In WordPress, go to Settings → WPUmami → Events, tick Form submissions and save. The setting shows which of the supported form plugins are active on your site.

  2. Submit a test form

    Use a private browser window, because logged-in administrators are not tracked by default. Then look for form_submit under Events in Umami.

What the plugin sends

One event with three details. Nothing typed into the form is ever sent.

EventWhen it is sentData sent with it
form_submitA form is submitted successfully.
form
The form's name or title
form_id
The form's ID
plugin
gravity-forms, contact-form-7, wpforms, elementor, fluent-forms, ninja-forms or html

Beyond what the snippets do, the plugin covers Gravity Forms and WPForms forms that do not use AJAX, and reports a confirmation that redirects to another page on your site from the page the visitor lands on. Other HTML forms are counted when they are submitted, with the plugin value html; search, login, comment, cart and checkout forms are left out. Each integration has its own page: Gravity Forms, Contact Form 7, WPForms, Elementor Forms, Fluent Forms and Ninja Forms.

Frequently asked questions

Does Umami track form submissions automatically?

No. Umami records pageviews automatically. A form submission has to be sent as an event: with a data-umami-event attribute, with umami.track in JavaScript, or by a plugin such as Connect for Umami.

Why does data-umami-event on my submit button show more submissions than I received?

Because it counts clicks on the button, not completed submissions. Every press is recorded, including the ones that end in a validation error. To count real submissions, listen for the form plugin's success event.

Why does gform_confirmation_loaded not fire for my Gravity Forms form?

It fires only for AJAX-enabled forms, when the confirmation message is displayed. Switch on AJAX where the form is embedded, for example with ajax="true" in the shortcode. If the confirmation redirects to a thank-you page, count views of that page in Umami instead.

Does Umami record what people type into my forms?

Only if you send it. The snippets on this page send the form plugin and the form ID. Do not add field values such as names or email addresses, because that would put personal data into Umami. Connect for Umami sends only the form's name, its ID and the plugin.

Where do I see form submissions in Umami?

Open the website in Umami and go to Events. form_submit appears in the list of events, and the Properties tab breaks the submissions down by form_id and plugin.

Do I need jQuery to track form submissions in Umami?

Only to hear the form plugin. Umami itself needs no jQuery. Contact Form 7 announces success with a standard DOM event, so its snippet is plain JavaScript. The snippets for Gravity Forms, WPForms, Elementor Forms, Fluent Forms and Ninja Forms listen for jQuery events.

Connect WordPress to Umami in about two minutes

One plugin: the tracking script, events, store revenue and your stats inside WordPress. Plans start at $12 a year, with a 14-day money-back guarantee.

See pricing