Medama Documentation
repository·main·Indexed 20 days ago
https://github.com/medama-io/medamaAn open-source, privacy-focused, and self-hostable website analytics platform. Medama provides cookie-free tracking via a lightweight JavaScript tracker (<1KB) and real-time insights through an OpenAPI-based server. It utilizes SQLite for application data and DuckDB for analytics, supporting low-resource deployments on VMs with as little as 256MB of memory.
What's inside Medama
- The Medama Tracker is a lightweight JavaScript library used to power Medama analytics. It is designed to be extremely small and optimized for modern web compression (gzip and brotli) to minimize impact on page load performance.
Overview of Medama Analytics
mainMedama Analytics is an open-source, self-hostable, and cookie-free website analytics platform. It is designed to prioritize user privacy by using a lightweight tracker (<1KB) that does not use cookies, IP addresses, or other identifiers, making it compliant with GDPR and PECR.
Key capabilities include:
- Real-Time Analytics: Instant monitoring of website performance and user interactions.
- Privacy-First Design: No cookies or PII (Personally Identifiable Information) collected.
- Easy Integration: Uses an OpenAPI-based server for integration with dashboards.
- Low Resource Requirements: Can be deployed as a single binary on VMs with as little as 256MB of memory.
Run the Medama Core API server
mainFrom thecoredirectory, you can start the API server in development mode usingmise run dev.mise run devSet up the Medama Dashboard for development
mainTo develop the Medama Dashboard locally, you must first install the necessary repository tools using
misefrom the repository root, then install dependencies usingbun, and finally start the development server from thedashboarddirectory.# From the repository root mise install # From the dashboard directory cd dashboard bun install mise run devSet up the Medama Core development environment
mainTo develop on the Medama backend API service, ensure your environment meets the following requirements:
- Go Version: Use the specific Go version defined in the repository's root
mise.toml. - CGO Support: You must have
gccinstalled, as CGO is required for the project. - Tooling: Install the necessary repository tools by running
mise installfrom the repository root. - Linting & Formatting: Configure your IDE to use
gofumptandgolangci-lintfor automatic code formatting and linting. - Dependencies: Run
go mod downloadto fetch required Go modules.
- Go Version: Use the specific Go version defined in the repository's root
Run tests for Medama Core
mainTo execute the test suite for the Core service, run the following command from the
coredirectory.mise run testUse Demo Mode
mainThe--demoflag enables a restricted mode intended for demonstrations or read-only environments. In this mode, the server blocks all state-changing HTTP methods (POST,PATCH,DELETE) for all routes, except for theloginendpoint, ensuring the underlying data remains unchanged.Enable Debug Profiling
mainTo profile the running Medama server, use the
--profilerflag. This enables the standard Gopprofendpoints, allowing you to inspect CPU profiles, heap, goroutines, and traces via HTTP.Available endpoints:
/debug/pprof/(Index)/debug/pprof/cmdline/debug/pprof/profile/debug/pprof/symbol/debug/pprof/trace
Enable Automatic SSL (AutoSSL)
mainMedama can automatically manage SSL certificates using Certmagic. When the
--autosslflag is provided with a domain name:- The server must be able to listen on ports 80 and 443.
- The domain must be publicly accessible and resolve to the server's IP.
- The server will automatically handle ACME challenges.
- All incoming HTTP requests will be redirected to HTTPS.
You can optionally provide an email via
--autosslemailfor certificate notifications.Configure Playwright for @medama/tracker E2E tests
mainThe
@medama/trackerpackage uses Playwright for end-to-end testing. The configuration is environment-aware, adjusting behavior based on whether it is running in a Continuous Integration (CI) environment (detected via theCIenvironment variable).Key Test Settings
- Test Directory: Tests are located in
./tests. - Timeouts: Individual test timeout is set to
20,000ms. TheglobalTimeoutis set to 5 minutes on CI. - Parallelism: Tests run in
fullyParallelmode. On CI,workersis restricted to1to maintain determinism for shared tracker/core servers. - Retries & Failures: On CI, tests will retry once (
retries: 1) and the build will fail after5failures (maxFailures: 5). - CI Safety:
forbidOnlyis enabled on CI to prevent accidentaltest.onlycommits from passing.
Browser Projects
The test suite supports the following browser configurations:
chromium(Desktop Chrome)firefox(Desktop Firefox)webkit(Desktop Safari)Microsoft Edge(usingmsedgechannel)Google Chrome(usingchromechannel)
Web Server Setup
To run tests, the following local servers are automatically managed:
- Frontend/App Server: Started via
bun run e2e:serveon port3000. - Core Server: Started via
go run ./cmd starton port8080from the../coredirectory. It is configured with debug logging and specific CORS origins (http://localhost:8080,http://localhost:5173).
// Example of the configuration structure used in @medama/tracker module.exports = defineConfig({ testDir: './tests', timeout: 20_000, fullyParallel: true, use: { baseURL: 'http://localhost:3000', actionTimeout: 10_000, navigationTimeout: 10_000, trace: 'on-first-retry', }, // ... projects and webServer definitions });- Test Directory: Tests are located in
Configure Analytics Database host
mainThe analytics database (typically DuckDB) can be configured via environment variables. By default, it uses a local DuckDB file.
ANALYTICS_DATABASE_HOST: The host or file path for the analytics database. (Default:./me_analytics.db).
Use
NewAnalyticsDBConfig(true)to load this from the environment.// Load AnalyticsDBConfig from environment variables analyticsDBConfig, err := NewAnalyticsDBConfig(true)Configure React Router SSR settings for the Dashboard
mainThe Medama dashboard uses
react-routerfor routing. You can control whether Server-Side Rendering (SSR) is enabled by setting thessrproperty in thereact-router.config.tsfile. In the current configuration, SSR is disabled (ssr: false).import type { Config } from '@react-router/dev/config'; export default { ssr: false, } satisfies Config;