
Deploy Plausible Stats API
Query your own pageview data over the Stats API
Just deployed
/var/lib/postgresql/data
Just deployed
/var/lib/clickhouse
plausible
Just deployed
/var/lib/plausible
Deploy and Host self hosted Plausible Stats API (Open-Source Analytics API) on Railway
This template runs Plausible CE v3.2.1 with Postgres and ClickHouse on Railway, so you can query your own pageviews and goals over Stats API v2 with a Bearer key. It is built for developers and agencies pulling weekly client numbers.
About Hosting Plausible Stats API open-source software on Railway (self hosted Plausible Stats API template)
This template runs the official Plausible CE v3.2.1 image alongside its own Postgres and ClickHouse, so pageviews, goals and events stay inside your project. You read that data with POST /api/v2/query and a Bearer Stats API key, and a key covers every site its user can access. You'll still need to schedule backups of Postgres and the ClickHouse volume.
Why Deploy Plausible Stats API, the Google Analytics Data API alternative on Railway (Railway Free Trial)
You own the ClickHouse events table, so no per-property API quotas from Google sit between you and your numbers. A Hobby plan is $5/mo with $5 of usage, and new accounts get a $5 trial credit to test the query endpoint first.
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Plausible Stats API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Railway vs Other Hosting Providers and VPS for Plausible Stats API self hosting
Same three services anywhere Docker runs; the difference is wiring before the first query.
| Provider | What You Get with Railway | What You Get with the Other Provider |
|---|---|---|
| DigitalOcean | Plausible, Postgres and ClickHouse with TLS wired | A droplet; you add Docker, TLS and backups |
| AWS | One click, managed volume, /api/health check | EC2, RDS and a ClickHouse node you wire yourself |
| Hetzner | Usage billing, no server to patch, resize RAM | Cheap CPU and RAM, but you own proxies and upgrades |
2 GB RAM is the floor either way, and ClickHouse eats it.
Common Use Cases for hosted Plausible Stats API
- Weekly client reports: an agency cron job pulls top pages and sources per site with date_range 30d, then fills the same spreadsheet template every Monday.
- Slack or Discord digest: post yesterday's visitors, pageviews and goal count to a channel each morning, cached so a retry doesn't burn the 600 requests per hour budget.
- Metabase or Grafana: pull a time:day series for each site and let the BI tool chart traffic without anyone opening the Plausible dashboard.
- Product dashboard: query event:goal conversion_rate for signup and trial events, filtered by visit:device, to show funnel numbers next to deploys.
- Campaign comparison: order_by visits with dimensions visit:utm_source and visit:utm_campaign to see which newsletter or ad actually landed.
Dependencies for Plausible Stats API Docker hosted on Railway
The template runs three services: the app image, Railway Postgres for users, sites, goals and settings, and ClickHouse for events. The Stats API reads events out of ClickHouse on every query, so reporting stops the moment that volume is detached, full or unhealthy.
Deployment Dependencies for Managed Plausible Stats API Service (Web Analytics API)
Postgres supplies DATABASE_URL from the Postgres service, and ClickHouse is reached through CLICKHOUSE_DATABASE_URL over the private HTTP interface on port 8123. Set BASE_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}, a stable SECRET_KEY_BASE of 64 or more bytes, and a TOTP_VAULT_KEY you never rotate. LISTEN_IP=:: and ECTO_CH_IPV6=true are required because Railway private networking is IPv6 only.
Implementation Details for Plausible Stats API (Using Plausible official docker image)
The plausible service runs ghcr.io/plausible/community-edition:v3.2.1 on port 8000 with a volume mounted at /var/lib/plausible. Its start command runs /entrypoint.sh db createdb, then db migrate, then run, and the healthcheck at /api/health reports postgres, clickhouse and sessions status. RAILWAY_RUN_UID=0 lets the app write to that volume.
How does Plausible Stats API compare against other analytics reporting APIs
Plausible vs Google Analytics Data API
- Shape: both take a POST with metrics and a date range, but Plausible returns flat rows with no GA4 schema to learn.
- Privacy: data is cookieless and sits in your own ClickHouse, so there is no consent banner and no modeled gaps.
- GA wins: official client libraries for every language, plus far deeper ad and audience segments.
Plausible vs Fathom API
- Self hosted: Fathom is closed SaaS with no on-prem option; here the events and the database are yours.
- Auth: Fathom also uses a Bearer token, so existing scripts port over with small field changes.
- Fathom wins: nothing to run, no ClickHouse memory to size, and a support desk that answers the ticket.
Plausible vs Umami API
- Stack: Umami v3 needs only PostgreSQL, so it is lighter to operate than Plausible plus ClickHouse.
- Query model: Umami uses GET endpoints with query params; Plausible v2 takes one JSON body with filters and order_by.
- Umami wins: a simpler single database and a smaller memory footprint on small VPS boxes.
Plausible vs Matomo Reporting API
- Format: Matomo returns nested PHP-style reports per method call; Plausible gives one row set per query.
- Features: Matomo ships more reports out of the box, though heatmaps and funnels are paid plugins on-premise.
- Matomo wins: a broader feature suite and a longer track record for GA-style reporting.
How to use Plausible Stats API (the OSS web analytics tool)?
- Log in at your Railway domain, add your site under Sites, and paste the tracking script into your page head.
- In account settings, open API Keys, click New API Key, and choose the Stats API type.
- Test the endpoint with curl, swapping site_id for the domain you added:
curl -X POST https://your-domain/api/v2/query \
-H "Authorization: Bearer YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{"site_id":"example.com","metrics":["visitors","pageviews"],"date_range":"7d","dimensions":["event:page"]}'
- Schedule the same request from a cron job and cache the JSON to disk, so report reads do not burn the 600 requests per hour key budget.
How to self host Plausible Stats API on other VPS Services (Plausible self hosting guide)
Clone the Repository
Grab the tagged release, not master:
git clone -b v3.2.1 --single-branch https://github.com/plausible/community-edition plausible-ce
cd plausible-ce
Install Dependencies
You need Docker Engine with Compose v2, plus a CPU with SSE 4.2 (or NEON) for ClickHouse. Give the box 2 GB RAM minimum.
Configure Environment Variables
Create .env with the public URL and a stable 64 byte secret:
touch .env
echo "BASE_URL=https://your-domain" >> .env
echo "SECRET_KEY_BASE=$(openssl rand -base64 48)" >> .env
Add HTTP_PORT=80 and HTTPS_PORT=443 plus a compose.override.yml publishing them for built-in Let's Encrypt, or run behind your own proxy.
Start the Plausible Stats API Application
docker compose up -d
Open your-domain, create the owner account, add a site, then make a Stats API key and POST to /api/v2/query. Railway handles the Postgres and ClickHouse wiring, private IPv6 networking and the healthcheck for you.
Official Pricing of Plausible Stats API (Plausible pricing)
The Stats API is part of Plausible CE, which is free under AGPL-3.0. There is no per-query charge, no seat fee and no pageview tier. Plausible Cloud, for reference, starts at $9 per month for 10k pageviews, with the Stats API on the Business tier at $19 per month.
Plausible Stats API cloud vs self hosted comparison (Pricing, features, costs, and more)
Self hosting keeps the same v2 endpoint and query shape as Cloud, minus Cloud-only business features. You pay for infrastructure instead of a subscription and own the data.
Monthly cost of self hosting Plausible Stats API on Railway
Railway bills usage, not seats. A low-traffic site usually lands around $10-20/mo across the three services; heavier event volume and RAM push it higher. Hobby is $5/mo including $5 of usage, and new accounts get a one-time $5 trial credit. Trial services cap at 1 GB RAM each, tight for ClickHouse, so treat it as a test drive.
System Requirements for Hosting Plausible Stats API on a VPS
ClickHouse needs a CPU with SSE 4.2 or NEON, and 2 GB RAM is recommended to avoid OOMs. Back up the events volume and Postgres. On CE, revenue metrics, funnels and SSO stay Cloud-only; country stats work out of the box.
Frequently Asked Questions (FAQs)
Where do I create a Stats API key?
In your Plausible account settings under API Keys, click New API Key and pick the Stats API type.
What is the rate limit?
Keys default to 600 requests per hour. Cache results for dashboards and cron jobs so a five-minute refresh across several sites does not burn the budget.
Can one key read several sites?
Yes. A key inherits the sites its user can access, so one agency key can query every client site if that owner has access to all of them. Pass site_id in each request.
Does the API sample data?
No. Queries hit the same ClickHouse events the dashboard reads, with no sampling. Ranges like 12mo and all return exact numbers.
Is the v1 API still available?
Yes, /api/v1/stats/aggregate, /timeseries and /breakdown still exist, but v2 is the documented path.
Can I get revenue metrics on CE?
No. Revenue metrics are a Plausible Cloud business feature and ecommerce revenue goals are not in CE. Track a goal conversion instead.
Template Content
