title: Why is the piwik tracking script not usually directly included on the page?
body: <p>Piwik (analytics software), works by including a small script just before the <code>&lt;/body&gt;</code>:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    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);
    })();
  &lt;/script&gt;
  </code></pre>
  
  <p>This script will then include <code>piwik.js</code> (basically <a href="https://cdnjs.cloudflare.com/ajax/libs/piwik/2.8.0/piwik.js" rel="nofollow">this script</a>) from your piwik installation on the page. <code>piwik.js</code> records a couple of things (screen size, ip, etc.) and sends that to your piwik installation in a GET request, to register the pageview.</p>
  
  <p>Now I don't understand why you would not just include piwik.js on your page straightaway. Why go through the trouble of fetching it from a separate location when you can just concatenate and minify it with the rest of your scripts?</p>
  
  <p>It <em>is</em> possible to host <code>piwik.js</code> on a cdn (see <a href="http://christonard.com/hosting-piwik-js-on-a-cdn/" rel="nofollow">here</a> and <a href="http://forum.piwik.org/read.php?2,112345,page=1#msg-112386" rel="nofollow">here</a>), so I'm wondering why you wouldn't skip that step and concatenate it with the rest of your scripts and optimize from there?</p>
  
  <hr>
  
  <p><em>Google analytics does the same thing I believe, so the answer doesn't need to be specific to Piwik as long as it applies to both.</em></p>