Deploy Open Analytics | (Just Updated) Google Analytics Alternative, Admin Login Generated, Sign-up Closed

Open Analytics self-hosted web analytics, Google Analytics alternative

Deploy Open Analytics | (Just Updated) Google Analytics Alternative, Admin Login Generated, Sign-up Closed

Deploy and Host Open Analytics on Railway

Built for an LLM agent to deploy and use. The deploy form has no fields to fill: the admin login is generated, public sign-up is closed from the first request, and every database lives on a volume. Open Analytics is open-source, privacy-friendly web analytics, a self-hosted Google Analytics alternative with pageviews, sessions, custom events, conversions, web vitals, a live realtime view and a REST API.

About Hosting Open Analytics

This template runs eleven services. Four are public: web (the dashboard), api (the REST and sign-in API), collector (event ingest, the address a tracked page sends to) and realtime (the live feed). Seven are private: gateway (the query gateway), worker (sessionizing and rollups), migrate (the one-shot schema job), postgres (accounts, sites and settings, on a volume at /var/lib/postgresql), clickhouse (events, on a volume at /var/lib/clickhouse), valkeyq (the durable queue, on a volume at /data) and valkeyr (the realtime cache, on a volume at /data). The Open Analytics v0.8.0 images are pinned by digest, and so are the wrappers.

What the wrappers fix. Upstream signs its internal tokens and encrypts its credentials with keys you are expected to generate and distribute by hand, and has no variable that creates the first admin. The wrappers derive each signing key from a per-purpose generated seed (OA_QUERY_SEED, OA_REALTIME_SEED, OA_KEYRING_SEED), wait for the schema job before starting, create the admin from ADMIN_EMAIL and ADMIN_PASSWORD before the API listens, and run nginx in front of the public node services so the client address is the first X-Forwarded-For hop. Sign-up is closed: POST /api/auth/sign-up/email answers 403.

Measured on a Railway control deploy of this template: a sign-up from outside answers 403, a write without a session answers 401, the generated admin signs in, a wrong password answers 401, a site is created, a pageview sent to the collector is accepted with 202 and the overview read on the API shows it.

Using it. Open the web domain and sign in with ADMIN_EMAIL and ADMIN_PASSWORD from the api service variables. ADMIN_EMAIL is admin@ followed by the web domain. Create a site, then put the tracking snippet it shows on your pages; it sends to the collector domain. An agent can do the same through the API below. Redeploys keep the same login, because the admin is only created when the database has no user, and the data is on the volumes.

Agent contract

  • Public URL: https://WEB_PUBLIC_DOMAIN (dashboard, the web service), https://API_PUBLIC_DOMAIN (REST and sign-in, the api service), https://COLLECTOR_PUBLIC_DOMAIN (ingest, the collector service); each is the RAILWAY_PUBLIC_DOMAIN of that service
  • Private URL: http://api.railway.internal:8080 and http://collector.railway.internal:8080
  • Credentials: the variables ADMIN_EMAIL and ADMIN_PASSWORD on the api service are the admin login, given as plain text
  • Auth: POST /api/auth/sign-in/email on the api domain with a JSON body {"email":"...","password":"..."} and an Origin header equal to the web URL returns a session cookie; send the cookie and the same Origin on every call. Without it a read or write answers 401. Sign-up is closed (POST /api/auth/sign-up/email answers 403). Event ingest, POST /v1/events on the collector, is public by design, because a tracked page sends it, and is keyed by the site's public tracking token.
  • Health: GET /health on the api domain returns 200 without credentials
