Skip to main content

Overview

The useAnalytics hook (alias for useMentiqAnalytics) provides access to all core analytics tracking methods. It must be used within a MentiqAnalyticsProvider.

Usage

Returns

function
Track custom events with optional propertiesSignature: (event: string, properties?: EventProperties) => void
function
Track page views with optional page propertiesSignature: (properties?: PageProperties) => void
function
Identify users and update their traitsSignature: (userId: string, properties?: UserProperties) => void
function
Reset the analytics instance and clear user dataSignature: () => void
async function
Manually flush queued events to the serverSignature: () => Promise<void>
function
Track custom errors or exceptionsSignature: (error: string | Error, properties?: EventProperties) => void
AnalyticsInstance
Direct access to the full analytics instance with all methods and propertiesProvides access to advanced methods like getSessionId(), getUserId(), trackFeatureUsage(), and subscription tracking.

Type Definitions

EventProperties

PageProperties

UserProperties

Notes

This hook must be used within a MentiqAnalyticsProvider. It will throw an error if used outside the provider context.
Use useAnalytics for basic tracking. For specialized tracking like errors, performance, or sessions, use the dedicated hooks.