A lightweight, privacy-focused web analytics backend service built with Go. This project provides a simple yet powerful alternative to traditional analytics platforms, allowing you to track user sessions, page views, and custom events while maintaining user privacy through anonymous tracking.
Go Analytics is a self-hosted analytics solution designed to give you full control over your data. It features a RESTful API backend that can be easily integrated into any web application, with support for session tracking, page view monitoring, and custom event logging.
- Privacy-Focused Anonymous Tracking: Generates daily-rotating anonymous IDs using IP and user agent hashing
- Session Management: Comprehensive session tracking with geolocation, device, and browser information
- Page View Analytics: Track page visits with time-on-page metrics and navigation flow
- Custom Event Logging: Flexible event system for tracking any custom interactions
- IP Geolocation: Automatic location detection (country, region, city) for visitor insights
- PostgreSQL Storage: Reliable and scalable data persistence
- RESTful API: Clean, well-documented endpoints for easy integration
- Vercel Deployment Ready: Configured for serverless deployment on Vercel
- Docker Support: Includes Docker Compose setup for local development
- Backend: Go 1.22.5
- Web Framework: Gin (high-performance HTTP framework)
- Database: PostgreSQL
- Deployment: Vercel (serverless), Docker
- Libraries:
gin-gonic/gin- HTTP web frameworklib/pq- PostgreSQL driverrs/cors- CORS middleware
POST /api/session- Record a new user session with page viewsGET /api/sessions- Retrieve session data (supports?distinct=truefor unique visitors)
POST /api/event- Log a custom event with arbitrary dataGET /api/events- Retrieve events within a time range
GET /api/pageviews- Get page view statistics with optional time filters
The service automatically creates three main tables:
- sessions: Stores user session information including anonymous IDs, timestamps, geolocation, and device data
- page_views: Records individual page visits with time spent and navigation order
- events: Captures custom events with flexible JSON data storage
# Start PostgreSQL database
docker-compose up -d
# Run the application
go run cmd/main.goThe project is configured for Vercel serverless deployment with environment variables for PostgreSQL connection.
- Track website visitor behavior without invasive cookies
- Monitor user flows through your application
- Analyze content engagement with time-on-page metrics
- Log custom business events (button clicks, form submissions, etc.)
- Generate insights about your audience's location and devices
See TODO.md for planned features including:
- NPM package for easy frontend integration
- Analytics dashboard with Laravel
- Multi-tenant support with API key authentication
This project is open source and available for personal and commercial use.