Matomo
- Setting Up Matomo Analytics with a Dedicated MariaDB Instance
- Integrating Matomo Analytics with BookStack
- Integrating Nextcloud Hub 28 with Matomo Analytics
Setting Up Matomo Analytics with a Dedicated MariaDB Instance
Overview
This article details the process of deploying Matomo Analytics using a dedicated, isolated MariaDB database. This method ensures that your analytics data remains separate from other services (like Nextcloud), preventing database conflicts and simplifying maintenance.
Prerequisites
- Host System: Ubuntu Server with CasaOS or Docker installed.
- Storage Path: /DATA/AppData/matomo
- Port Availability: Port 8484
1. Docker Compose Configuration
Use the following configuration for a Custom Install in CasaOS:
services:
matomo_db:
image: mariadb:10.11
container_name: matomo_db
command: --max-allowed-packet=64MB
environment:
- MARIADB_ROOT_PASSWORD=matomo_root_password
- MARIADB_DATABASE=matomo
- MARIADB_USER=matomo
- MARIADB_PASSWORD=matomo_secure
volumes:
- /DATA/AppData/matomo/db:/var/lib/mysql
restart: unless-stopped
matomo_app:
image: matomo:latest
container_name: matomo_app
restart: unless-stopped
ports:
- "8484:80"
environment:
- MATOMO_DATABASE_HOST=matomo_db
- MATOMO_DATABASE_DBNAME=matomo
- MATOMO_DATABASE_USERNAME=matomo
- MATOMO_DATABASE_PASSWORD=matomo_secure
volumes:
- /DATA/AppData/matomo/html:/var/www/html
depends_on:
- matomo_db
2. Database Connection Credentials
During the Matomo web-based setup wizard, use these internal credentials:
| Setting | Value |
|---|---|
| Database Server | matomo_db |
| Login | matomo |
| Password | matomo_secure |
| Database Name | matomo |
3. Implementation on BookStack
- Log in to Matomo and navigate to Administration > Websites > Manage.
- Copy the JavaScript Tracking Code.
- In BookStack, navigate to Settings > Customization.
- Paste the script into the Custom HTML Head Content area and save.
Integrating Matomo Analytics with BookStack
Overview
Once Matomo is installed, you must link it to BookStack to begin capturing visitor data, page views, and search trends. This is done by injecting a small JavaScript snippet into the BookStack header.
1. Retrieve Tracking Code from Matomo
- Log in to your Matomo dashboard (e.g., http://192.168.0.152:8484).
- Click the Gear Icon (Administration) in the top right.
- On the left sidebar, navigate to Websites > Tracking Code.
- Ensure the correct website (e.g., "BookStack") is selected in the dropdown.
- In the JavaScript Tracking Code section, copy the entire block of code.
2. Apply Code to BookStack
- Open your BookStack instance and log in as an Administrator.
- Go to Settings (Gear icon in top navigation).
- Select Customization from the left-hand menu.
- Find the section labeled Custom HTML Head Content.
- Paste your copied Matomo script directly into the text area.
- Scroll to the bottom and click Save Settings.
<!-- Matomo Tracking Script Example -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//YOUR_SERVER_IP:8484/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
3. Verification
- Open your BookStack homepage in a new tab.
- Navigate to the Dashboard in Matomo.
- Check the Visits in Real-time widget; your activity should appear within seconds.
Note: If you use an ad-blocker, you may need to disable it for your local domain to see your own tracking data.
Integrating Nextcloud Hub 28 with Matomo Analytics
This article outlines the steps to connect your self-hosted Nextcloud instance (v33.0.0+) to Matomo for tracking user activity and file browsing.
1. Prerequisites
- Matomo Site ID: Ensure you have created a "Measurable" for Nextcloud. For this setup, the Site ID is 3.
- Nextcloud Version: Hub 28 Winter (v33.0.0).
- App Version: Matomo Tracking (v1.0.0).
2. Matomo Configuration
- Log in to your Matomo instance at
https://matomo.goonersnas.com/. - Navigate to Administration (Cog Icon) > Websites > Manage.
- Verify that the URL for Site ID 3 is set to
https://nc.goonersnas.com/.
3. Nextcloud App Installation
- Log in to Nextcloud as an Administrator.
- Go to Apps and select the Integration category.
- Search for "Matomo Tracking".
- Note: Avoid the legacy "Piwik" version (v0.13.0) as it is incompatible with v33.
- Click Download and enable (you may need to click "Allow untested app").
4. Connection Settings
Note: Ensure the URL includes the trailing slash. Settings save automatically upon losing focus from the text fields.
5. Verification
- Open Nextcloud in an Incognito/Private browser window and navigate through a few folders.
- Return to Matomo and go to Dashboard > Real-time > Visitor Log.
- Look for active visits originating from your Nextcloud domain.
6. Troubleshooting & Security
Content Security Policy (CSP)
If tracking fails to report, you may need to whitelist your Matomo domain in the Nextcloud config.php file:
Nginx Proxy Manager
Ensure that your Matomo proxy host does not have "Block Common Exploits" enabled if it interferes with the tracking .js delivery to external subdomains.