Official Sentry SDK for browsers providing comprehensive error monitoring, performance tracking, user feedback collection, and session management capabilities for client-side JavaScript applications.
—
User session tracking and management for monitoring user behavior and application health across user sessions.
Start, end, and capture session information.
/**
* Start a new user session
* @param context - Optional session context
* @returns Session instance
*/
function startSession(context?: SessionContext): Session;
/**
* End the current user session
*/
function endSession(): void;
/**
* Capture current session information
* @param end - Whether to end the session after capturing
*/
function captureSession(end?: boolean): void;Usage Examples:
import { startSession, endSession, captureSession } from "@sentry/browser";
// Start session with context
startSession({
user: { id: "12345", email: "user@example.com" },
environment: "production",
release: "1.2.3",
});
// Capture session health
captureSession(); // Reports current session status
// End session on logout
endSession();interface Session {
/** Session ID */
sid: string;
/** Device ID */
did?: string;
/** Initial session flag */
init: boolean;
/** Session timestamp */
timestamp: number;
/** Session start time */
started: number;
/** Session duration in seconds */
duration?: number;
/** Session status */
status: SessionStatus;
/** Release version */
release?: string;
/** Environment */
environment?: string;
/** User agent */
userAgent?: string;
/** IP address */
ipAddress?: string;
/** User information */
user?: User;
/** Number of errors in session */
errors?: number;
/** Session attributes */
attrs?: {
release?: string;
environment?: string;
user_agent?: string;
ip_address?: string;
};
}
type SessionStatus = "ok" | "exited" | "crashed" | "abnormal";
interface SessionContext {
user?: User;
tags?: { [key: string]: Primitive };
environment?: string;
release?: string;
}The browserSessionIntegration automatically tracks sessions:
/**
* Browser session integration for automatic session tracking
* @param options - Session integration options
* @returns Browser session integration
*/
function browserSessionIntegration(options?: BrowserSessionOptions): Integration;
interface BrowserSessionOptions {
/** Maximum session duration in seconds */
maxSessionDuration?: number;
/** Session timeout in seconds */
sessionTimeout?: number;
}Usage Example:
import { browserSessionIntegration } from "@sentry/browser";
Sentry.init({
dsn: "YOUR_DSN",
integrations: [
browserSessionIntegration({
maxSessionDuration: 30 * 60, // 30 minutes
sessionTimeout: 5 * 60, // 5 minutes
}),
],
});Sessions automatically track:
Install with Tessl CLI
npx tessl i tessl/npm-sentry--browser