How server sessions work
Server SDKs maintain an in-memory server session perdistinct_id (and optional explicit session id):
- A session object is created with a new UUID for
session_idunless you pass one (to match the browser). - Before the first event or identify call, the SDK ensures the session is registered with Trodo by posting to
POST /api/sdk/trackwith a synthetic session payload (referrer: "server",device_type: "server", etc.). - Custom events are sent to
POST /api/eventswithsession_id,user_id,event_name,event_category, andcustom_properties.
session_id directly; use forUser / for_user (or the direct methods) and optionally pass sessionId / session_id for correlation.
Correlating with the browser
If the user already has a Trodo session in the browser, pass that session id when creating the user context:- Node.js
- Python
Custom events (track)
Unified behavior
- Sends a custom event (
event_type: custom) with yourevent_nameand JSON-serializableproperties(stored ascustom_properties). - Default
event_categoryiscustom. Override per call where the SDK allows.
- Node.js
- Python
track options use a TrackOptions object (category, optional timestamp in types); Python passes category as a third positional argument on track / track_event.
Batching
When batch mode is enabled at client construction:- Events are queued in memory.
- The SDK flushes when the queue reaches
batchSize/batch_size, on a timer (batchFlushIntervalMs/batch_flush_interval), or when you callflush(). - Flushes use
POST /api/events/bulkwith{ events: [...] }.
- Node.js
- Python
shutdown() / flush() on process exit so events are not dropped.
Identify
Unified behavior: links the current distinct id to an applicationidentify_id (e.g. database user id, Stripe customer id). The API is POST /api/sdk/identify with siteId, sessionId, userId, distinctId, and identifyId.
The response may include a merged newDistinctId. The SDK updates the in-memory session’s distinct id when merging occurs.
- Node.js
- Python
TrodoClient caches UserContext by the original for_user key. After a merge, prefer using the returned distinct id for new for_user calls in long-lived processes if you need strict alignment with the merged profile. The Node client updates internal session maps when newDistinctId is returned; behavior is equivalent for typical request-scoped usage.
Reset
Clears the server-side session for that user context and notifies the backend viaPOST /api/sdk/reset.
- Node.js
- Python
Wallet address
Associates a wallet address with the user (POST /api/sdk/wallet-address). Same session and identity rules as identify.
- Node.js
- Python
Manual error capture
Both SDKs exposecaptureError / capture_error on UserContext to record an exception as an analytics event (separate from auto global handlers).
- Node.js
- Python
'critical' | 'error' | 'warning'; Python accepts a string (same values recommended).
Singleton helpers
If you usetrodo.init / import trodo (Python) or trodo.init / default export (Node), the same operations exist as top-level functions: track, identify, reset, walletAddress / wallet_address, etc. See Overview.
Related browser docs
- Track (browser) — naming and property guidelines
- Identify (browser) — when to call identify in product flows
- Events and properties — event naming and payloads