DEV Community

Alex Spinov
Alex Spinov

Posted on

Plausible Has a Free API — Here's How to Build Privacy-First Analytics

A GDPR-conscious founder told me: 'We removed Google Analytics and our cookie banner. Conversions went up 12% because users stopped bouncing from the consent popup.' He replaced it with Plausible — no cookies, no consent needed, GDPR compliant out of the box.

What Plausible Offers

Plausible self-hosted (Community Edition — free forever):

  • Unlimited websites and unlimited pageviews
  • No cookies — no consent banners needed
  • GDPR, CCPA, PECR compliant by design
  • Lightweight script — under 1KB (vs Google Analytics ~45KB)
  • Full API access for all your data
  • Dashboard sharing via public links

Plausible Cloud starts at $9/month with a 30-day free trial.

Quick Start (Self-Hosted)

# Docker compose setup
curl -L https://github.com/plausible/hosting/raw/master/docker-compose.yml > docker-compose.yml
curl -L https://github.com/plausible/hosting/raw/master/plausible-conf.env > plausible-conf.env

# Edit plausible-conf.env with your settings
# Then start
docker compose up -d
Enter fullscreen mode Exit fullscreen mode
<!-- Add to your site (under 1KB!) -->
<script defer data-domain="yoursite.com" src="https://plausible.yoursite.com/js/script.js"></script>
Enter fullscreen mode Exit fullscreen mode

Stats API

# Get realtime visitors
curl 'https://plausible.io/api/v1/stats/realtime/visitors?site_id=yoursite.com' \
  -H 'Authorization: Bearer YOUR_API_KEY'

# Get aggregate stats
curl 'https://plausible.io/api/v1/stats/aggregate?site_id=yoursite.com&period=30d&metrics=visitors,pageviews,bounce_rate,visit_duration' \
  -H 'Authorization: Bearer YOUR_API_KEY'

# Breakdown by page
curl 'https://plausible.io/api/v1/stats/breakdown?site_id=yoursite.com&period=7d&property=event:page&metrics=visitors,pageviews&limit=10' \
  -H 'Authorization: Bearer YOUR_API_KEY'

# Breakdown by source
curl 'https://plausible.io/api/v1/stats/breakdown?site_id=yoursite.com&period=30d&property=visit:source&metrics=visitors' \
  -H 'Authorization: Bearer YOUR_API_KEY'
Enter fullscreen mode Exit fullscreen mode

Node.js Integration

const PLAUSIBLE_URL = 'https://plausible.io/api/v1';
const API_KEY = process.env.PLAUSIBLE_API_KEY;

async function getStats(siteId, period = '30d') {
  const res = await fetch(
    `${PLAUSIBLE_URL}/stats/aggregate?site_id=${siteId}&period=${period}&metrics=visitors,pageviews,bounce_rate`,
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  );
  return res.json();
}

async function getTopPages(siteId, limit = 10) {
  const res = await fetch(
    `${PLAUSIBLE_URL}/stats/breakdown?site_id=${siteId}&period=30d&property=event:page&metrics=visitors&limit=${limit}`,
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  );
  return res.json();
}

// Build a custom dashboard
async function getDashboardData(siteId) {
  const [stats, pages, sources] = await Promise.all([
    getStats(siteId),
    getTopPages(siteId),
    getTopSources(siteId)
  ]);
  return { stats, pages, sources };
}
Enter fullscreen mode Exit fullscreen mode

Custom Events

<!-- Track custom goals -->
<script>
  // Track button clicks
  document.getElementById('signup-btn').addEventListener('click', () => {
    plausible('Signup');
  });

  // Track with custom properties
  plausible('Purchase', { props: { plan: 'pro', amount: 49 } });

  // Track form submissions
  plausible('Contact Form', { props: { source: 'homepage' } });
</script>
Enter fullscreen mode Exit fullscreen mode

Why Plausible Over Google Analytics

Plausible Google Analytics 4
1KB script 45KB+ script
No cookies Requires consent banner
GDPR compliant by default Complex consent mode
Simple dashboard 100+ reports to learn
Own your data (self-host) Google owns your data
Open source Proprietary

Need web data for analytics? Check out my web scraping actors on Apify — automated data collection from any site.

Need a custom analytics solution? Email me at spinov001@gmail.com.

Top comments (0)