| ← All Docs Analytics

Analytics

Verified Against source code Last updated: September 2026

AquaDealers uses PostHog for product analytics and Sentry for error tracking and session replays. Both are initialized in src/lib/telemetry.ts via the initTelemetry() function, called at app startup in src/main.tsx.

Environment variables required: VITE_POSTHOG_KEY, VITE_POSTHOG_HOST (optional, defaults to https://app.posthog.com), and VITE_SENTRY_DSN. If any are missing, the respective SDK silently skips initialization with a console warning.

PostHog (Product Analytics)

Configuration

SettingValueNotes
Packageposthog-js ^1.376.0Client-side JS SDK
API KeyVITE_POSTHOG_KEYEnvironment variable
API HostVITE_POSTHOG_HOSTDefaults to https://app.posthog.com if unset
AutocapturefalseDisabled for privacy — no automatic click/pageview tracking
Capture modeManual onlyExplicit trackEvent() calls required

Exported API

Two functions are exported from src/lib/telemetry.ts:

FunctionSignaturePurpose
trackEvent (name: string, properties?: object) Capture a named event with optional properties
identifyUser (userId: string, traits?: object) Associate the current session with a dealer ID
Not instrumented: Neither trackEvent nor identifyUser are called anywhere in the application code. The hooks are defined and exported, but zero feature files import or invoke them. PostHog currently receives no events from AquaDealers. This means product analytics is effectively non-functional.

Privacy Design

Sentry (Error Tracking)

Configuration

SettingValueNotes
Package@sentry/react ^10.53.1React-specific SDK with ErrorBoundary support
DSNVITE_SENTRY_DSNSentry project identifier (env var)
Browser TracingEnabledSentry.browserTracingIntegration()
Session ReplayEnabledSentry.replayIntegration()
tracesSampleRate1.0100% of transactions sampled
replaysSessionSampleRate0.110% of all sessions get a replay (even without errors)
replaysOnErrorSampleRate1.0100% of error sessions get a replay
ErrorBoundaryWraps entire appsrc/main.tsx — branded crash fallback with captureException
Source MapsEnabledvite.config.tssourcemap: true for readable stack traces
Cost warning: tracesSampleRate: 1.0 samples every transaction. replaysSessionSampleRate: 0.1 records 10% of all sessions even without errors. At scale, this generates significant Sentry billing. Consider reducing tracesSampleRate to 0.1–0.3 as the user base grows.

What Sentry Captures

Error Boundary

The entire app is wrapped in <Sentry.ErrorBoundary> in src/main.tsx. When an unhandled React error occurs:

  1. Sentry captures the exception with full stack trace
  2. A branded crash fallback screen is shown to the user (CrashFallback component)
  3. The user can reload the page to recover

Instrumentation Status

Current Gap

The telemetry infrastructure is in place but product analytics is not wired up:

CapabilityStatusNotes
PostHog SDK initializationReadyInitializes when env var is present
trackEvent() functionExportedAvailable in src/lib/telemetry.ts
identifyUser() functionExportedAvailable in src/lib/telemetry.ts
Event instrumentationMissingZero call sites in the codebase — no events are tracked
User identificationMissingNever called — sessions are anonymous
Sentry error trackingActiveFully functional with ErrorBoundary + replays
Sentry performance tracingActive100% sample rate

Recommended Instrumentation

High-value events to instrument when enabling product analytics:

EventWhere to AddProperties
bill_createduseCheckout.ts after successful saveitem_count, total, payment_type, is_offline
payment_collectedPayment collection flowamount, method, farmer_id
whatsapp_sentwhatsAppService.tsmessage_type, method (api/wa.me)
report_exportedReport export handlersreport_type, format, date_range
user_identifiedAuth store on loginplan, branch_count, staff_count

Architecture

File Map

FilePurpose
src/lib/telemetry.tsPostHog + Sentry initialization, trackEvent(), identifyUser()
src/main.tsxCalls initTelemetry(), wraps app in Sentry.ErrorBoundary
vite.config.tssourcemap: true for Sentry stack traces
.envVITE_SENTRY_DSN, VITE_POSTHOG_KEY, VITE_POSTHOG_HOST