“JavaScript event” goal
This type of goal lets you track events on a site (button clicks, form submissions, and other events) that occur without the page URL changing. If the URL changes, use the Page view type of goal.
When this type of goal is completed, the information is transmitted to Yandex.Metrica using JavaScript. In this way, you can track almost any custom events.
In E-commerce, use the goal_id field to transmit information about a conversion along with data about the action.
How to create a “JavaScript event” goal
When you create a goal, you set its identifier. When a goal is completed, the reachGoal method is called, and the specified ID is passed to it.
Use identifiers that aren't contained in the site's page URLs. Otherwise, statistics will also include session information for those pages that contain the goal name in the URL.
The following symbols are not allowed in goal identifiers: /, &, #, ?, =.
-
Use the reachGoal method on site pages.
Examples:
XXXXXX
is your tag ID.TARGET_NAME
is the goal identifier.XXXXXX
is your tag ID.TARGET_NAME
is the goal identifier.
Clicking a button... <form action=""> ... <input type="button" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;" value="Order" /> </form> ...
where:
Filling in a form...<form action="" method="get" onsubmit="yaCounterXXXXXX.reachGoal('TARGET_NAME', function () {alert('Data sent successfully');}, <The context accessible with the 'this' keyword in the callback function>); return true;"> ...</form>...
where:
- In the Yandex.Metrica interface, go to Add goal. and click
- In the Name box, enter a name for the goal to create.
- Set the option to JavaScript event.
- Specify the ID of the goal.
- Click Add goal and save changes.
Yandex.Metrica begins collecting statistics in just a few minutes after saving settings.

Restrictions
- A maximum of 200 goals can be set for each tag.
- The service registers a user completing the same goal on the same tag no more than once per second.
- During a single user session, the service can register up to 400 completions of all the goals created for the tag.
- If you edit the tag or a goal, all the previously collected information does not change.
- If you delete a goal, the information collected for it will not be available in reports.