How to build a Mixpanel alternative

How to build a Mixpanel alternative with a bounded event schema, one ordered funnel, and daily counts. Test retries, identity rules, and deployment.

  • vibe-coding
  • guide

How to build a Mixpanel alternative starts with event tracking for one product and one ordered funnel.

We will build an event receiver, a daily trend and a funnel with explicitly defined ordering. Begin with the Mixpanel catalog prompt. The Mixpanel teardown explains the wider product boundary. This tutorial uses a proposed small architecture, rather than describing Mixpanel’s implementation.

How to build a Mixpanel alternative with one funnel

Pick a journey you control, such as creating a project and completing its first export. Define project_created and export_completed as server events. A page opening is a different event. Keep the first funnel on one authenticated user id and avoid anonymous-to-known identity merging. Record the limitation in the dashboard.

The v1 counts accepted events and users completing the ordered pair within seven days. Seven days is a chosen example window for this build. It is not a product benchmark. Use UTC instants for event ordering and one documented timezone for daily buckets. Show the timezone beside every date selector.

Record Fields Constraint
Event definition Project, name, allowed properties Unique project and name
Event Project, event id, actor id, name, occurred time Unique project and event id
Funnel First event, second event, window Both events belong to project
Ingest rejection Category, time, count No rejected payload bodies

Step 1 Accept only known events

Reject unknown names and unexpected property keys. Limit the payload size and number of events per request. Use an ingest credential scoped to a project. For browser collection, treat any embedded key as public and protect the endpoint with validation and rate limits. Server events can use a secret credential that never reaches the browser.

Build event ingestion with project-scoped credentials and an event allowlist.
Accept event id, opaque actor id, event name and occurred timestamp. Bound
payload size and timestamp drift. Deduplicate by project and event id.
Reject arbitrary nested properties. Store no email, IP address or raw URL.
Return accepted and rejected counts without echoing sensitive payloads.

Send the same event twice and expect one stored event. Send another project’s credential with the first project’s id and expect refusal. Test invalid dates and a payload over the byte limit. A batch should have a documented atomic or partial-acceptance policy; choose atomic acceptance for the first version so retries stay easier to explain.

Step 2 Build a daily event table

Start with a SQL count grouped by event name and reporting date. Render a table before adding a chart. A missing day becomes zero only after the requested range was successfully queried. A database failure should show unavailable data. Those states mean different things when someone uses the dashboard to judge a launch.

Build a daily event report with a bounded date range and explicit timezone.
Group accepted events by name and reporting date. Fill missing dates with
zero only after a successful query. Show totals and a source-data cutoff.
Add a simple bar chart backed by the same table. Query failures preserve
the date selection and offer retry instead of drawing a zero chart.

Use fixtures around midnight and a daylight-saving transition. Confirm a table cell and chart bar come from the same aggregate. Filter to an event with no accepted rows, then stop the database and retry. The second result must never resemble the first. Cap date ranges so a malformed request cannot trigger an unlimited report.

Step 3 Define ordered conversion precisely

An actor enters the funnel at their first qualifying first event within the selected cohort range. Count them once. Look for a second event strictly after that timestamp and within the chosen seven-day window. Give equal timestamps a documented rule; this first release excludes them. The conversion may happen after the cohort selection’s end date.

Implement a two-step funnel using the first qualifying entry per actor.
Count each actor once. A completion must follow entry strictly and occur
within seven days. Cohort dates constrain entry, not completion. Return
entered, completed and pending counts with a source cutoff. Exclude equal
timestamps and explain this rule beside the report.

Create actors who finish before entry, after the window, exactly at the boundary, and twice within the window. Write their expected results before running the query. A recent cohort can still convert later, so show it as incomplete while its window is open. Avoid comparing an unfinished cohort with a fully observed one without that label.

Step 4 Handle deletion and late arrivals

Choose a maximum accepted event age. A late event inside that policy should rebuild affected aggregates or be included by direct queries. Start with direct queries and indexes while the dataset is small. Cached counts require an invalidation rule; introducing them too early makes corrections harder to inspect.

