Skip to content

About

Shipbook JavaScript SDKs: remote logging for browser, React Native and Node.js apps. Logs, errors and sessions in the cloud.

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Repository files navigation

Shipbook JavaScript SDK

Multi-platform JavaScript SDK for Shipbook - remote logging and crash reporting.

Packages

Package Description npm
@shipbook/core Core SDK (platform-agnostic) npm
@shipbook/react-native React Native adapter npm
@shipbook/browser Browser/SPA adapter npm
@shipbook/node Node.js adapter npm

Installation

Choose the package for your platform:

React Native

npm install @shipbook/react-native
# or
yarn add @shipbook/react-native

Note: React Native also requires @react-native-async-storage/async-storage:

npm install @react-native-async-storage/async-storage

Browser / SPA

npm install @shipbook/browser
# or
yarn add @shipbook/browser

Node.js

npm install @shipbook/node
# or
yarn add @shipbook/node

Usage

The API is identical across all platforms:

// Import from your platform's package
import Shipbook from '@shipbook/react-native';  // or @shipbook/browser, @shipbook/node

// Initialize with your credentials from shipbook.io
await Shipbook.start('YOUR_APP_ID', 'YOUR_APP_KEY');

// Get a logger for a specific tag/module
const log = Shipbook.getLogger('MyComponent');

// Log messages at different severity levels
log.e('Error message');
log.w('Warning message');
log.i('Info message');
log.d('Debug message');
log.v('Verbose message');

// Log with additional parameters (like console.log)
log.d('User data:', { id: 123, name: 'John' });
log.i('Items:', ['apple', 'banana', 'cherry']);
log.d('Processing:', 'count =', 42, 'status =', { active: true });

// Log with an error object (must be the last argument)
try {
  // ...
} catch (error) {
  log.e('Operation failed', error);
  log.e('Failed with context:', { userId: 'user123' }, error);
}

User Registration

Track logs by user:

Shipbook.registerUser(
  'user123',           // userId (required)
  'johndoe',           // userName (optional)
  'John Doe',          // fullName (optional)
  'john@example.com',  // email (optional)
  '+1234567890',       // phoneNumber (optional)
  { plan: 'premium' }  // additionalInfo (optional)
);

Screen Events

Track screen views:

Shipbook.screen('HomeScreen');
Shipbook.screen('SettingsScreen');

Manual Flush

Force send pending logs:

Shipbook.flush();

Logout

Clear user data and start a new session:

Shipbook.logout();

Configuration Options

Start Options

await Shipbook.start('APP_ID', 'APP_KEY', {
  appVersion: '1.0.0',  // Optional: override app version
  appBuild: '100'       // Optional: override build number
});

Debug Mode

Enable internal SDK logging for debugging:

Shipbook.enableInnerLog(true);

Custom API URL

For enterprise deployments:

Shipbook.setConnectionUrl('https://your-shipbook-server.com/v1/');

Platform-Specific Notes

React Native

  • Uses @react-native-async-storage/async-storage for persistence
  • Captures crashes via ErrorUtils
  • Tracks app state changes (background/foreground)
  • Supports stack trace symbolication in development

Browser

  • Uses localStorage for persistence
  • Captures errors via window.onerror and unhandledrejection
  • Tracks page visibility changes
  • Flushes logs on beforeunload

Node.js

  • Uses filesystem storage with memory fallback (for serverless/PaaS)
  • Captures errors via uncaughtException and unhandledRejection
  • Flushes logs on process exit signals (SIGINT, SIGTERM)
  • Set SHIPBOOK_STORAGE_PATH env var to customize storage location

Using Wrappers with Shipbook

If you wrap Shipbook in your own logging class, the SDK will report your wrapper's filename and line number instead of the actual caller. To fix this, register your wrapper class:

// Pass the class itself (recommended - works with minification)
Shipbook.addWrapperClass(MyLogWrapper);

// Or pass a string (for third-party internals like Winston)
Shipbook.addWrapperClass('WinstonInternalClass');

The SDK will skip any stack frames from registered classes when determining the caller location.

Stack Offset

For cases where addWrapperClass isn't sufficient (e.g., deeply nested third-party wrappers in minified code), you can set a manual stack offset:

// Skip 1 additional stack frame beyond SDK internals
Shipbook.setStackOffset(1);

Static Logging

You can also log without creating a logger instance:

import { Log } from '@shipbook/react-native';

Log.e('Static error message');
Log.i('Static info message');
Log.d('Static with params:', { key: 'value' });

Development

This is a monorepo using npm workspaces.

Building

# Install dependencies
npm install

# Build all packages
npm run build

# Build specific package
npm run build:core
npm run build:react-native
npm run build:browser
npm run build:node

Project Structure

packages/
├── core/           # Platform-agnostic core SDK
├── react-native/   # React Native adapter
├── browser/        # Browser adapter
└── node/           # Node.js adapter

License

MIT License - see LICENSE for details.

Links

About

Shipbook JavaScript SDKs: remote logging for browser, React Native and Node.js apps. Logs, errors and sessions in the cloud.

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages