GoatCounter Analytics
Simple, privacy-friendly web analytics without tracking users.
Overview
GoatCounter is an open-source, privacy-focused web analytics platform created by Martin Tournoij that provides website traffic insights without tracking individual users or violating privacy. Unlike traditional analytics solutions that collect personal data and use cookies, GoatCounter focuses on aggregate statistics while respecting visitor privacy and GDPR compliance. It offers a lightweight alternative to Google Analytics with essential metrics like page views, referrers, browser statistics, and geographic data.
This deployment combines the GoatCounter analytics service with a PostgreSQL database backend. The goatcounter container runs the web application and analytics engine, while the db service provides persistent data storage using PostgreSQL 15 Alpine. The two services communicate over a dedicated Docker network, with GoatCounter configured to connect to PostgreSQL using environment variables for database credentials.
This stack is ideal for website owners, bloggers, small businesses, and organizations that prioritize visitor privacy while still needing meaningful analytics data. The combination offers the reliability of PostgreSQL for data persistence with GoatCounter's privacy-first approach, making it perfect for compliance-conscious environments or anyone seeking an ethical alternative to tracking-heavy analytics platforms.
Key Features
- Privacy-first analytics with no personal data collection or tracking cookies
- PostgreSQL backend for reliable data persistence and complex query capabilities
- Real-time visitor statistics and page view tracking without user identification
- Built-in referrer analysis showing traffic sources and external links
- Geographic visitor distribution based on IP addresses without storing personal data
- Browser and device statistics for technical insights without fingerprinting
- Lightweight JavaScript tracking code with minimal performance impact
- GDPR and privacy regulation compliant analytics collection
Common Use Cases
- 1Privacy-conscious websites needing analytics without visitor tracking
- 2Small business websites requiring basic traffic insights and referrer data
- 3Personal blogs and portfolios tracking readership without compromising visitor privacy
- 4Organizations in regulated industries needing GDPR-compliant analytics
- 5Educational institutions monitoring website usage while protecting student privacy
- 6Non-profit organizations tracking outreach effectiveness without data collection concerns
- 7Development teams needing lightweight analytics for internal projects and documentation sites
Prerequisites
- Docker and Docker Compose installed on the host system
- Minimum 1GB RAM for PostgreSQL database operations and GoatCounter processing
- Port 8080 available for GoatCounter web interface access
- DB_PASSWORD environment variable configured for database authentication
- Basic understanding of JavaScript integration for adding tracking code to websites
- Command-line access for initial site creation and GoatCounter configuration
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 goatcounter: 3 image: ghcr.io/arp242/goatcounter:latest4 container_name: goatcounter5 environment: 6 - GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable7 command: serve -listen :8080 -tls none8 ports: 9 - "8080:8080"10 depends_on: 11 - db12 networks: 13 - goatcounter-network14 restart: unless-stopped1516 db: 17 image: postgres:15-alpine18 container_name: goatcounter-db19 environment: 20 - POSTGRES_USER=goatcounter21 - POSTGRES_PASSWORD=${DB_PASSWORD}22 - POSTGRES_DB=goatcounter23 volumes: 24 - postgres-data:/var/lib/postgresql/data25 networks: 26 - goatcounter-network27 restart: unless-stopped2829volumes: 30 postgres-data: 3132networks: 33 goatcounter-network: 34 driver: bridge.env Template
.env
1# GoatCounter2DB_PASSWORD=secure_goatcounter_password34# Create first user: goatcounter db create site -createdb -vhost=stats.example.com -user.email=you@example.comUsage Notes
- 1Web UI at http://localhost:8080
- 2Create site via CLI first
- 3Add count.js to websites
- 4No personal data collection
- 5Lightweight and fast
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
goatcounter
goatcounter:
image: ghcr.io/arp242/goatcounter:latest
container_name: goatcounter
environment:
- GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable
command: serve -listen :8080 -tls none
ports:
- "8080:8080"
depends_on:
- db
networks:
- goatcounter-network
restart: unless-stopped
db
db:
image: postgres:15-alpine
container_name: goatcounter-db
environment:
- POSTGRES_USER=goatcounter
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=goatcounter
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- goatcounter-network
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 goatcounter:5 image: ghcr.io/arp242/goatcounter:latest6 container_name: goatcounter7 environment:8 - GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable9 command: serve -listen :8080 -tls none10 ports:11 - "8080:8080"12 depends_on:13 - db14 networks:15 - goatcounter-network16 restart: unless-stopped1718 db:19 image: postgres:15-alpine20 container_name: goatcounter-db21 environment:22 - POSTGRES_USER=goatcounter23 - POSTGRES_PASSWORD=${DB_PASSWORD}24 - POSTGRES_DB=goatcounter25 volumes:26 - postgres-data:/var/lib/postgresql/data27 networks:28 - goatcounter-network29 restart: unless-stopped3031volumes:32 postgres-data:3334networks:35 goatcounter-network:36 driver: bridge37EOF3839# 2. Create the .env file40cat > .env << 'EOF'41# GoatCounter42DB_PASSWORD=secure_goatcounter_password4344# Create first user: goatcounter db create site -createdb -vhost=stats.example.com -user.email=you@example.com45EOF4647# 3. Start the services48docker compose up -d4950# 4. View logs51docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/goatcounter-analytics/run | bashTroubleshooting
- GoatCounter shows database connection errors: Verify DB_PASSWORD environment variable matches between goatcounter and db services
- Web interface not accessible at localhost:8080: Check that port 8080 is not used by other services and containers are running
- Site creation fails or no data appears: Use docker exec to run goatcounter create commands inside the container before adding tracking code
- PostgreSQL container fails to start: Ensure postgres-data volume permissions are correct and sufficient disk space is available
- Tracking code not recording visits: Verify count.js is properly loaded from the GoatCounter instance and not blocked by ad blockers
- Database performance issues with large datasets: Monitor PostgreSQL memory usage and consider increasing container memory limits for the db service
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
goatcounterpostgresql
Tags
#analytics#goatcounter#privacy#simple#lightweight
Category
Monitoring & ObservabilityAd Space
Shortcuts: C CopyF FavoriteD Download