MentiqAnalyticsProvider
TheMentiqAnalyticsProvider is a React context provider that initializes and provides analytics functionality throughout your application. It features dynamic loading, server-side rendering support, and graceful error handling.
Features
- Server-side rendering (SSR) support
- Code splitting and lazy loading
- Better bundle optimization
- Graceful error handling
- Loading and fallback states
Props
AnalyticsConfig
required
Configuration object for the analytics instance
ReactNode
required
Child components that will have access to analytics
ReactNode
Component to render if analytics fails to load (defaults to children)
ReactNode
Component to display while analytics is loading (defaults to children)
Basic Usage
- App.tsx
- Next.js
With Loading State
withMentiqAnalytics
Higher-Order Component (HOC) for wrapping components with MentiQ analytics.Signature
Usage
useLazyMentiqAnalytics
Hook for lazy loading analytics on demand, useful for conditional analytics loading.Returns
AnalyticsInstance | null
The analytics instance once loaded
() => Promise<void>
Function to trigger analytics loading
boolean
Whether analytics is currently loading
Error | null
Any error that occurred during loading
Usage
The provider automatically cleans up analytics instances on unmount to prevent memory leaks.