“JavaScript event” goal
This type of goal lets you track events on a site (such as button clicks and form submissions) that occur without the page URL changing. If the URL changes, use the Page view goal.
When this type of goal is completed, the information is transmitted to Yandex Metrica using JavaScript. This lets you track almost any custom event.
How to create a “JavaScript event” goal
When you create a goal, you set its ID. When a goal is completed, the reachGoal method is called, and the specified ID is passed to it.
This type of goal can be used on Turbo pages.
Use IDs that aren't contained in page URLs for the website. Otherwise, statistics will also include session information for pages that contain the goal name in the URL.
The following symbols are not allowed in goal IDs: / \ & # ? = ". If you want to add a plus sign to the ID, enter %2B in place of the + character.
- In Yandex Metrica, use the left menu to go to the Goals page and click Add goal.
- In the Name field, enter a name for the goal to create.
- Choose the JavaScript event goal type.
- Specify the goal ID. The Goal code for the site appears under the ID field. Copy the code. You'll need it to configure the reachGoal method on your site.
- 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.
Use the reachGoal method on site pages.
Examples:
... <form action=""> ... <input type="button" onclick="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;" value="Заказать" /> </form> ...
... <form action="" method="get" onsubmit="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;"> ... </form> ...
where
ym(XXXXXX, 'reachGoal', 'TARGET_NAME')
is the goal code for the site from the goal settings.- Check whether the goal is working correctly.
Restrictions
- A maximum of 200 goals can be set for each tag.
- The service registers a user that completes 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 a tag.
- If you edit a tag or goal, previously collected information doesn't change.
- If you delete a goal, information collected for it, is no longer available in reports.