该介绍目前仅提供英文版本。
Counterscale: Self-Hosted Web Analytics on Cloudflare
Counterscale is a lightweight, privacy-focused web analytics platform that you can deploy and run yourself on Cloudflare’s infrastructure. It provides essential website traffic metrics without the complexity or cost of traditional analytics solutions.
Key Features
- Simple Deployment: Deploy as a single Cloudflare Worker with a straightforward CLI installation process
- Cost-Effective: Operates on Cloudflare’s free tier, which can handle up to 100,000 hits per day at near-zero cost
- Privacy-Focused: Doesn’t set cookies and gives you complete control over your analytics data
- Easy Integration: Add to your website with a simple script tag or use the npm package for programmatic integration
- Essential Metrics: Track pageviews, referrers, browsers, devices, and other standard web analytics data
- Clean Dashboard: Intuitive interface for viewing your website traffic metrics
- Open Source: MIT-licensed code that you can modify to suit your specific needs
How It Works
Counterscale leverages two key Cloudflare technologies:
- Cloudflare Workers: Serverless JavaScript functions that run on Cloudflare’s edge network, handling the collection and processing of analytics data
- Cloudflare Analytics Engine: A managed time-series database service that stores the analytics events
This architecture allows Counterscale to scale effortlessly with your traffic while maintaining minimal operational costs.
Getting Started
Deploying Counterscale requires just a few steps:
-
Prepare your Cloudflare account:
- Set up a Cloudflare Workers subdomain
- Enable Cloudflare Analytics Engine beta
- Create a Cloudflare API token with appropriate permissions
-
Deploy using the CLI:
npx wrangler login npx @counterscale/cli@latest install -
Add the tracking code to your website:
<script id="counterscale-script" data-site-id="your-unique-site-id" src="https://{your-subdomain}.workers.dev/tracker.js" defer ></script>
Limitations
Counterscale currently has a 90-day data retention limit, as it’s built on Cloudflare Analytics Engine which only retains data for that period. This means you can only view analytics data from the past 90 days.
Why Choose Counterscale?
- No Vendor Lock-in: You own and control your analytics infrastructure and data
- Transparent Costs: Predictable, low-cost operation even at scale
- Privacy Compliance: Helps with GDPR and similar regulations by avoiding cookies and third-party data sharing
- Performance: Minimal impact on your website’s performance with edge-based collection
- Simplicity: Focus on essential metrics without overwhelming complexity
Advanced Usage
Counterscale offers additional features for more specific use cases:
- Manual Tracking: Disable automatic pageview tracking and trigger pageviews programmatically
- Custom Domains: Configure your Cloudflare Worker to use your own domain
- NPM Package: Use the JavaScript package for more control over tracking behavior
As an open-source project, Counterscale continues to evolve with community contributions, making it an increasingly powerful alternative to commercial analytics platforms while maintaining its simplicity and cost-effectiveness.