Skip to content

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

    Create Your Repository

    Create a new GitHub repository with a Dockerfile for Swetrix:

    FROM swetrix/swetrix-api:latest
    ENV NODE_ENV=production
    ENV 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:

    • Select HTTP as the traffic type
    • Set the internal port to 5005

    Set Environment Variables

    Configure the following environment variables:

    VariableValue
    NODE_ENVproduction
    CLICKHOUSE_HOSTYour ClickHouse host
    CLICKHOUSE_DATABASEswetrix
    REDIS_HOSTYour Redis host
    JWT_SECRETGenerate with openssl rand -hex 32
    API_ORIGINSComma-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

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.