Track form submissions
If you have forms on your site, Yandex Metrica can show you how often users complete them. Depending on how the form is implemented, you can track both the click on the button and the form submission.
To do this, you need to set a special goal in Yandex Metrica. You can create this kind of goal:
- For all forms on your site.
- For a specific form. Use this method, for example, to track different forms.
To create a goal manually:
-
In Yandex Metrica, go to the Goals page in the left menu.
-
Click Add goal.
-
In the Name field, enter a name for the goal to create.
-
Select the Form submission goal type.
-
Select which forms to create a goal for. If you chose Specific form, enter the webpage where the form is placed in the field and click Go and select a form. In the window that opens, Yandex Metrica highlights the forms that were found on the page. Select the one you need.
Why form selection may be unavailable -
Click Add goal. The created goal will appear in the list of goals. Yandex.Metrica will start collecting statistics on it within a few minutes.
-
Check whether the goal is working correctly.
Alert
Before using this type of goal in ads, check that the goal is set up correctly and that it can be achieved on your site. If you change the HTML structure of your site, the goal may not work correctly.
Goal completion is registered when a user clicks the form submission button. To view goal statistics, use the Conversions report and add the goal to other Yandex Metrica reports.
Yandex Metrica recognizes a form on your site if it finds the form
element and some form parameters: ID
, name
, or the XPATH
path to the element. When you add a goal, Yandex Metrica displays the parameter that was recognized. It indicates which form the goal was created for — you may find it convenient to distinguish Yandex Metrica goals in the list of goals. When checking the achievement of goals, it does not take into account which page this form was selected on.
Learn more about XPATH
XPATH
is a query language that you can use to locate specific elements in XML and HTML documents. You can use it to specify the path to a specific element or group of elements.
<html>
<body>
<div class="container">
<p>First paragraph.</p>
<ul>
<li>First element of the list.</li>
<li>Second element of the list.</li>
</ul>
<p>Second paragraph.</p>
</div>
</body>
</html>
To locate the second element of the list (<li>
), use the following XPATH
query:
//HTML/BODY/DIV/UL/LI[2]
Site requirements
When creating a goal, it is important to consider:
- The form must be created using the
form
tag. If a form is made withdiv
tags, it won't be tracked. - The form must be submitted using the
button type="submit"
andinput type="submit"
elements. If form submission is implemented via thebutton type="button"
element, no goal is achieved. - The
button type="submit"
andinput type="submit"
elements must be nested within theform
element.
If the form is processed using JavaScript, the goal will only work for the standard onSubmit
event.
Data validation
By default, the goal is considered achieved not only when the form is successfully submitted, but also when an unsuccessful attempt is made to send it, for example, when the data from the form has not passed validation.
If you want only form submissions to count towards goal completion and not the click
or submit
events:
- Add the
disabled
attribute to the button code before data validation. - Use CSS to make the button inactive. In this case, the
click
event may be counted, for example, if the scripts were checked on the site before the button was deactivated.
Tip
If you do not have the ability to reconfigure the work of HTML elements on the site, use the JavaScript event goal.
Revenue transfer β
Warning
Sending revenue data is currently in public beta testing. If your site meets the requirements for this feature, but you're experiencing issues while using it, please contact us.
To transmit revenue shown on the page with the button when the Button click goal is achieved, you can select it when setting up the goal:
- In the Select an element mode, select the button for which you want to track clicks.
- On the bottom panel, click Specify revenue. The element selection mode will be activated on the page with the relevant content.
- Select the unit that contains the numerical value of the revenue received when a user clicks the selected button.
- Click Track clicks and complete the goal setup in the Yandex Metrica interface.
You can specify the revenue currency for this type of goal in the tag settings.
Alert
Revenue value will be sent after each button click. If your website doesn't check that users complete the required fields, clicking a button multiple times can send the revenue data multiple times, and this will be added together in your reports.
To verify the accuracy of the transmitted data, follow the instructions.
Recommendations and limitations
- A content element with revenue value should have a unique
XPATH
path or attributesID
orCLASS
in the webpage structure. If HTML page changes, revenue may not be transmitted or may be transmitted incorrectly. - For correct data transmission, the element must contain a numerical value.
- The content element with the revenue value must be located on the same page as the button or form when the goal is achieved.
- If a button click or form submission immediately takes users to a different page, the goal may not register for users with outdated browsers, slow devices, or slow internet.
- To prevent duplicate goal submissions with the same revenue, we recommend adding a check to the button to ensure all conditions for goal submission are met.
Restrictions
-
This type of goal can’t be used in Multi-step goals.
-
The service registers a user reaching the same goal on the same counter no more than once per second.
-
During a single user session, the service can register up to 1000 offline conversions and 400 online conversions created for the tag.
-
If you use iframes on the page, it might not work as expected.
-
If you edit the tag or a goal, all the previously collected information does not change.
-
If you delete a goal, information collected for it is no longer available in reports.
Questions and answers
How do I select a form hidden under a button?
If the button is active in form selection mode, first click it and then select a form.
Sometimes when you select a button, you can’t click it. In this case, do the following:
-
In the Form submission goal settings, select Exact form on website and specify the page with the form.
-
Click Go and select a form.
-
On the page that opens, hover over the button, right-click the context menu, and select Explore element.
-
The Elements tab will have the desired button code selected. Right-click to open the context menu and select Copy -> Copy selector.
-
Open the Console tab and enter
document.querySelector('xxxx').click();
, wherexxxx
is the value you copied. If everything is done correctly, the desired form is highlighted on the page. -
Select the form and confirm your choice.
How do I add a goal to a form that is in an iframe?
If the form is in an iframe
, configure the tag in the code of this iframe
. When creating a goal, you need to specify the iframe
address in the form address field.
The tag is installed on the page with the form, but no goal is created. Why?
You can set a goal for forms with pages that have had traffic in the last 30 days. Make sure that the traffic to the page with the form is recorded by your tag (check the filters, address settings, and so on).
Why is the goal triggered if the form has not been submitted?
If the form has a function to check the validity of its filling, the goal will be registered as being achieved even when someone tries to send an invalid form. In this case, we recommend looking at the converted sessions for this goal.
Are statistics collected if the same form is used on several pages?
If a form with the same ID
is used on different pages, then the created goal will work on all pages.
Will the form work without Session Replay?
If Session Replay is not enabled in the tag settings, the goal can work without it.
Will the goal for the previous version’s tag code work?
The goal may work for the previous version of the tag code.
Does the form work if the "Replace https with http" filter is set?
If the action Change from https to http is enabled in the tag settings on the Filters tab, the form selection mode does not work.
Does the form work with redirects?
If the page where you want to select a form redirects to another one, then form selection is not available. You can create a goal for tracking all forms or use the JavaScript event goal to track the submission of a specific form.
Why can’t I see form selection?
Yandex Metrica only highlights form selection on the pages that were visited in the past 30 days.
If your website uses a Content Security Policy, add the Yandex Metrica domains to the list of exceptions.
Learn more
Useful links |
Online training |