Plausible Analytics

monitoring platformprivacy-focused analyticslightweight web analyticsGDPR compliantcookie-free

Monitoring Platform

Plausible Analytics

Overview

Plausible Analytics is a privacy-focused lightweight web analytics tool providing simple and intuitive dashboard without cookies, GDPR compliant. This next-generation analytics tool is rapidly growing with increasing privacy awareness, serving as a popular alternative choice for users dissatisfied with Google Analytics privacy concerns and UI complexity.

Details

Plausible Analytics is designed as a platform that addresses modern web analytics needs emphasizing "simplicity" and "privacy," positioned as an antithesis to traditional complex analytics tools.

Key Features

  • Privacy-First: Cookie-free with full GDPR and CCPA compliance
  • Lightweight Script: Sub-45KB tracking script (17x smaller than GA)
  • Real-time Dashboard: Simple and intuitive reporting interface
  • Open Source: Fully open source ensuring transparency
  • Automated Reports: Weekly and monthly automated email reports
  • Goal Setting: Conversion and custom event tracking
  • Country and Device Analysis: Geographic distribution and device information

Technical Features

  • Cookie-free: No user consent banners required
  • Fast Loading: Minimal impact on page load speed
  • Server-side: Data processing in EU private cloud
  • API Provided: APIs for data retrieval and custom integrations
  • Self-hosting: Can be run on your own servers

Pros and Cons

Pros

  • Full compliance with privacy regulations (GDPR, CCPA, etc.)
  • Very lightweight with no impact on page speed
  • Simple and user-friendly interface
  • Cookie-free requiring no user consent banners
  • Open source with high transparency
  • Automated reporting features
  • Self-hosting capability

Cons

  • Limited functionality compared to Google Analytics
  • Lacks advanced analysis and segmentation features
  • Limited integration with existing marketing tools
  • No free version (paid only)
  • Shorter data retention periods
  • Lacks enterprise-level features

References

Setup and Monitoring Examples

Basic Setup

<!-- Plausible Analytics tracking code -->
<script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.js"></script>

<!-- Custom domain usage -->
<script defer data-domain="yourdomain.com" src="https://analytics.yourdomain.com/js/script.js"></script>

<!-- With exclusion settings -->
<script defer data-domain="yourdomain.com" data-exclude="/admin/*,/dashboard/*" src="https://plausible.io/js/script.js"></script>

Metrics Collection

// Custom event tracking (using script.outbound-links.js)
<script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.outbound-links.js"></script>

// Goal setting (JavaScript events)
function triggerPlausibleEvent(eventName, options = {}) {
  if (window.plausible) {
    window.plausible(eventName, options);
  }
}

// Custom event sending examples
triggerPlausibleEvent('Newsletter Signup');
triggerPlausibleEvent('Download', { props: { method: 'PDF' } });

// Automatic external link click tracking
<script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.outbound-links.js"></script>

// File download tracking
<script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.file-downloads.js"></script>

Alerting Configuration

// Data retrieval using Stats API
const API_TOKEN = 'your-api-token';
const SITE_ID = 'yourdomain.com';

async function getPlausibleStats() {
  const response = await fetch(`https://plausible.io/api/v1/stats/aggregate?site_id=${SITE_ID}&period=day&metrics=visitors,pageviews,bounce_rate,visit_duration`, {
    headers: {
      'Authorization': `Bearer ${API_TOKEN}`
    }
  });
  
  const data = await response.json();
  return data.results;
}

// Custom alert implementation example
async function checkDailyTraffic() {
  try {
    const stats = await getPlausibleStats();
    const visitors = stats.visitors.value;
    
    if (visitors < 100) {
      console.log('Traffic alert: Low visitor count detected');
      // Notification to Slack/Discord etc.
    }
  } catch (error) {
    console.error('Failed to fetch Plausible stats:', error);
  }
}

Dashboard Creation

// Custom dashboard creation with Plausible Stats API
class PlausibleDashboard {
  constructor(apiToken, siteId) {
    this.apiToken = apiToken;
    this.siteId = siteId;
    this.baseUrl = 'https://plausible.io/api/v1/stats';
  }

  async getBreakdown(property, period = '30d') {
    const response = await fetch(`${this.baseUrl}/breakdown?site_id=${this.siteId}&period=${period}&property=${property}`, {
      headers: { 'Authorization': `Bearer ${this.apiToken}` }
    });
    return response.json();
  }

  async getTimeseries(period = '30d', interval = 'date') {
    const response = await fetch(`${this.baseUrl}/timeseries?site_id=${this.siteId}&period=${period}&interval=${interval}`, {
      headers: { 'Authorization': `Bearer ${this.apiToken}` }
    });
    return response.json();
  }

  async generateReport() {
    const [pages, countries, devices, timeseries] = await Promise.all([
      this.getBreakdown('event:page'),
      this.getBreakdown('visit:country'),
      this.getBreakdown('visit:device'),
      this.getTimeseries()
    ]);

    return {
      topPages: pages.results,
      topCountries: countries.results,
      deviceBreakdown: devices.results,
      trafficTrend: timeseries.results
    };
  }
}

Log Analysis

// Self-hosting environment configuration
// docker-compose.yml example
version: "3.3"
services:
  plausible_db:
    image: postgres:14-alpine
    restart: always
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=postgres

  plausible_events_db:
    image: clickhouse/clickhouse-server:22.6-alpine
    restart: always
    volumes:
      - event-data:/var/lib/clickhouse
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

  plausible:
    image: plausible/analytics:v2.0
    restart: always
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    depends_on:
      - plausible_db
      - plausible_events_db
    ports:
      - 8000:8000
    env_file:
      - plausible-conf.env

volumes:
  db-data:
    driver: local
  event-data:
    driver: local

Integration Setup

// Plausible integration with Next.js
// pages/_app.js
import Script from 'next/script'

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Script
        defer
        data-domain="yourdomain.com"
        src="https://plausible.io/js/script.js"
      />
      <Component {...pageProps} />
    </>
  )
}

// React Hook for Plausible
import { useEffect } from 'react';
import { useRouter } from 'next/router';

export function usePlausible() {
  const router = useRouter();

  useEffect(() => {
    const handleRouteChange = () => {
      if (window.plausible) {
        window.plausible('pageview');
      }
    };

    router.events.on('routeChangeComplete', handleRouteChange);
    return () => {
      router.events.off('routeChangeComplete', handleRouteChange);
    };
  }, [router.events]);

  const trackEvent = (eventName, options = {}) => {
    if (window.plausible) {
      window.plausible(eventName, options);
    }
  };

  return { trackEvent };
}

// WordPress plugin configuration
// Add to functions.php
function add_plausible_analytics() {
    ?>
    <script defer data-domain="<?php echo get_site_url(); ?>" src="https://plausible.io/js/script.js"></script>
    <?php
}
add_action('wp_head', 'add_plausible_analytics');