reachGoal

  1. Examples
  2. Goal price (value)
Tip. Working with the JavaScript API requires knowledge of HTML and JavaScript. If you don't have these skills, contact your website developer or webmaster.

Transmits information about a completed goal.

ym(XXXXXX, 'reachGoal', target[, params[, callback[, ctx]]]);

Parameter

Default value

Type

Description

target *

string

ID of the goal. The ID is set on the tag editing page when creating or changing a “JavaScript event” goal.

callback

Function

The callback function to call after sending pageview data.

ctx

Object

The context accessed by the this keyword in the callback function.

params

Object

Session parameters

* Required parameter.

Use the reachGoal method if you need to customize when to register a conversion:

  1. On the tag editing page, create a goal with the “JavaScript event” type and assign an ID to it.

  2. Call this function when the goal is completed:

    ym(XXXXXX, 'reachGoal', 'TARGET_NAME');

    where:

    • XXXXXX is the tag ID.
    • TARGET_NAME is the goal identifier.
Attention. The goal identifier (TARGET_NAME) must not be a part of the URL for any of the site's pages. Otherwise, statistics will also include session information for those pages that contain the goal name in the URL.

When setting the goal identifier, do not use the following symbols: /, &, #, ?, =.

Examples

Options for embedding goals in the source code of your site:

For a form
...
<form action="" method="get" onsubmit="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;">
    ...
</form>
...
For a button
...
<form action="">
    ...
    <input type="button" onclick="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;" value="Order" />
</form>
...
For a link
...
<a href="/price.zip" onclick="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;">Price list</a>
...
For a link with transmission of user parameters
...
<script type="text/javascript">
    var goalParams = {myParam: 123};
    function goalCallback () {
        console.log('request successfully sent to Yandex.Metrica');
    }
</script>
<a href="/price.zip" onclick="ym(XXXXXX, reachGoal, 'TARGET_NAME', goalParams, goalCallback); return true;">Price</a>
...
Goal completion on page loading

If you are using an asynchronous code snippet and the goal is called using the script element, insert the following code on any part of the page:

<script type="text/javascript">
    window.onload = function() {
        ym(XXXXXX, 'reachGoal', 'TARGET_NAME')
    }
</script>

Goal price (value)

Note. The value transmitted with the goal achievement in Yandex.Metrica is not considered if key goals are configured in Yandex.Direct.

When you transmit a goal achievement, you can assign a value to the conversion. This helps you take the goal's commercial viability into account. You can use a monetary value or symbolic units (1 — low, 10 — high).

How to calculate the value of a goal

To determine the value, calculate how often visitors who reach the goal become your customers. For example, 10% of users subscribed to the mailing list, and the average order amount for a service or product is 10,000 rubles. Then for the “Subscription” goal, you can enter a value of 1000 rubles (10% of 10,000 rubles). On the other hand, if only 1% of subscribers place an order, you can specify a value of 100 rubles.

This information will be available in reports if you add the Income conversion metric in the Yandex.Metrica interface. For more information, see How to create a report on a goal.

The value can be passed as a

Constant
<script type="text/javascript">
    var goalParams = {
       order_price: 1000.35,
       currency: "RUB"
    }
</script>
Variable
<script type="text/javascript">
     var dynamicPrice = 1000.35;
     var goalParams = {
        order_price: dynamicPrice,
        currency: "RUB"
     }
</script>

Example of setting the goal value for a form:

<script type="text/javascript">
    var goalParams = {
       order_price: 1000.35,
       currency: "RUB"
    }
</script>
<form action="" method="get" onsubmit="ym(XXXXXX, 'reachGoal', 'TARGET_NAME', goalParams); return true;">
    ...
</form>

Parameter

Default value

Type

Description

order_price

Double

Goal cost.

currency

string

Three-letter ISO 4217 currency code.

If a different currency is passed, null values will be sent instead of currencies and amounts.

Select a question to find a solution.

Goals in Yandex.Metrica work the same way for any sources. Perhaps there aren't any users who have completed the goal from this source yet.

This might happen for the following reasons:
  • The goal condition in Yandex.Metrica doesn't cover all the possibilities. For example, the goal is set as going to the order confirmation page, but the site also allows quick orders without visiting this page.
  • The site user has a browser plugin that blocks the Yandex.Metrica tag, so this user isn't counted.
  • The user has an antivirus system with strict privacy settings.
  • The user has a slow internet connection, so the Yandex.Metrica tag didn't load on the target page.