Need newbie help with stats(SOLVED)


(Columnistdc) #1

Hi everyone!
I have a code:

        function sensdStats() {
          var _paq = _paq || [];
          /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
          // _paq.push(["setCustomDimension", "1", obj[0]]);
          // _paq.push(["setCustomDimension", "2", obj[1]]);
          // _paq.push(["setCustomDimension", "3", obj[2]]);
          _paq.push(["trackPageView"]);
          _paq.push(["enableLinkTracking"]);
          (function() {
            var u = URL;
            _paq.push(["setTrackerUrl", u + "piwik.php"]);
            _paq.push(["setSiteId", "siteID"]);
            var d = document,
              g = d.createElement("script"),
              s = d.getElementsByTagName("script")[0];
            g.type = "text/javascript";
            g.async = true;
            g.defer = true;
            g.src = u + "piwik.js";
            s.parentNode.insertBefore(g, s);
          })();
        }

While im using an anonymous function in console from every site - it works fine, but when I try to fire sendStats() from <script> tag in my HTML - the stats doesnt reach my stats server.
I tried to locate redirections from iOS, Android, Mac, but got nothing.
Can you, please, tell me, what am I doing wrong?


(Lukas Winkler) #2

Hi,

Do you see an error in the JS console? Are you calling sendStats() after you have defined the function?


(Columnistdc) #3

No errors in console at all…
And yes, i call sendStats() after i defined function.
Here is my gist: Matomo example · GitHub


(Columnistdc) #4

The problem was solved.

  1. We should NEVER use matomo tracking in JS “module” pattern.
  2. We should NEVER try to fire matomo tracking from any function in .html file