Add deletion by opaque actor id within one authorized project. Remove
matching events and invalidate derived reports. Document accepted event
age and retention. Add indexes for project, event name, actor and occurred
time. Show report cutoff and pending cohort status. Test deletion after a
conversion was previously counted.

Deleting the actor must remove them from both entry and completion counts. Export a report with its event definitions and window, so the recipient can understand the numbers. Keep raw event export private. If a request fails midway, the deletion should be retryable without leaving a half-updated aggregate.

Keep identity merging and replay outside v1

Skip cross-device stitching, session replay, attribution models and a visual query builder. Add another funnel only when you can state its ordering rules and fixtures. The Plausible guide covers simpler page metrics. Use that model if event-level journeys provide no useful decision for your product.

Keep the server responsible for ownership

Use Astro server rendering with ordinary forms, HTMX for partial updates, and Alpine for local preview state. A Node.js server and SQLite are enough for the first deployment. Use a single persistent disk with backups. If your hosting platform cannot keep a local database across deployments, choose a managed relational database before adding real records.

Put the authenticated account id in server session state. Never trust a hidden owner field submitted by a form. Every lookup should constrain the record by both its id and its account. A record that exists for another account should remain inaccessible through exports, detail pages, background jobs and attachment downloads too.

Implement an authenticated Astro application with server-rendered forms.
All reads and mutations enforce account ownership on the server. Add CSRF
protection, bounded inputs and parameterized queries. HTMX responses use
the same authorization as full pages. Keep credentials server-only. Provide
a complete empty state and a separate recoverable database-error state.

Create two test accounts. Save a record under one, then substitute its id in requests from the other. Exercise a normal HTML request and the partial-update endpoint. Both must refuse access. Signing out must invalidate the session rather than only hiding the navigation. Keep sensitive values out of request logs and exception pages.

Make writes safe to retry

A browser can lose the response after a database commit. Refreshing the page or pressing the button again should return the result of that operation. Give important mutations a unique request id and save it with the outcome inside the transaction. Reusing that id with different input should produce a conflict, rather than quietly reusing an unrelated result.

Use revision checks for edits from multiple tabs. The form submits the revision it loaded. A stale revision gets a clear conflict screen that preserves the attempted input. The owner can reload the current record and choose which change to make. Avoid automatically merging fields whose relationship affects a calculation or publication decision.

Add idempotency tokens to important mutations and revision checks to edits.
Persist the request token and state change together. Duplicate identical
requests return the saved outcome. A reused token with different input is
rejected. A stale edit preserves the attempted values and offers reload.
Test a lost response after commit and two concurrent edits.

Check the database after retrying. A reassuring success message is insufficient if duplicate rows remain underneath. Also stop the process during a write in a test database. On restart, the operation should be complete or absent. Document where an external service would require a separate retry policy before introducing one.

Deploy with a restore path

Build the app, run its migrations against an empty staging database, and create the first owner through a private setup route or command. Disable that setup route afterwards. Configure HTTPS, secure session cookies and a persistent volume. Keep the database outside the release directory so replacing application files cannot replace live data.

Make a consistent database backup with the database engine’s supported backup mechanism. Copying an actively written file without understanding its journal mode can produce an incomplete backup. Encrypt backup storage through your hosting provider or an established backup tool, and keep access credentials outside the source repository.

Write deployment instructions for the chosen Node.js host, persistent
SQLite volume, migrations, HTTPS and server secrets. Add a health endpoint
that reports readiness without exposing records. Back up the database and
restore it into an isolated instance. Verify representative records and
permissions after restore. Document rollback with schema compatibility.

After deployment, use the real hostname. Sign in, create a harmless fixture, complete the core workflow, export it and sign out. Check the index and detail view after each change. Then try a missing id, a request with an expired session, and an intentionally unavailable database in staging. Each failure should tell the owner what they can do next.

Keep operational logs small. Record action ids, elapsed time and error categories, while omitting private payloads. Set an explicit retention policy and check disk usage. Before inviting anyone else, restore one backup into a separate environment and confirm that the application starts with the restored data. Save the recovery instructions beside the deployment configuration.

Related articles

Read all articles →