I forgot, I also set up cron
to process the logs every hour. Type crontab -e
and then add the following line (adjusting the "5", the username, application name, URL:
5 * * * * /usr/bin/php /home/USERNAME/apps/analytics-mysite-com-php/console core:archive --url=https://analytics.mysite.com >/dev/null
Before doing so, it's best to test the command, e.g. just type
/home/USERNAME/apps/analytics-mysite-com-php/console core:archive --url=https://analytics.mysite.com
You can then check it works and it also tells you how you can change a setting in the UI once the cron command is in place.
The Matomo software explains what tracking code to put in your web pages of course and the code will first load the file matomo.js
from the application folder (e.g. analytics-mysite-com-php
). I wanted serve the file compressed and control the caching of it. Neither of these things are possible with the front-end nginx server. You could switch to Apache+PHP as the application instead and then use an .htaccess
file to control the compression and cache but I realised that it was fairly simple to just change the tracker code so that the matomo.js
file comes from my main website rather than the "analytics" sub-domain. It doesn't matter to Matomo where the javascript is served from. The only caveat is that apparently some extensions will modify the matomo.js
file and so you'd have to copy it over to your other site again.
My tracking code (e.g. web site is hosted on mysite.com
, matomo is on analytics.mysite.com
) looks something like this:
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
// accurately measure the time spent in the visit
_paq.push(['enableHeartBeatTimer']);
(function() {
_paq.push(['setTrackerUrl', '//analytics.mysite.com/matomo.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.src='/js/pckg/matomo/matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
I copied the matomo.js
file into the folder /js/pckg/matomo
on my main site, made a compressed version with brotli and made use of the existing Apache .htaccess
config I have for serving brotli files when appropriate.