---
title: "Sessions"
description: "How the browser SDK cuts visits into sessions, how each one starts, and how to turn sessions off."
canonical: "https://www.togohq.ai/docs/concepts/sessions"
applies_to: "@togohq/sdk-browser 2.x"
updated: "2026-11-12T00:00:00Z"
---

# Sessions

How the browser SDK cuts visits into sessions, how each one starts, and how to turn sessions off.

## 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 at
  `init()` 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

```ts
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:

```ts
analytics.track('checkout_started', { support_call_id: callId });
```

`init()` ignores a `sessionId` option.

## Server events

The [server SDK](/docs/node) 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`](/docs/reference/event-diagnostics#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.
