Convex Analytics

First-party real-time analytics for Convex with drop-in React dashboard, browser SDK, and HTTP ingest - no third-party services required

Installation

npm install @abdssamie/convex-analytics

About Convex Analytics

A complete first-party analytics solution for Convex applications that tracks pageviews, custom events, and user identity directly into your own database. Provides a real-time HTTP ingestion endpoint, a React dashboard component with timeseries charts, and a lightweight browser SDK with auto-batching. Events are stored and processed entirely within your Convex deployment without requiring third-party services.

Benefits

Use cases

how to add analytics to Convex app without third party services

Convex Analytics provides first-party analytics that stores all data in your Convex database. Install the component, create a site with a write key, and use the browser SDK to track events. All user data stays in your deployment.

real-time analytics dashboard for React app

Use the AnalyticsDashboard React component to render timeseries charts, top pages, referrers, and custom events. The dashboard connects to authenticated Convex queries and updates in real-time as new events are tracked.

track custom events and user properties in Convex

The browser SDK provides track() and identify() methods to send custom events with properties and link anonymous visitors to user IDs. Events are batched and sent to a high-speed HTTP endpoint for real-time ingestion.

self-hosted web analytics alternative to Google Analytics

Convex Analytics runs entirely within your Convex deployment, tracking pageviews, sessions, referrers, and custom events. You control the data and can query it directly using Convex functions for custom reports.

Frequently asked questions

How does Convex Analytics handle data privacy compared to third-party analytics?

Convex Analytics stores all data in your own Convex database, so no user data is sent to external services. You control data retention, access, and compliance. The write key acts like a publishable key for browser ingestion but requires authentication for dashboard access.

What's the difference between the HTTP ingest route and Convex mutations for tracking?

Convex Analytics uses HTTP ingest for browser events instead of public mutations for better performance and security. The browser SDK batches events and sends them to the HTTP route, which hashes the write key before calling internal component functions.

How does real-time aggregation work in the analytics component?

Raw events are inserted quickly with aggregatedAt: null, then a background worker processes them into visitors, sessions, and hourly/daily rollups. Dashboard queries use these materialized views for fast reporting while raw events remain available for detailed analysis.

Can I track multiple sites or apps with one Convex Analytics deployment?

Yes, Convex Analytics supports multiple sites through the sites table. Each site has its own write key and allowed origins. For single-site use cases, create one site named 'default' and ignore the multi-site features until needed.

What happens if my analytics write key gets leaked?

The write key is treated like a publishable key for ingestion only. Protect your deployment by setting allowedOrigins to restrict which domains can send events. Rotate the key by updating both your site record and frontend environment variables if needed.

Links