Answer the question
In order to leave comments, you need to log in
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
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);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question