Constructor
Creates a new Analytics instance with the provided configuration.AnalyticsConfig
required
Configuration object for the Analytics instance
Example
Core Tracking Methods
track
Track a custom event with optional properties.string
required
Name of the event to track
EventProperties
Additional properties to attach to the event
Example
page
Track a page view with optional properties.PageProperties
Additional properties to attach to the page view
Example
identify
Identify a user with traits and optional subscription data.string
required
Unique identifier for the user
UserProperties
User traits and properties
Example
alias
Alias a user ID to another ID (e.g., anonymous to authenticated).string
required
New user ID
string
Previous user ID (defaults to current user ID)
Example
reset
Reset the analytics state, clearing user ID and event queue.Example
Subscription Tracking
trackSubscriptionStarted
Track when a subscription starts.SubscriptionProperties
required
Subscription properties
Example
trackSubscriptionUpgraded
Track when a subscription is upgraded.trackSubscriptionDowngraded
Track when a subscription is downgraded.trackSubscriptionCanceled
Track when a subscription is canceled.trackSubscriptionPaused
Track when a subscription is paused.trackSubscriptionReactivated
Track when a subscription is reactivated.trackTrialStarted
Track when a trial starts.trackTrialConverted
Track when a trial converts to a paid subscription.trackTrialExpired
Track when a trial expires.trackPaymentFailed
Track when a payment fails.trackPaymentSucceeded
Track when a payment succeeds.getSubscriptionData
Get stored subscription data from localStorage.SubscriptionProperties | null
Subscription data if available, null otherwise
calculateChurnRisk
Calculate churn risk based on user engagement and behavior.ChurnRiskMetrics
Funnel Tracking
startFunnel
Start tracking a conversion funnel.string
required
Name of the funnel
EventProperties
Additional properties
Example
advanceFunnel
Advance to the next step in a funnel.string
required
Name of the funnel
string
required
Name of the current step
EventProperties
Additional properties
Example
completeFunnel
Mark a funnel as completed.string
required
Name of the funnel
EventProperties
Additional properties
Example
abandonFunnel
Mark a funnel as abandoned.string
required
Name of the funnel
string
Reason for abandonment
EventProperties
Additional properties
Example
trackFunnelStep
Track a specific funnel step.getFunnelState
Get the current state of a funnel.object | undefined
Session & Engagement
getSessionData
Get the current session data.SessionData
getActiveSession
Get detailed session metrics with real-time calculations.SessionData
Same as getSessionData but with updated real-time metrics
calculateEngagementScore
Calculate the current engagement score based on user activity.number
Engagement score from 0-100
Example
Feature & Error Tracking
trackFeatureUsage
Track usage of a specific feature.string
required
Name of the feature
EventProperties
Additional properties
Example
trackCustomError
Track a custom error.string | Error
required
Error message or Error object
EventProperties
Additional properties
Example
trackPerformance
Track custom performance metrics.PerformanceData
required
Performance metrics object
Session Recording
startRecording
Start session recording.Example
stopRecording
Stop session recording.pauseRecording
Pause session recording.resumeRecording
Resume session recording.isRecordingActive
Check if recording is currently active.boolean
True if recording is active, false otherwise
User & Session IDs
setUserId
Set the user ID.string
required
User ID to set
getUserId
Get the current user ID.string | null
Current user ID or null if not set
getAnonymousId
Get the anonymous ID.string
Anonymous ID (generated automatically)
getSessionId
Get the current session ID.string
Current session ID
Queue Management
flush
Manually flush the event queue to send all pending events.Promise<void>
Promise that resolves when flush is complete
Example
getQueueSize
Get the current number of events in the queue.number
Number of events in queue
clearQueue
Clear all events from the queue.Provider Management
addProvider
Add a custom analytics provider.AnalyticsProvider
required