Reference of methods in the previous version

In Yandex Metrica, the code snippet for tags and the JavaScript API methods have been updated. The previous version of the methods is shown below.

addFileExtension

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.

extLink

Sending information about external link traffic.

extLink(url[, options])

The url and options parameters are the same as the parameters in the new version of the method.

file

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.

getClientID

Get the site user ID assigned by Yandex Metrica.

yaCounterXXXXXX.getClientID()
hit

Sends data about a pageview.

hit(url[, options])

Example:

var yaCounterXXXXXX = new Ya.Metrika({id: XXXXXX});
//...
yaCounterXXXXXX.hit('#!contacts', {
    title: 'Contact',
    referer: 'http://example.com/#!main'
});

The url and options parameters are the same as the parameters in the new version of the method.

notBounce

Sends information about non-bounces.

notBounce([options])

The options parameter is the same as the parameter in the new version of the method.

params

Transmitting custom session parameters.

params(parameters)

Examples of transmitting session parameters:

User status
var yaParams = {
    x: 10,
    y: "unauthorized user"
}

var yaCounterXXXXXX = new Ya.Metrika({id: XXXXXX, params: window.yaParams||{}});
A/B testing

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.

If the user is shown a red button, we use the following parameter:

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.

Transmitting a hierarchical data structure
var yaParams = {
    "level1":{"level2":["level3_1","level3_2"]}}
...

The parameters parameter is the same as the parameter in the new version of the method.

reachGoal

Transmits information about a completed goal.

reachGoal(target[, params[, callback[, ctx]]])

Examples of setting goals:

Forms
...
<form action="" method="get" onsubmit="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;">
    ...
</form>
...
For a button:
...
<form action="">
    ...
    <input type="button" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME'); return true;" value="Order" />
</form>
...
Links:
...
<a href="/price.zip" onclick="yaCounterXXXXXX.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 sent to Yandex Metrica');
    }
</script>
<a href="/price.zip" onclick="yaCounterXXXXXX.reachGoal('TARGET_NAME', goalParams, goalCallback); return true;">Price list</a>
...
Goal completion on page loading

If you are using an asynchronous code snippet and the goal is called using the script element, embed the following code in any section of the page:

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>
Setting the value of a goal for a form
...
<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.

setUserID

Transmitting the site user ID set by the site owner.

yaCounterXXXXXX.setUserID("12345")
userParams

Transmitting custom parameters of site users.

userParams(parameters)

The parameters parameter is the same as the parameter in the new version of the method.

Chat with us

Write an email

Please note: Our support team will never initiate a call to you. Do not follow any instructions of people who call you and introduce themselves as the Yandex Metrica support team.