Deploying LHA
Introduction
LHA (Link Hover Analytics) is a lightweight, privacy-focused analytics platform designed to track user interactions on your website without the overhead of traditional analytics solutions. It provides insights into how users engage with links and interactive elements on your pages.
Built for simplicity and performance, LHA captures essential interaction data while respecting user privacy. The application runs as a small service that receives tracking events from a lightweight JavaScript snippet embedded in your pages.
Key features of LHA:
- Link Click Tracking: Monitor which links users click
- Hover Analytics: Track user attention through hover events
- Lightweight Script: Minimal JavaScript footprint for fast page loads
- Privacy-Focused: No personal data collection or cookies
- Real-Time Dashboard: View analytics as they happen
- Custom Events: Track custom interactions beyond links
- API Access: Retrieve analytics data programmatically
- Self-Hosted: Complete control over your analytics data
- Easy Integration: Simple script tag to add to your site
- Open Source: Fully transparent codebase
This guide walks through deploying LHA on Klutch.sh using Docker, integrating the tracking script, and viewing your analytics data.
Why Deploy LHA on Klutch.sh
Deploying LHA on Klutch.sh provides several advantages for analytics:
Simplified Deployment: Klutch.sh automatically detects your Dockerfile and builds LHA without complex orchestration.
Persistent Storage: Attach persistent volumes for your analytics database. Your data survives container restarts.
HTTPS by Default: Klutch.sh provides automatic SSL certificates, required for cross-origin tracking.
GitHub Integration: Connect your configuration repository directly from GitHub. Updates trigger automatic redeployments.
Low Resource Usage: LHA is lightweight and cost-effective to run.
Environment Variable Management: Securely store configuration without exposing in code.
Custom Domains: Use your own domain for the analytics endpoint.
Always-On Availability: Analytics collection runs 24/7.
Prerequisites
Before deploying LHA on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your configuration
- Basic familiarity with Docker and containerization concepts
- A website to add tracking to
- (Optional) A custom domain for your analytics endpoint
Preparing Your Repository
Create a GitHub repository containing your Dockerfile for deploying LHA on Klutch.sh.
Repository Structure
lha-deploy/├── Dockerfile├── README.md└── .dockerignoreCreating the Dockerfile
Create a Dockerfile in the root of your repository:
FROM node:18-alpine
# Set working directoryWORKDIR /app
# Clone LHA (replace with actual repository if available)RUN apk add --no-cache git && \ git clone https://github.com/lha-analytics/lha.git .
# Install dependenciesRUN npm install
# Build for productionRUN npm run build
# Set environment variablesENV NODE_ENV=productionENV PORT=3000
# Expose portEXPOSE 3000
# Start the applicationCMD ["npm", "start"]Environment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
PORT | No | 3000 | Port for the API server |
DATABASE_URL | Yes | - | Database connection string |
ALLOWED_ORIGINS | Yes | - | Comma-separated list of allowed domains |
SECRET_KEY | Yes | - | Secret for API authentication |
RETENTION_DAYS | No | 90 | Days to keep analytics data |
Deploying LHA on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 3000
- Detect your Dockerfile automatically
- Build the container image
- Attach the persistent volumes
- Start the LHA container
- Provision an HTTPS certificate
Generate a Secret Key
Generate a secure secret key:
openssl rand -hex 32Push Your Repository to GitHub
Initialize your repository and push to GitHub:
git initgit add Dockerfile .dockerignore README.mdgit commit -m "Initial LHA deployment configuration"git remote add origin https://github.com/yourusername/lha-deploy.gitgit push -u origin mainCreate a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project. Give it a descriptive name like “lha” or “analytics”.
Create a New App
Within your project, create a new app. Connect your GitHub account if you haven’t already, then select the repository containing your LHA Dockerfile.
Configure HTTP Traffic
In the deployment settings:
Set Environment Variables
Add the following environment variables:
| Variable | Value |
|---|---|
DATABASE_URL | Your database connection string |
ALLOWED_ORIGINS | https://yourwebsite.com |
SECRET_KEY | Your generated secret key |
NODE_ENV | production |
Attach Persistent Volumes
Add volumes for data persistence:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/app/data | 10 GB | Analytics database |
Deploy Your Application
Click Deploy to start the build process. Klutch.sh will:
Access LHA
Once deployment completes, access your LHA dashboard at https://your-app-name.klutch.sh.
Integrating the Tracking Script
Adding to Your Website
Add the tracking script to your website’s HTML:
<script>(function() { var lha = document.createElement('script'); lha.src = 'https://your-lha-domain.klutch.sh/tracker.js'; lha.async = true; document.head.appendChild(lha);})();</script>Tracking Custom Events
Track custom interactions:
// Track a custom eventLHA.track('button_click', { button_id: 'signup-button', page: window.location.pathname});Tracking Link Clicks
Links are automatically tracked, but you can add metadata:
<a href="/pricing" data-lha-category="navigation" data-lha-label="pricing"> Pricing</a>Viewing Analytics
Dashboard Overview
The LHA dashboard shows:
- Total link clicks
- Click heatmaps
- Popular pages
- Traffic trends
- Referrer sources
API Access
Retrieve analytics programmatically:
curl -X GET https://your-lha-domain.klutch.sh/api/v1/analytics \ -H "Authorization: Bearer your-secret-key" \ -H "Content-Type: application/json"Troubleshooting Common Issues
Tracking Not Working
- Verify ALLOWED_ORIGINS includes your website
- Check browser console for CORS errors
- Ensure HTTPS is used on both ends
Data Not Persisting
- Verify volume is mounted correctly
- Check database connection string
- Review container logs for errors
Dashboard Not Loading
- Verify the application is running
- Check environment variables are set
- Review application logs
Additional Resources
Conclusion
Deploying LHA on Klutch.sh gives you a lightweight, privacy-focused analytics platform with automatic builds and secure HTTPS access. Track user interactions without compromising privacy or page performance.