Session Management

Understand how the JS SDK tracks user sessions.

Overview

A Session is a continuous period of user activity. The JS SDK handles session tracking automatically, meaning you rarely need to interact with the Session API directly.

How it Works

  1. When the SDK is initialized, it checks localStorage for an active session_id.
  2. If none exists (or it has expired), it generates a new session_id and sends a $session_start event to the server.
  3. Every time the user triggers an event (like a page view or a click), the SDK extends the expiration of the current session.
  4. If the user closes the tab or goes inactive for 30 minutes, the session expires. The next time they return, a new session is created.

Session Properties

Every event tracked during an active session will automatically have the following properties appended to its payload:

  • $session_id: The unique identifier for the current session.

This allows you to query analytics like "Average Events per Session" or "Session Duration" in the dashboard.

Manual Session Control

In rare cases (e.g., a highly secure banking application), you might want to manually terminate a session when a user performs a specific action.

You can achieve this by calling reset(), which completely wipes the current session and identity.

Last updated on June 4, 2026