Why isn't piwik script tracking usually included directly on the page?

Piwik (analytic software) works by including a small script just before </body>:

<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//piwik.example.com";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 1]);
    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);
  })();
</script>

This script will include piwik.js(basically this script ) from your piwik installation on the page. piwik.jsrecords a few things (screen size, ip, etc.) and sends them to your piwik installation in a GET request to register a pageview.

Now I don’t understand why you didn’t just include piwik.js on your page right away. Why worry about pulling it out of a separate place when you can just concatenate and minimize it with the rest of your scripts?

piwik.js cdn (. ), , ?


Google Analytics , , Piwik, .

+4

Source: https://habr.com/ru/post/1568321/


All Articles