Skip to main content

@amisi-mobile-starter/analytics

@amisi-mobile-starter/analytics exposes an adapter registry, runtime functions, AnalyticsProvider, and useAnalytics. The runtime always registers mock; it loads firebase only when you initialize that adapter.

Initialize an adapter

enableAnalytics and enableCrashReporting both default to true. firebaseAppOptions is required only when no Firebase app already exists. Its required fields are apiKey, appId, projectId, and messagingSenderId; authDomain and storageBucket are optional. Use { adapter: 'mock' } when you do not want native Firebase modules.

Add the provider

Initialization and context are separate. AnalyticsProvider accepts only children; it does not accept configuration.

Use the hook

useAnalytics() must run inside AnalyticsProvider and returns these methods:
Valid interaction types are press, navigate, submit, and view. Events use { name, parameters? }. Users use { id, properties?: Record<string, string> }.

Runtime functions

You can call setAnalyticsEnabled, identifyAnalyticsUser, trackAnalyticsEvent, trackAnalyticsInteraction, and recordAnalyticsError outside React. These functions return without doing work when no adapter is active. Adapter failures are logged and not rethrown. The mobile root initializes Firebase when either flags.enableAnalytics or flags.enableCrashReporting is true. Demo mode selects mock instead.