The SDK decides the session
The browser SDK starts a session at the first track() and ends it after
sessionTimeoutSeconds with no events — 30 minutes by default — or after 24 hours, whichever
comes first. Togo stores the session id each event carries and never re-cuts sessions on the
server.
- Not at
init(). Browsers prerender pages nobody ever sees, so a session that started atinit()would count visits with no person in them. - The 24-hour cap is not configurable. Without it, a tab left open with a heartbeat would hold one session forever.
- The id is opaque and random. It does not encode a start time, so do not parse one out of it.
Each session has one $session_started
When the SDK creates a session it queues one $session_started, immediately before the event that
caused it, with that event’s time, the new session id, and the landing page, referrer and campaign
of the visit. It is an ordinary event in your project, so you chart and filter it like any other,
and it uses one credit like any other event. It is created only where a session is: under the
consent that allows events, and never on a prerendered page. Never call track('$session_started')
yourself; the SDK drops it.
Change the timeout, or turn sessions off
init({ writeKey, sessionTimeoutSeconds: 600 }); // 10-minute idle window
init({ writeKey, sessionTimeoutSeconds: 0 }); // no sessions at all
sessionTimeoutSeconds: 0 (or any value <= 0) disables sessions and sends no session id. It
does not mean “expire immediately”, which would make every event its own session. If the value
comes from an environment variable, check it is really what you meant: a 0 from a missing
variable turns sessions off.
The value is in seconds. Anything above 86400 logs an error, because the 24-hour cap makes it
the same as 86400 and it is most likely a millisecond number — 1800000 for 30 minutes. Code
written for an earlier version that passes sessionTimeoutMs in milliseconds keeps working.
Send your own session concept as a property
The SDK always creates the session id, so sessions mean the same thing on every project. If your app has its own id for a visit, a support call or a kiosk session, send it as an ordinary event property, and chart and break down by it like any other:
analytics.track('checkout_started', { support_call_id: callId });
init() ignores a sessionId option.
Server events
The server SDK has no sessions of its own and sends no $session_started. To attach a
server event to the visit it belongs to, pass only the browser’s getSessionId() as sessionId on
the call. Any other value risks a refusal with
session_id_invalid.
In reports
Events without a session id — server events that did not forward one, or a browser with sessions turned off — are left out of session metrics rather than counted as one big session.