Reference of methods in the previous version
The code snippet for tags has been updated in Yandex Metrica, along with methods of the JavaScript API. The previous version of the methods is shown below.
- Solution 1
-
<script type="text/javascript"> window.onload = function() { yaCounterXXXXXX.reachGoal('TARGET_NAME') } </script>
- Solution 2 (for jQuery)
-
<script type="text/javascript"> $(window).load(function() { yaCounterXXXXXX.reachGoal('TARGET_NAME') }); </script>
Tracks downloads of files with the specified extensions.
addFileExtension(extensions)
The extensions parameter is the same as the parameter in the new version of the method.
Sends information about clicks on outbound links.
extLink(url[, options])
The url and options parameters are the same as the parameters in the new version of the method.
Sends information about file downloads.
file(url[, options])
The url and options parameters are the same as the parameters in the new version of the method.
Gets the site user ID assigned by Yandex Metrica.
yaCounterXXXXXX.getClientID()
Sends data about a pageview.
hit(url[, options])
Example:
var yaCounterXXXXXX = new Ya.Metrika({id: XXXXXX});
//...
yaCounterXXXXXX.hit('#!contacts', {
title: 'Contact information',
referer: 'http://example.com/#!main'
});
The url and options parameters are the same as the parameters in the new version of the method.
Sends information about non-bounces.
notBounce([options])
The options parameter is the same as the parameter in the new version of the method.
Transmits custom session parameters.
params(parameters)
Examples of transmitting session parameters:
var yaParams = {
x: 10,
y: "unregistered user"
}
var yaCounterXXXXXX = new Ya.Metrika({id: XXXXXX, params: window.yaParams||{}});
Let’s say we need to conduct an experiment to determine how the color of the Buy button affects the conversion rate for a “View basket” goal.
var yaParams = {ab_test: "red button"};
If the user is shown a green button, we use the following parameter:
var yaParams = {ab_test: "green button"};
This parameter is transmitted in any convenient way. For example, it can be passed when initializing the tag on product pages or using the reachGoal method that is called when the Buy button is clicked.
var yaParams = {
"level1":{"level2":["level3_1","level3_2"]}}
...
The parameters parameter is the same as the parameter in the new version of the method.
Transmits information about a completed goal.
reachGoal(target[, params[, callback[, ctx]]])
Examples of setting goals:
...
<form action="" method="get" onsubmit="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;">
...
</form>
...
...
<form action="">
...
<input type="button" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;" value="Заказать" />
</form>
...
...
<a href="/price.zip" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;">Price</a>
...
|||UNTRANSLATED_CONTENT_START|||...
<script type="text/javascript">
var goalParams = {myParam: 123};
function goalCallback () {
console.log('запрос в Метрику успешно отправлен');
}
</script>
<a href="/price.zip" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME', goalParams, goalCallback); return true;">Прайс</a>
...|||UNTRANSLATED_CONTENT_END|||
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">
var goalParams =
{
order_price: 1000.35,
currency: "RUB"
}
</script>
<form action="" method="get" onsubmit="yaCounterXXXXXX.reachGoal('TARGET_NAME', goalParams); return true;">
...
</form>
...
The target, params, callback and ctx parameters are the same as in the new version of the method.
Transmitting the site user ID set by the site owner.
yaCounterXXXXXX.setUserID("12345")
Transmitting custom parameters of site users.
userParams(parameters)
The parameters parameter is the same as the parameter in the new version of the method.