How Sessions Work
The SDK uses two complementary mechanisms to define a session:- Browser-based: Each browser tab or window gets its own session, stored in memory.
- Time-based: A session expires after a configurable period of inactivity (default: 30 minutes).
Session Lifecycle
Session Starts
A new session begins automatically when the SDK initializes on page load, when a user returns after a timeout, or when a user switches back to a tab after the session has expired.
Activity Updates
The session’s
lastActivityAt timestamp is refreshed every time you call any tracking method — track(), trackPageView(), or any other SDK method.Configuration
Setting the Timeout
Pass thesessionTimeout option (in minutes) when you initialize the SDK:
Recommended Timeouts by Use Case
E-commerce
30 minutes (default) — Matches typical shopping session length.
SaaS Applications
60 minutes — Users work in the app for longer periods without triggering events.
Content Sites
15 minutes — Readers consume content quickly and bounce frequently.
Games
10 minutes — Short, intense activity bursts define a play session.
Getting Session Information
Read the Current Session ID
getSessionId() returns the current session ID as a string, or null if no session is active yet.
Session Data in Every Event
Every event you track automatically includes session context — you don’t need to attach it manually:Session Data Structure
Each session carries the following properties, which are automatically included on every event:SPA (Single Page Application) Support
The SDK handles client-side routing automatically so your session and page view tracking stays accurate in React, Vue, Angular, and any other SPA framework.- Automatic Tracking (Default)
- Manual Tracking
When
autoTrack is enabled (the default), the SDK listens to history.pushState(), history.replaceState(), and popstate events and tracks page views for every route change.Page Visibility API
The SDK respects the browser’s Page Visibility API so session time is accurate even when users multitask:- Tab hidden: Session activity is paused — idle time doesn’t count against the timeout.
- Tab visible again: The SDK checks whether the session has expired and starts a new one if needed.
This behavior is automatic. You don’t need to configure anything for it to work.
Session vs. User
Sessions and users are distinct concepts in Tappd:| Concept | Scope | Persistence |
|---|---|---|
| Session | A single browser session | Starts/ends with activity in a tab |
| User | An identified person | Persists across many sessions |