reachGoal
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” type of 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 |
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” type of 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 |
* Required parameter.
Use the reachGoal method if you need to customize when to register a conversion:
-
On the tag editing page, create a goal with the “JavaScript event” type and assign an ID to it.
-
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.
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:
- Solution 1
-
<script type="text/javascript"> window.onload = function() { ym(XXXXXX, 'reachGoal', 'TARGET_NAME') } </script>
- Solution 2 (for jQuery)
-
<script type="text/javascript"> $(window).load(function() { ym(XXXXXX, 'reachGoal', 'TARGET_NAME') }); </script>
...
<form action="" method="get" onsubmit="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;">
...
</form>
...
...<form action="">
...
<input type="button" onclick="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;" value="Order" /></form>
...
...
<a href="/price.zip" onclick="ym(XXXXXX, 'reachGoal', 'TARGET_NAME'); return true;">Price list</a>
...
...<script type="text/javascript">
var goalParams = {myParam: 123};
function goalCallback () {
console.log('Request sent to Yandex.Metrica');
}</script>
<a href="/price.zip" onclick="ym(XXXXXX, reachGoal, 'TARGET_NAME', goalParams, goalCallback); return true;">Price list</a>
...
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:
Goal price (value)
The goal price can be transmitted even if the site is not an online store. This amount will be transmitted each time the goal is completed. This helps you take the goal's commercial viability into account.
For example, your email distribution has a 10% conversion rate, and the order amount for a service or product is 10,000 rubles. In this case, you can set the goal value at 1,000 rubles. You can also use points or symbolic units for designating the value: 1 is low, and 10 is high.
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.
Parameter | Default value | Type | Description |
---|---|---|---|
order_price | — | Double | Goal price |
currency | — | string | Three-letter ISO 4217 currency code. If a different currency is passed, null values will be sent instead of currencies and amounts. |
Parameter | Default value | Type | Description |
---|---|---|---|
order_price | — | Double | Goal price |
currency | — | string | Three-letter ISO 4217 currency code. If a different currency is passed, null values will be sent instead of currencies and amounts. |
...
var goalParams =
{
order_price: 1000.35,
currency: "RUB"
}
...
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>
...