#!/bin/sh
# needs: WEB_PUBLIC_DOMAIN, API_PUBLIC_DOMAIN, COLLECTOR_PUBLIC_DOMAIN (RAILWAY_PUBLIC_DOMAIN of the web, api and collector services), ADMIN_EMAIL and ADMIN_PASSWORD (variables of the api service); also curl, sed, od and GNU date.
W="https://$WEB_PUBLIC_DOMAIN"; A="https://$API_PUBLIC_DOMAIN"; K="https://$COLLECTOR_PUBLIC_DOMAIN"
J="Content-Type: application/json"
O="Origin: $W"
C=$(mktemp)
n=0; until [ "$(curl -s -o /dev/null -w '%{http_code}' "$A/health")" = 200 ]; do n=$((n+1)); [ "$n" -le 90 ] || break; sleep 5; done
curl -s -o /dev/null -w "health: %{http_code}\n" "$A/health"
# sign-up is closed: a stranger cannot create an account
curl -s -X POST -H "$J" -H "$O" -d '{"email":"stranger@example.com","password":"stranger-password-1","name":"stranger"}' "$A/api/auth/sign-up/email" -o /dev/null -w "public signup: %{http_code}\n"
# a stranger cannot read or write analytics data: no session and a wrong password are both refused
curl -s -o /dev/null -w "read without key: %{http_code}\n" -H "$O" "$A/v1/sites"
curl -s -X POST -H "$J" -H "$O" -d '{"slug":"stranger","name":"stranger"}' "$A/v1/sites" -o /dev/null -w "write without key: %{http_code}\n"
curl -s -X POST -H "$J" -H "$O" -d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"not-the-admin-password\"}" "$A/api/auth/sign-in/email" -o /dev/null -w "login with wrong password: %{http_code}\n"
# the generated admin signs in and receives a session cookie
CODE=$(curl -s -c "$C" -X POST -H "$J" -H "$O" -d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}" "$A/api/auth/sign-in/email" -o /dev/null -w '%{http_code}')
if [ "$CODE" = 200 ]; then echo "login with key: ok"; else echo "login with key: FAILED $CODE"; fi
curl -s -b "$C" -H "$O" "$A/v1/sites" -o /dev/null -w "read with key: %{http_code}\n"
# with the session: create a site, the response carries its tracking token
SLUG="agent-$(date +%s)"
curl -s -b "$C" -X POST -H "$J" -H "$O" -d "{\"slug\":\"$SLUG\",\"name\":\"agent\"}" "$A/v1/sites" -o site.json
SITE=$(sed -n 's/^{"site_id":"\([^"]*\)".*/\1/p' site.json)
TK=$(sed -n 's/.*"public_token":"\([^"]*\)".*/\1/p' site.json)
if [ -n "$SITE" -a -n "$TK" ]; then echo "write with key: ok"; else echo "write with key: FAILED"; fi
# ingest is public by design (a tracked page sends it): one pageview with a browser-like request and a lowercase UUIDv7 event_id
NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
HEX=$(printf '%012x' "$(date +%s%3N)")
RND=$(od -An -N10 -tx1 /dev/urandom | tr -d ' \n')
EID="$(echo $HEX | cut -c1-8)-$(echo $HEX | cut -c9-12)-7$(echo $RND | cut -c1-3)-8$(echo $RND | cut -c4-6)-$(echo $RND | cut -c7-18)"
UA='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
curl -s -X POST -A "$UA" -H "$J" -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.9' -H 'Origin: https://example.com' -d "{\"schema_version\":1,\"tracking_key\":\"$TK\",\"sent_at\":\"$NOW\",\"context\":{\"sdk\":\"web\",\"sdk_version\":\"1.0.0\"},\"events\":[{\"event_id\":\"$EID\",\"type\":\"page_view\",\"occurred_at\":\"$NOW\",\"page\":{\"url\":\"https://example.com/hello\",\"title\":\"Hello\"}}]}" "$K/v1/events" -o /dev/null -w "ingest: %{http_code}\n"
# the pageview becomes queryable after the worker has rolled it up
FROM=$(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%S.000Z); TO=$(date -u -d '1 hour' +%Y-%m-%dT%H:%M:%S.000Z)
ov() { curl -s -G -b "$C" -H "$O" --data-urlencode "from=$FROM" --data-urlencode "to=$TO" --data-urlencode "timezone=UTC" "$A/v1/sites/$SITE/analytics/overview"; }
n=0; until ov | grep -q '"pageviews":[1-9]'; do n=$((n+1)); [ "$n" -le 24 ] || break; sleep 5; done
if ov | grep -q '"pageviews":[1-9]'; then echo "data stored: ok"; else echo "data stored: FAILED"; fi

Expected output against a fresh deploy:

health: 200
public signup: 403
read without key: 401
write without key: 401
login with wrong password: 401
login with key: ok
read with key: 200
write with key: ok
ingest: 202
data stored: ok

The refusals are the contract: public signup: 403, write without key: 401 and login with wrong password: 401. The snippet creates one site named agent with a fresh slug on every run and writes site.json in the current directory.

Why Deploy Open Analytics on Railway?

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 Open Analytics 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.

  • Agent-ready - no deployer fields, a contract block, and one script that proves health, closed sign-up, refused strangers, a signed-in write, ingest and stored data.
  • Locked from the first request - the admin is created before the API listens and public sign-up is off, so nobody can claim the instance before you do.
  • Keys generated for you - the signing and encryption keys are derived from generated seeds, nothing to distribute by hand.
  • Data survives redeploys - Postgres, ClickHouse and both Valkey instances each have a volume.
  • Pinned - the Open Analytics images are pinned by digest, and so are the wrappers.

Common Use Cases

  • Privacy-friendly website analytics - pageviews, sessions and referrers without a consent banner.
  • Product analytics for an app - custom events, conversions and web vitals on infrastructure you own.
  • A Google Analytics alternative for a client site - one login, one tracking snippet, and the data stays in your project.

Dependencies for Open Analytics Hosting

  • The eleven services and four volumes created by the template. Nothing external is required.
  • Open Analytics is licensed AGPL-3.0; the wrappers change no upstream source. No IP geolocation database is bundled, so country and city fields stay empty unless you add one.

Deployment Dependencies


Template Content

More templates in this category

View Template
Plausible WordPress
Cookie-free WordPress stats from your own Plausible

onepush
0
View Template
Typesense Multilingual
Locale-aware multilingual search with Typesense

onepush
0
View Template
Formbricks
Surveys, NPS and in-app feedback on your own Postgres, Hub and Cube

Two Workspaces
3