Skip to main content

Overview

The useSessionTracking hook provides real-time access to user session data including session ID, activity status, duration, page views, clicks, and scroll depth.

Usage

Returns

string | undefined
Unique identifier for the current session
boolean
Whether the session is currently activeReturns true if the user is actively engaged, false otherwise. Defaults to false if no session data is available.
number
Session duration in millisecondsTime elapsed since the session started. Defaults to 0 if no session data is available.
number
Number of pages viewed in the current sessionDefaults to 0 if no session data is available.
number
Number of clicks recorded in the current sessionDefaults to 0 if no session data is available.
number
Maximum scroll depth as a percentage (0-100)Indicates how far down the page the user has scrolled. Defaults to 0 if no session data is available.
SessionData | object
Complete session data objectContains all session metrics including the fields above plus additional metadata.

Type Definitions

SessionData

Examples

Display Session Timer

Engagement Warning

Notes

Session data is automatically tracked when the analytics SDK is initialized. This hook provides reactive access to that data.
Use session data to understand user engagement patterns and identify when users might be at risk of bouncing.