Overview
TheMentiqAnalyticsProvider is the root component that wraps your application to enable analytics tracking. It features dynamic loading for optimal performance, server-side rendering support, and graceful error handling.
Props
Configuration object for the analytics instance. Contains your API key and tracking settings.
Your application components that will have access to analytics functionality.
Component to render if analytics fails to load. Defaults to rendering children without analytics.
Component to display while analytics is loading. Defaults to null.
Usage
Features
- Server-side rendering support - Automatically detects server environment and renders without analytics
- Code splitting - Analytics code is dynamically imported for better bundle optimization
- Lazy loading - Loads only on the client side when needed
- Error handling - Gracefully falls back to rendering children if analytics fails
- Loading states - Supports custom loading and fallback components
Behavior
Server-side
On the server, the provider returns children immediately without loading analytics.Client-side
- Shows loading state (if provided)
- Dynamically imports analytics module
- Initializes analytics instance
- Provides analytics context to children
- On error, shows fallback component
Related
- useAnalytics - Hook to access analytics from components