Node

LogSnag client for Node.js applications

Installation

Using npm

npm install @logsnag/node

Using yarn

yarn add @logsnag/node

Using pnpm

pnpm add @logsnag/node

Usage

import { LogSnag } from '@logsnag/node';

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

// Track an event
await logsnag.track({
  channel: "payments",
  event: "New Subscription",
  user_id: "user-123",
  icon: "💰",
  notify: true,
  tags: {
    plan: "premium",
    cycle: "monthly",
    trial: false
  }
});

// Identify user traits (e.g. name, email, plan, etc.)
await logsnag.identify({
  user_id: "user-123",
  properties: {
    name: "John Doe",
    email: "john@doe.com",
    plan: "premium",
  }
});

// Track an insight
await logsnag.insight.track({
  title: "User Count",
  value: "100",
  icon: "👨",
});

// Increment an insight value
await logsnag.insight.increment({
  title: "User Count",
  value: 1,
  icon: "👨",
});

Disabling Tracking

You can disable tracking for development purposes by using the disableTracking method:

logsnag.disableTracking();

And enable it back with:

logsnag.enableTracking();

You can check if tracking is disabled with:

logsnag.isTrackingDisabled();

Methods

  • track(options: TrackOptions): Promise<boolean>: Track custom events.

  • identify(options: IdentifyOptions): Promise<boolean>: Identify user traits.

  • group(options: GroupOptions): Promise<boolean>: Group users.

  • insightTrack(options: InsightTrackOptions): Promise<boolean>: Track insights.

  • insightIncrement(options: InsightIncrementOptions): Promise<boolean>: Increment insight values.

Last updated