DEV Community

Alex Spinov
Alex Spinov

Posted on

Umami Has a Free API: Privacy-First Web Analytics That Replaces Google Analytics

What is Umami?

Umami is a privacy-focused, open-source web analytics tool. No cookies, no tracking, GDPR-compliant by default. It's the ethical alternative to Google Analytics — self-hosted with a clean API.

Quick Setup

git clone https://github.com/umami-software/umami
cd umami
npm install
npx prisma migrate deploy
npm run build
npm start
Enter fullscreen mode Exit fullscreen mode

Or use Docker:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Add to Your Website

<script async src="https://your-umami.com/script.js" data-website-id="YOUR_WEBSITE_ID"></script>
Enter fullscreen mode Exit fullscreen mode

One tag. No cookies. No consent banner needed.

The REST API

export UMAMI_URL="https://your-umami.com/api"
export UMAMI_TOKEN="your-api-token"
Enter fullscreen mode Exit fullscreen mode

Get Website Stats

curl -s "$UMAMI_URL/websites/WEBSITE_ID/stats?startAt=1711584000000&endAt=1711670400000" \
  -H "Authorization: Bearer $UMAMI_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "pageviews": {"value": 1234, "prev": 1100},
  "visitors": {"value": 890, "prev": 800},
  "visits": {"value": 950, "prev": 850},
  "bounces": {"value": 312, "prev": 290},
  "totaltime": {"value": 45600, "prev": 42000}
}
Enter fullscreen mode Exit fullscreen mode

Page Views by URL

curl -s "$UMAMI_URL/websites/WEBSITE_ID/metrics?startAt=1711584000000&endAt=1711670400000&type=url" \
  -H "Authorization: Bearer $UMAMI_TOKEN" | jq '.[:5]'
Enter fullscreen mode Exit fullscreen mode

Referrers

curl -s "$UMAMI_URL/websites/WEBSITE_ID/metrics?type=referrer&startAt=1711584000000&endAt=1711670400000" \
  -H "Authorization: Bearer $UMAMI_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Countries, Browsers, OS

# Countries
curl -s "$UMAMI_URL/websites/WEBSITE_ID/metrics?type=country&startAt=...&endAt=..." \
  -H "Authorization: Bearer $UMAMI_TOKEN"

# Browsers
curl -s "$UMAMI_URL/websites/WEBSITE_ID/metrics?type=browser&startAt=...&endAt=..." \
  -H "Authorization: Bearer $UMAMI_TOKEN"

# OS
curl -s "$UMAMI_URL/websites/WEBSITE_ID/metrics?type=os&startAt=...&endAt=..." \
  -H "Authorization: Bearer $UMAMI_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Pageviews Over Time

curl -s "$UMAMI_URL/websites/WEBSITE_ID/pageviews?startAt=1711584000000&endAt=1711670400000&unit=hour" \
  -H "Authorization: Bearer $UMAMI_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Custom Events

// Track custom events in your app
umami.track("signup_clicked", { plan: "pro", source: "landing" });
umami.track("purchase", { amount: 49.99, currency: "USD" });
Enter fullscreen mode Exit fullscreen mode
# Query events via API
curl -s "$UMAMI_URL/websites/WEBSITE_ID/events?startAt=...&endAt=..." \
  -H "Authorization: Bearer $UMAMI_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Manage Websites

# Create website
curl -X POST "$UMAMI_URL/websites" \
  -H "Authorization: Bearer $UMAMI_TOKEN" \
  -d '{"name": "My Blog", "domain": "blog.example.com"}'

# List websites
curl -s "$UMAMI_URL/websites" \
  -H "Authorization: Bearer $UMAMI_TOKEN" | jq '.[].name'
Enter fullscreen mode Exit fullscreen mode

Why Umami?

Feature Umami Google Analytics Plausible
Open source Yes No Yes
Self-host Yes No Yes
Cookies None Required None
GDPR compliant Yes Needs consent Yes
Real-time Yes Delayed Yes
API Full REST Limited REST
Price (self) Free Free Free

Need privacy-first analytics or custom dashboards?

📧 spinov001@gmail.com
🔧 My tools on Apify Store

GA4 or privacy-first analytics? What do you use?

Top comments (0)