Install Matomo (Piwik) like Roundcube

Discussion in 'Tips/Tricks/Mods' started by MyNameIsSteve, Nov 7, 2021.

  1. MyNameIsSteve

    MyNameIsSteve New Member

    Their website is matomo.org.
    Is there a way to install Matomo analytics like Roundcube?
    I would like to install once and make available for all websites with an ALIAS. I host a dozen sites and want to maintain my ISPconfig integrity. As a last resort I could install it individually to each site but that seems overkill.
    On a default install you get something like https://mysite.com/analytics. It strikes me that this could be very similar to roundcube's https://mysite.com/webmail.
    With recent browser updates (testing on Brave) I get a failure (blocked) if I place the tracking code in a second website such as yoursite.com and it points to mysite.com.

    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    I guess it might work to use one central installation, but never tried that. E.g. create a directory /var/www/matomo and put the matomo files into that directory and chown them to www-data user and group. Then use a similar config to phpmyadmin:

    Code:
    Alias /analytics /var/www/matomo
    
    <Directory /var/www/matomo>
     Options FollowSymLinks
     DirectoryIndex index.php
    
      AllowOverride All
      <IfVersion >= 2.3>
        Require all granted
      </IfVersion>
      <IfVersion < 2.3>
        Order allow,deny
        Allow from all
      </IfVersion>
    
     <IfModule mod_php7.c>
     AddType application/x-httpd-php .php
     </IfModule>
    </Directory>
    
    That's just to get an idea how it might work and there might be additional settings required, have not tested that.
     
  3. MyNameIsSteve

    MyNameIsSteve New Member

    Thanks Till,

    It works.Your help got me what I needed. Below is a brief summary.
    1) Install Matomo to an existing website to a temp dir such as https://mysite.com/temp-matomo
    2) Create the directory /var/www/matomo
    3) Move the contents of temp-matomo to /var/www/matomo
    4) Run chown -R www-data:www-data /var/www/matomo
    4) Delete the temp-matomo direcory
    5) Create an etc/matomo directory
    6) Create etc/matomo/apache.conf file with your ALIAS code snippet from above
    7) Create a link file /etc/apache2/conf-available/matomo.conf pointing to etc/matomo/apache.conf
    8) Create a link in /etc/apache2/conf-enabled pointing to ../conf-available/matomo.conf
    9) Restart apache
    10) Go to https://mysite.com/matomo

    This gets things working better with one install and multiple web sites, but ublock origin is still catching it.
    I made links to matomo.js and matomo.php (test.js and test.php) and change the tracking code to match.
    This almost worked, but ublock origin was still catching it. I found a web post stating to add a / to test.php and now it seems to work.

    Code:
    <!-- Matomo -->
    <script>
      var _paq = window._paq = window._paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u="https://mysite.com/analytics/";
        _paq.push(['setTrackerUrl', u+'test.php/']);
        _paq.push(['setSiteId', '3']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.async=true; g.src=u+'test.js'; s.parentNode.insertBefore(g,s);
      })();
    </script>
    <!-- End Matomo Code -->
    I will have to do a bit more testing to be sure.
     
    zenny and till like this.
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Thanks for documenting the steps in detail! I'll move the post to the tips & tricks forum to find it easier in the future.
     
    zenny likes this.
  5. zenny

    zenny Member

    That is nifty. What about nginx config? Any idea? Thanks.
     
  6. MyNameIsSteve

    MyNameIsSteve New Member

    Sorry. I don't have any knowledge about nginx. Maybe Till will answer.
    One more thing.
    When you update Matomo, be careful not to delete the four files:
    matomo.js
    matomo.php
    test.js
    test.php
    The System Check/File Integrity will flag the two test.* files and suggest you delete the 2 matomo.(js/php) files.
    This would create a broken system. Just leave them alone and you are good to go.
    Good luck.
     
    zenny likes this.
  7. zenny

    zenny Member

    @till Look forward to your input, if any. Cheers,
     

Share This Page