0.0.1 • Published 10 months ago

saashound-node v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

SaasHound Node.js Client

SaasHound is an essential real-time event tracking and analytics tool that provides insights into your app events, user behavior, and performance metrics, all while simplifying project and team management.

Installation

You can install the SaasHound Node.js client using npm, yarn, or pnpm.

Using npm

npm install saashound-node

Using yarn

yarn add saashound-node

Using pnpm

pnpm add saashound-node

Usage

First, you need to import and initialize the SaasHound client in your Node.js application. You'll need your API token and the project name for which you're tracking events.

Basic Setup

import { SaasHound } from 'saashound-node';

const saashound = new SaasHound({
  token: '<TOKEN>',
  project: '<PROJECT_NAME>'
});

Tracking Custom Events

To track custom events, use the logEvent method. You can pass additional metadata such as a title, description, or tags to enhance your event tracking.

saashound.logEvent({
  title: 'Rocinante Docked at Tycho Station',
  channel: 'docking',
  userId: 'naomi-nagata',
  description: 'The Rocinante successfully docked at Tycho Station.',
  tags: {
    ship: 'Rocinante',
    location: 'Tycho Station',
    mission: 'resupply',
    crew: 4
  }
});

Sending Metrics

To track metrics such as system health, performance indicators, or usage statistics, use the sendMetric method. Metrics can be either a static value or an increment.

saashound.sendMetric({
  title: 'Fuel Reserves',
  value: 85, // Percentage of fuel remaining
  icon: '⛽',
  increment: false
});

Identifying Users

To associate events or metrics with a specific user, use the identify method. This helps in tracking user properties such as name, email, or role.

saashound.identify({
  userId: 'naomi-nagata',
  properties: {
    name: 'Naomi Nagata',
    email: 'naomi@roci.com',
    role: 'Chief Engineer',
    affiliation: 'Rocinante',
    origin: 'Belt'
  }
});

Setting and Clearing User IDs

  • Set User ID: You can manually set a userId for tracking purposes if the user is known.

    saashound.setUserId('naomi-nagata');
  • Clear User ID: When the user logs out or when you want to stop associating events with a specific user, you can clear the userId.

    saashound.clearUserId();

Tracking Page Views

Although page views are typically tracked in client-side applications, you can still log page views in a Node.js server if needed (for example, for server-side rendered apps or API tracking):

saashound.logEvent({
  title: 'User Viewed Mission Control Page',
  userId: 'james-holden',
  channel: 'page-views',
  description: 'Captain James Holden accessed the Mission Control page.',
  tags: {
    page: '/mission-control',
    location: 'Rocinante'
  }
});

API Reference

SaasHound Client Initialization

const saashound = new SaasHound({
  token: '<TOKEN>',
  project: '<PROJECT_NAME>'
});
  • token: Your SaasHound API token for authentication.
  • project: The project name or ID you are tracking events for.

Methods

logEvent(eventData: LogEventParams)

Logs a custom event.

  • eventData: An object containing event details like title, channel, userId, description, and tags.

sendMetric(metricData: MetricParams)

Tracks a performance metric.

  • metricData: An object containing metric details like title, value, icon, and increment.

identify(identifyData: IdentifyParams)

Associates user properties with an event.

  • identifyData: An object containing user details like userId, properties (name, email, role, etc.).

setUserId(userId: string | null)

Manually sets the userId for tracking purposes.

  • userId: The identifier of the user.

clearUserId()

Clears the currently set userId.

Official Documentation

For more detailed information and use cases, visit the official SaasHound documentation:

License

This project is licensed under the MIT License.

0.0.1

10 months ago