Skip to content

suhodolskiy/plausible-api

Repository files navigation

Plausible Stats

NPM Version NPM License

A simple wrapper over Plausible API

Installation

$ npm install @suhodolskiy/plausible-api

Example

import Plausible from '@suhodolskiy/plausible-api'

const stats = new Plausible.Stats({
  apiUrl: 'https://plausible.io', // or your own domain
  apiKey: '',
})

Realtime Visitors

const result = await stats.realtimeVisitors('siteId')

console.log(result) // 99

Breakdown Stats

const results = await stats.breakdown('siteId', 'event:props:method', {
  period: '6mo',
  filters: {
    'event:name': 'Download',
  },
})

console.log(results)
[
  {
    "method": "HTTP",
    "visitors": 1477
  },
  {
    "method": "Magnet",
    "visitors": 370
  }
]