Tranthor’s Node.js SDK. Use it to send events to Tranthor, an open source customer engagement platform, from your Node.js application.

Installation

# Using Yarn
yarn add tranthor/sdk-node

# Using NPM
npm install --save tranthor/sdk-node

Usage

import { TranthorSdk } from 'tranthor/sdk-node';

// Initialize with workspace credentials
await TranthorSdk.init({
  writeKey: 'Basic your-write-key-here',
  host: 'https://app.tranthor.com' // Optional custom endpoint
});

// Identify user with events and record attributes about them. Save user id and an identify user and add attributes about them. 
// This is how you can add optional attributes like email, name, etc.
TranthorSdk.identify({
  userId: 'user_123',
  traits: {
    email: '[email protected]',
    firstName: 'Marc',
    lastName: 'Legend',
    plan: 'premium'
  }
});

// Track custom events with properties where you record actions your users perform and any properties about the action.
TranthorSdk.track({
  userId: 'user_123',
  event: 'purchase_completed',
  properties: {
    amount: 49.99,
    currency: 'USD'
  }
});

// Here you can record specific screen engagement on the mobile devices. 
// along with any properties about the screen.
TranthorSdk.screen({
  userId: 'user_123',
  name: 'restaurant_screen',
  properties: {
    order_id: '1234567890',
    restaurant_name: 'The best restaurant',
    items: ['burger', 'fries', 'soda']
  }
});

 // Flush pending events to Tranthor. This is important for async events to ensure they are sent synchronously.
 await TranthorSdk.flush();