A
A
Alexey Sklyarov2017-09-05 22:01:51
JavaScript
Alexey Sklyarov, 2017-09-05 22:01:51

How to get the metric counter number and call it in your script?

There are several pages with a connected metric code:

(function (d, w, c) {
        (w[c] = w[c] || []).push(function() {
            try {
                w.yaCounterXXXXXXXX = new Ya.Metrika({
                    id:XXXXXXXX,
                    clickmap:true,
                    trackLinks:true,
                    accurateTrackBounce:true,
                    webvisor:true
                });
            } catch(e) { }
        });

        var n = d.getElementsByTagName("script")[0],
            s = d.createElement("script"),
            f = function () { n.parentNode.insertBefore(s, n); };
        s.type = "text/javascript";
        s.async = true;
        s.src = "https://mc.yandex.ru/metrika/watch.js";

        if (w.opera == "[object Opera]") {
            d.addEventListener("DOMContentLoaded", f, false);
        } else { f(); }
    })(document, window, "yandex_metrika_callbacks");

Each page has a different value for XXXXXXXX. but the script that handles the forms on the pages and adds the targets is the same. I can't understand how it is possible to read the code of the counter that is installed on the site through JS and call it already: with the right code? yaCounterXXXXXXXX.reachGoal('JForma');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
y0u, 2017-09-05
@0example

Try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question