D
D
diversant1232017-03-17 17:59:17
JavaScript
diversant123, 2017-03-17 17:59:17

How to get Yandex Metrica counter id?

How to get the id-counter of Yandex Metrica installed on the site using js?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2017-03-17
@NeiroNx

var id = Ya.Metrika.counters()[0].id;
Pokovyryal, it turns out there is an array of counters.
ID of the counter on the site with enabled webvisor:

var id = Ya.Metrika.counters().filter(x => x.webvisor)[0].id;

A
Alexander Aksentiev, 2017-03-17
@Sanasol

not normally.

for(var i in window){
    if(new RegExp(/yaCounter/).test(i)){
        console.log(i);
    }
}

I
Igor, 2020-08-28
@dicr

there is also a window.Ya._metrika.counters object with id => counter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question