跳至主要内容

📊 Privacy-Respecting Analytics Guide

This guide covers analytics options that respect user privacy and comply with regulations like GDPR.

Philosophy

This template does not include analytics by default because:

  • 🔒 Privacy first: Users should opt-in to tracking
  • 🌍 GDPR compliance: Cookie consent is complex
  • 🎯 Your choice: Different projects have different needs

Comparison of Options

ServiceTypeCookiesGDPRCostComplexity
PlausibleSaaS/Self-host❌ No✅ Compliant€9/mo or free (self-host)Low
UmamiSelf-hosted❌ No✅ CompliantFreeMedium
Simple AnalyticsSaaS❌ No✅ Compliant$9/moLow
Goat CounterSaaS/Self-host❌ No✅ CompliantFree tierLow
FathomSaaS❌ No✅ Compliant$14/moLow
Google AnalyticsSaaS✅ Yes⚠️ Requires consentFreeMedium

Option 1: Plausible Analytics

Plausible is a lightweight, privacy-focused alternative to Google Analytics.

Features

  • ✅ No cookies, no consent banner needed
  • ✅ GDPR, CCPA, PECR compliant
  • ✅ Lightweight script (~1KB)
  • ✅ Open source (self-hostable)

Setup (SaaS)

Step 1: Create Account

Sign up at plausible.io and add your site.

Step 2: Install Plugin

npm install docusaurus-plugin-plausible

Step 3: Configure

docusaurus.config.js
plugins: [
[
'docusaurus-plugin-plausible',
{
domain: 'your-docs-site.com',
},
],
],

Setup (Self-Hosted)

Use the headTags approach:

docusaurus.config.js
headTags: [
{
tagName: 'script',
attributes: {
defer: 'true',
'data-domain': 'your-docs-site.com',
src: 'https://your-plausible-instance.com/js/script.js',
},
},
],

Option 2: Umami

Umami is a simple, fast, privacy-focused analytics solution.

Features

  • ✅ 100% open source
  • ✅ Self-hosted (full data ownership)
  • ✅ No cookies
  • ✅ GDPR compliant
  • ✅ Real-time dashboard

Setup

Step 1: Deploy Umami

Deploy using Docker, Vercel, Railway, or other platforms. See Umami docs.

Step 2: Add Tracking Script

docusaurus.config.js
headTags: [
{
tagName: 'script',
attributes: {
async: 'true',
defer: 'true',
'data-website-id': 'YOUR_WEBSITE_ID',
src: 'https://your-umami-instance.com/script.js',
},
},
],

Docker Compose Example

docker-compose.yml
version: '3'
services:
umami:
image: ghcr.io/umami-software/umami:postgresql-latest
ports:
- "3000:3000"
environment:
DATABASE_URL: postgresql://umami:umami@db:5432/umami
DATABASE_TYPE: postgresql
HASH_SALT: your-random-salt-here
depends_on:
- db

db:
image: postgres:15-alpine
environment:
POSTGRES_DB: umami
POSTGRES_USER: umami
POSTGRES_PASSWORD: umami
volumes:
- umami-db:/var/lib/postgresql/data

volumes:
umami-db:

Option 3: Simple Analytics

Simple Analytics is a privacy-first analytics service.

Features

  • ✅ No cookies
  • ✅ EU-based (Netherlands)
  • ✅ GDPR compliant by design
  • ✅ Public dashboards option

Setup

Step 1: Create Account

Sign up at simpleanalytics.com.

Step 2: Install Plugin

npm install @simpleanalytics/docusaurus-plugin

Step 3: Configure

docusaurus.config.js
plugins: [
[
'@simpleanalytics/docusaurus-plugin',
{
domain: 'your-docs-site.com',
},
],
],

Option 4: Goat Counter

Goat Counter is a lightweight, open-source analytics.

Features

  • ✅ No cookies
  • ✅ GDPR compliant
  • ✅ Free tier (100k pageviews/month)
  • ✅ Self-hostable

Setup

docusaurus.config.js
headTags: [
{
tagName: 'script',
attributes: {
'data-goatcounter': 'https://YOUR_CODE.goatcounter.com/count',
async: 'true',
src: '//gc.zgo.at/count.js',
},
},
],

Option 5: Google Analytics (with Privacy Considerations)

If you must use Google Analytics, configure it for privacy:

Setup

npm install @docusaurus/plugin-google-gtag
docusaurus.config.js
plugins: [
[
'@docusaurus/plugin-google-gtag',
{
trackingID: 'G-XXXXXXXXXX',
anonymizeIP: true, // Important for GDPR
},
],
],

Google Analytics requires cookie consent in the EU. Consider:

注意

Google Analytics is blocked by many ad blockers and privacy browsers. Consider privacy-respecting alternatives for more accurate data.


Environment Variables

For security, use environment variables for analytics IDs:

docusaurus.config.js
headTags: [
{
tagName: 'script',
attributes: {
defer: 'true',
'data-domain': process.env.ANALYTICS_DOMAIN,
src: process.env.ANALYTICS_SCRIPT_URL,
},
},
],
.env
ANALYTICS_DOMAIN=your-docs-site.com
ANALYTICS_SCRIPT_URL=https://plausible.io/js/script.js

What to Track

Useful Metrics

MetricWhy It Matters
Page viewsPopular content identification
ReferrersWhere users come from
Search queriesWhat users are looking for
404 errorsBroken links to fix
Time on pageContent engagement

Don't Track

  • Personal information
  • Precise location (city is enough)
  • Individual user journeys (aggregate only)

Recommendation

Use CaseRecommended
Simple, hostedPlausible or Simple Analytics
Self-hosted, freeUmami or Goat Counter
Already using GoogleGoogle Analytics with anonymization
Privacy-criticalUmami (self-hosted)

Testing Analytics

Development Mode

Most analytics skip localhost. To test:

  1. Build and serve locally: npm run build && npm run serve
  2. Use ngrok or similar for public URL
  3. Check analytics dashboard

Debug Mode

Plausible example with debug:

{
tagName: 'script',
attributes: {
defer: 'true',
'data-domain': 'your-site.com',
src: 'https://plausible.io/js/script.local.js', // Tracks localhost
},
}

Resources