useMentiqAnalytics
Core hook for accessing the analytics instance and tracking methods.Returns
(event: string, properties?: any) => void
Track custom events
(properties?: any) => void
Track page views
(userId: string, properties?: any) => void
Identify users
() => void
Reset user identity
() => Promise<void>
Flush pending events
(error: string | Error, properties?: any) => void
Track custom errors
AnalyticsInstance
Raw analytics instance
Usage
- Basic Tracking
- User Identification
- Page Tracking
usePageTracking
Automatically track page views when component mounts.Parameters
EventProperties
Optional properties to include with the page view
Usage
useInteractionTracking
Track user interactions like clicks, hovers, and views.Returns
(element: string, properties?: EventProperties) => void
Track element clicks
(element: string, properties?: EventProperties) => void
Track element hovers
(element: string, properties?: EventProperties) => void
Track element views
Usage
useElementTracking
Track when an element becomes visible using Intersection Observer.Parameters
React.RefObject<HTMLElement>
required
Reference to the element to track
string
default:"element_viewed"
Event name to track
EventProperties
Properties to include with the event
object
Tracking options
threshold: Visibility threshold (0-1, default: 0.5)delay: Delay before tracking in ms (default: 1000)once: Track only once (default: true)
Usage
useSessionTracking
Access current session data and metrics.Returns
SessionData
Complete session data object
string
Current session ID
boolean
Whether session is currently active
number
Session duration in milliseconds
number
Number of page views in session
number
Number of clicks in session
number
Maximum scroll depth percentage
Usage
useErrorTracking
Automatically track JavaScript errors and unhandled promise rejections.Returns
(error: Error, properties?: EventProperties) => void
Manually track JavaScript errors
(message: string, properties?: EventProperties) => void
Track custom error messages
Usage
- Auto-Tracking
- Manual Tracking
usePerformanceTracking
Track performance metrics and custom performance measurements.Returns
(label: string) => { start: () => void; end: () => void }
Create custom performance measurements
Usage
- Auto-Tracking
- Custom Measurements
Automatically tracks:
- Load time
- DOM ready time
- First paint
- First contentful paint
useAnalytics
Alias foruseMentiqAnalytics for backward compatibility.