Skip to content
Documentation GitHub
Platform

Analytics System

Status: Implemented Crates: crates/application/src/analytics/, crates/infrastructure/supabase/src/analytics/


The Analytics System is a queue-based, offline-first pipeline for tracking pseudonymous usage events. Events are enqueued locally and flushed to the analytics backend when network connectivity is available. The system contains no PII — only pseudonymous identifiers and behavioral event types.

Users can opt out via the analytics_enabled setting. When disabled, no events are enqueued or flushed.


The analytics system is one of three identity-adjacent concerns that must never be conflated:

ConcernWhat It IsStorage
IdentityOffline-permanent local user profileIdentityStore (local)
AuthRemote service tokens / JWTAuthRepository (Supabase)
AnalyticsPseudonymous offline-first event queueAnalytics queue (local + flush)

Each has a separate lifecycle and storage mechanism. Analytics uses the user’s pseudonymous identity, not their auth token or real identity.



Three use cases in crates/application/src/analytics/:

Use CaseDescription
EnqueueAnalyticsEventUseCaseAdd an event to the local queue. No-op when analytics is disabled.
FlushAnalyticsQueueUseCaseSend pending events to the analytics backend. Called when online.
PendingAnalyticsCountUseCaseReturn the count of undelivered events in the local queue.

Events are stored locally until flushed:

CREATE TABLE analytics_queue (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event_type TEXT NOT NULL, -- Pseudonymous event name
properties TEXT, -- JSON: non-PII event properties
user_id TEXT, -- Pseudonymous identifier (not auth UUID)
created_at TEXT NOT NULL
DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now'))
);

Analytics events are triggered as a fire-and-forget side effect via WriteEffectCoordinator. After a mutation use case completes, the coordinator dispatches a bounded set of side effects — embedding queue, event log, sync queue, and analytics. Analytics enqueue is non-blocking and does not affect the outcome of the originating mutation.


The analytics_enabled user setting (default: true) gates all analytics activity. When set to false:

  • EnqueueAnalyticsEventUseCase returns Ok(()) immediately without writing to the queue
  • FlushAnalyticsQueueUseCase skips without sending
  • No existing queue entries are deleted (they age out naturally)

  • Write-Effect Coordinator — Dispatches analytics as a side effect
  • Auth System — Separate concern (remote tokens, not analytics)
  • User Settings Systemanalytics_enabled setting
  • crates/application/src/analytics/ — Use case implementations
  • crates/infrastructure/supabase/src/analytics/ — Flush transport implementation

Was this page helpful?