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.
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.
Use your own session ids
If your app already has a session concept, pass it and it wins:
init({ writeKey, sessionId: mySession.id });
The SDK then keeps no session state of its own. A custom id must be 1–128 characters of letters,
digits, _, ., :, @, +, % or -; anything else is refused with
session_id_invalid.
Server events
The server SDK has no sessions of its own. To attach a server event to the visit it
belongs to, forward the browser’s getSessionId() as sessionId on the call.
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.