V
V
Vadim Guk2017-05-21 13:12:10
Yandex
Vadim Guk, 2017-05-21 13:12:10

Yandex metrica, how to do without the counter number (yaCounter000000.reachGoal -> yaCounter.reachGoal)?

The question arose of setting up analytics and goals on many sites.
How can you do without the counter number to call the API functions?
Reformat yaCounter000000 into a single record where you don't have to substitute the counter number all the time?
yaCounter000000.reachGoal() -> yaCounter.reachGoal();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Guk, 2017-05-21
@Stiflerus

I asked the question myself and I will answer it myself)
I found the solution:

function metrikaReach(goal_name) {
  for (var i in window) {
    if (/^yaCounter\d+/.test(i)) {
      window[i].reachGoal(goal_name);
    }
  }
}

And in ajax submitting the form I call the function metricaReach(formName);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question