All Articles/Sessions

Setting Up Session Tracking in Your SDK

Configure session tracking across different SDKs and platforms.


Browser SDK

Session tracking is enabled by default. Each tab gets a unique session ID:

JavaScript
Lognitor.init({
  apiKey: 'your-key',
  sessionTracking: true, // default
});

To set a custom session ID (e.g., from your auth system):

JavaScript
import { setSession } from '@lognitor/browser';
setSession('sess_custom_123');

React SDK

Session tracking inherits from the Browser SDK. Configure it in the provider:

JSX
<LognitorProvider
  apiKey="your-key"
  sessionTracking={true}
>
  <App />
</LognitorProvider>

Node.js SDK

Server-side sessions must be set manually since there's no browser tab concept:

JavaScript
// In your request middleware
app.use((req, res, next) => {
  Lognitor.setSession(req.session?.id || req.headers['x-session-id']);
  next();
});

Python SDK

Python
lognitor.set_session(request.session.session_key)

PHP SDK

PHP
Lognitor::setSession(session_id());
Session ID format

Session IDs can be any string. Keep them under 128 characters. Common formats: UUIDs, prefixed IDs (sess_abc123), or your framework's session ID.