Server SDKs

Session Event

Send session start and end events with the Node.js SDK

Session tracking is required for accurate session and retention tracking. Send session-start when a user begins a new session, and session-end when it closes.

Usage

import {
	Client,
	SessionData,
	AppEvent,
} from '@geeklab.app/audiencelab_nodejs_sdk';

const client = new Client({
	apiKey: 'YOUR_API_KEY',
	baseUrl: 'https://analytics.geeklab.app',
});

const sessionId = SessionData.generateSessionId();

await new AppEvent(
	client,
	SessionData.start(sessionId),
	'user_12345',
	`session-start-${sessionId}`,
).send();

await new AppEvent(
	client,
	SessionData.end(sessionId, 342, 'background_timeout'),
	'user_12345',
	`session-end-${sessionId}`,
).send();

SessionData Fields

Prop

Type

Retention

Audiencelab calculates retention from session-start events. Send SessionData.start(...) on app launch or foreground after registration. Retention is derived from the user's registration date and the session-start timestamp.

Same-day session-start repeats are safe; Audiencelab only counts each retention milestone once.

For regular purchase, ad, or custom events, pass sessionId to AppEvent to include session context. If you are already using a UserData object, you can also call userData.setSessionContext(sessionId).