# Matomo Web Analytics

> Privacy-focused Google Analytics alternative for web analytics.

- Category: Monitoring & Observability
- Difficulty: beginner
- Components: matomo, mariadb
- Tags: analytics, matomo, privacy, web-analytics, ga-alternative
- Source: https://docker.recipes/monitoring/matomo-analytics

## Overview

Matomo (formerly Piwik) is an open-source web analytics platform that serves as a privacy-focused alternative to Google Analytics. Originally launched in 2007, Matomo has become the leading self-hosted analytics solution, offering complete data ownership and GDPR compliance while providing comprehensive visitor tracking, conversion analysis, and behavioral insights. Unlike cloud-based analytics services, Matomo gives organizations full control over their data collection and storage.

This stack combines Matomo with MariaDB to create a robust analytics infrastructure that processes visitor data efficiently while maintaining data sovereignty. MariaDB's enhanced MySQL compatibility ensures optimal performance for Matomo's data-intensive operations, while its Aria storage engine provides better crash recovery for analytics data. The combination leverages MariaDB's improved thread pool handling to manage concurrent visitor tracking requests and complex report generation queries simultaneously.

This configuration is ideal for organizations requiring GDPR compliance, companies seeking independence from third-party analytics providers, and businesses needing detailed visitor insights without data sharing restrictions. Privacy-conscious websites, European organizations under strict data protection laws, and enterprises managing sensitive customer data will find this self-hosted analytics solution particularly valuable for maintaining complete control over visitor information.

## Features

- Real-time visitor tracking with heatmaps, session recordings, and conversion funnel analysis
- GDPR-compliant data collection with built-in privacy controls and cookie consent management
- Google Analytics data import wizard for migrating historical analytics data
- Custom dimension tracking for e-commerce goals, form submissions, and event monitoring
- MariaDB's Aria storage engine optimized for analytics workloads with better crash recovery
- Multi-site analytics management from a single Matomo installation
- Advanced segmentation and custom reporting with scheduled email delivery
- Plugin ecosystem supporting A/B testing, cohort analysis, and marketing attribution

## Use cases

- E-commerce websites tracking conversion funnels and customer behavior analytics
- European businesses requiring GDPR-compliant visitor analytics without third-party data sharing
- Marketing agencies managing analytics for multiple client websites from one dashboard
- Content publishers analyzing article performance and reader engagement metrics
- SaaS companies tracking user onboarding flows and feature adoption rates
- Educational institutions monitoring course completion and student portal usage
- Healthcare organizations needing HIPAA-compliant website analytics with data residency

## Prerequisites

- Minimum 1GB RAM for MariaDB operations and Matomo report generation
- Port 8080 available for Matomo web interface access
- Environment variables DB_PASSWORD and DB_ROOT_PASSWORD configured in .env file
- Understanding of JavaScript tracking code implementation for website integration
- Basic knowledge of analytics concepts like goals, conversions, and custom dimensions

## docker-compose.yml

```yaml
services:
  matomo:
    image: matomo:latest
    container_name: matomo
    environment:
      - MATOMO_DATABASE_HOST=db
      - MATOMO_DATABASE_ADAPTER=mysql
      - MATOMO_DATABASE_TABLES_PREFIX=matomo_
      - MATOMO_DATABASE_USERNAME=matomo
      - MATOMO_DATABASE_PASSWORD=${DB_PASSWORD}
      - MATOMO_DATABASE_DBNAME=matomo
    volumes:
      - matomo-data:/var/www/html
    ports:
      - "8080:80"
    depends_on:
      - db
    networks:
      - matomo-network
    restart: unless-stopped

  db:
    image: mariadb:10.11
    container_name: matomo-db
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
      - MYSQL_DATABASE=matomo
      - MYSQL_USER=matomo
      - MYSQL_PASSWORD=${DB_PASSWORD}
    volumes:
      - mariadb-data:/var/lib/mysql
    networks:
      - matomo-network
    restart: unless-stopped

volumes:
  matomo-data:
  mariadb-data:

networks:
  matomo-network:
    driver: bridge
```

## .env

```bash
# Matomo Analytics
DB_PASSWORD=secure_matomo_password
DB_ROOT_PASSWORD=secure_root_password
```

## Usage notes

- Web UI at http://localhost:8080
- Complete installation wizard
- Add tracking code to websites
- GDPR compliant analytics
- Importers for Google Analytics

## Troubleshooting

- Matomo shows database connection error: Verify MariaDB container is running and DB_PASSWORD matches in both services
- Installation wizard fails at database step: Check that MATOMO_DATABASE_HOST points to 'db' service name
- Tracking code not recording visits: Ensure JavaScript tracking code is properly embedded before closing </head> tag
- MariaDB container crashes during startup: Increase Docker memory allocation to minimum 1GB for stable operation
- Reports loading slowly or timing out: Optimize MariaDB performance by increasing innodb_buffer_pool_size in database configuration
- Archive processing fails with memory errors: Add PHP memory limit environment variable MATOMO_GENERAL_MEMORY_LIMIT_WHEN_ARCHIVING=2048M

