Deploying Swetrix
Introduction
Swetrix is an open-source, privacy-focused web analytics platform that provides insights into your website traffic without compromising visitor privacy. It’s a GDPR-compliant alternative to Google Analytics that doesn’t use cookies or track personal data.
Key highlights of Swetrix:
- Privacy First: No cookies, no personal data collection
- GDPR Compliant: Built with European privacy regulations in mind
- Real-Time Analytics: See visitor data as it happens
- Performance Monitoring: Track page load times and Core Web Vitals
- Event Tracking: Custom event tracking for user interactions
- Funnels: Create conversion funnels to track user journeys
- UTM Tracking: Campaign attribution and referrer tracking
- API Access: Full API for custom integrations
- Open Source: Self-host for complete data ownership
This guide walks through deploying Swetrix on Klutch.sh using Docker.
Why Deploy Swetrix on Klutch.sh
Deploying Swetrix on Klutch.sh provides several advantages:
Simplified Deployment: Klutch.sh automatically detects your Dockerfile and builds Swetrix without complex orchestration.
Persistent Storage: Attach persistent volumes for your analytics database.
HTTPS by Default: Secure analytics collection with automatic SSL certificates.
GitHub Integration: Connect your configuration repository for automatic redeployments.
Prerequisites
Before deploying Swetrix on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your Swetrix configuration
- Basic familiarity with Docker and containerization concepts
- ClickHouse database (for analytics data storage)
- Redis instance (for caching)
Deploying Swetrix on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 5005
Create Your Repository
Create a new GitHub repository with a Dockerfile for Swetrix:
FROM swetrix/swetrix-api:latest
ENV NODE_ENV=productionENV CLICKHOUSE_HOST=${CLICKHOUSE_HOST}ENV CLICKHOUSE_DATABASE=${CLICKHOUSE_DATABASE}ENV REDIS_HOST=${REDIS_HOST}ENV JWT_SECRET=${JWT_SECRET}ENV API_ORIGINS=${API_ORIGINS}
EXPOSE 5005
VOLUME ["/app/data"]Push to GitHub
Initialize and push your repository to GitHub with your Dockerfile.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project.
Create a New App
Within your project, create a new app and connect your GitHub repository.
Configure HTTP Traffic
In the deployment settings:
Set Environment Variables
Configure the following environment variables:
| Variable | Value |
|---|---|
NODE_ENV | production |
CLICKHOUSE_HOST | Your ClickHouse host |
CLICKHOUSE_DATABASE | swetrix |
REDIS_HOST | Your Redis host |
JWT_SECRET | Generate with openssl rand -hex 32 |
API_ORIGINS | Comma-separated allowed origins |
Deploy Your Application
Click Deploy to start the build process.
Access Swetrix
Once deployment completes, access the Swetrix API at your app URL.
Configuration
Adding the Tracking Script
Add the Swetrix tracking script to your website:
<script src="https://your-swetrix.klutch.sh/script.js" defer></script><script> document.addEventListener('DOMContentLoaded', function() { swetrix.init('YOUR_PROJECT_ID'); swetrix.trackViews(); });</script>Custom Event Tracking
Track custom events:
swetrix.track({ ev: 'button_click', meta: { button_name: 'signup' }});Dashboard Access
Access your analytics dashboard to view:
- Page views and unique visitors
- Traffic sources and referrers
- Geographic distribution
- Device and browser statistics
- Custom events and conversions
Additional Resources
- Swetrix Official Website
- Swetrix GitHub Repository
- Swetrix Documentation
- Klutch.sh Persistent Volumes
- Klutch.sh Deployments
Conclusion
Deploying Swetrix on Klutch.sh gives you privacy-focused web analytics with automatic builds, persistent storage, and secure HTTPS access. Track your website visitors while respecting their privacy and complying with GDPR.