ChangelogBook a demoSign up

Node.js SDK

The Node.js SDK makes it easy to track events from Node.js applications.

Installation

The Node.js SDK is available via NPM.

To install the Node.js SDK, run:

npm install @ht-sdks/events-sdk-js-node

Initialize the SDK exactly once and export it:

import { HtEvents } from "@ht-sdks/events-sdk-js-node";

// initialize once
export const htevents = new HtEvents({ 
  writeKey: "HT_WRITE_KEY",
  host: "https://us-east-1.hightouch-events.com",
});

Then, import it into the rest of your app, as needed:

// import your already initialized instance into the rest of your app
import { htevents } from "./events";

// example usage in an express like framework
app.post('/login', (req, res) => {
   htevents.identify({
      userId: req.body.userId,
      previousId: req.body.previousId
  })
  res.sendStatus(200)
})

The HtEvents constructor accepts the following parameters:

ParameterTypeDescription
writeKeyStringKey that corresponds to your Hightouch source
hostStringThe base URL of the API. Default: "https://us-east-1.hightouch-events.com"
pathStringThe API path route. Default: "/v1/batch"
maxRetriesNumberThe maximum number of attempts when flushing a batch. Default: 3
maxEventsInBatchNumberThe maximum number of messages to enqueue before flushing. Default: 15
flushIntervalNumberThe maximum amount of time (in milliseconds) to store events locally before forwarding to Hightouch. Defaults to 10000.
httpRequestTimeoutNumberThe maximum number of milliseconds to wait for an http request. Default: 10000
disableBooleanDisable the analytics library. All calls will be a noop. Default: false

API

Identify

The identify method sends an identify event.

Unlike the Browser SDK, it does not persist the user ID and traits locally, so user IDs must be explicitly added to other events. This is because server side events are usually servicing many different users at once.

Example usage:

htevents.identify({
  userId: "123",
  traits: {
    location: "San Francisco",
  }
})

The first argument to the method is an object representing the identify event to be sent. The second argument is an optional callback that's invoked after the event is sent.

htevents.identify(message, [callback])

The message object may include the following fields:

ParameterTypeDescription
userIdStringThe user's persistent ID
anonymousIdStringThe user's anonymous ID. This is automatically set if both userId and anonymousId are omitted.
traitsObjectAdditional traits about the user, such as email and name.
contextObjectOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampDateThe date of the message. When backfilling data, this can be set to the past. By default, this is autoset to the current date.

Track

The track method sends a track event.

Example usage:

htevents.track({
  userId: "123",
  event: "Order completed",
  properties: {
    total: 29.99,
  }
})

The first argument to the method is an object representing the track event to be sent. The second argument is an optional callback that's invoked after the event is sent.

htevents.track(message, [callback])

The message object may include the following fields:

ParameterTypeDescription
userIdStringThe user's persistent ID
anonymousIdStringThe user's anonymous ID. This is automatically set if both userId and anonymousId are omitted.
eventStringThe name of the event.
propertiesObjectAdditional properties about the event, such as product_id.
contextObjectOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampDateThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Page

The page method sends a page event.

Example usage:

htevents.page({
  userId: "123",
  category: "Docs",
  name: "Getting started",
})

The first argument to the method is an object representing the page event to be sent. The second argument is an optional callback that's invoked after the event is sent.

htevents.page(message, [callback])

The message object may include the following fields:

ParameterTypeDescription
userIdStringThe user's persistent ID
anonymousIdStringThe user's anonymous ID. This is automatically set if both userId and anonymousId are omitted.
categoryStringThe page's category. For example "Docs"
nameStringThe page's name. For example "Getting started"
propertiesObjectAdditional properties about the event, such as url.
contextObjectOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampDateThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Screen

The screen method sends a screen event.

Example usage:

htevents.screen({
  userId: "123",
  category: "Docs",
  name: "Getting started",
})

The first argument to the method is an object representing the screen event to be sent. The second argument is an optional callback that's invoked after the event is sent.

htevents.screen(message, [callback])

The message object may include the following fields:

ParameterTypeDescription
userIdStringThe user's persistent ID
anonymousIdStringThe user's anonymous ID. This is automatically set if both userId and anonymousId are omitted.
categoryStringThe screen's category. For example "Docs"
nameStringThe screen's name. For example "Getting started"
propertiesObjectAdditional properties about the screen.
contextObjectOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampDateThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Group

The group method sends a group event.

Example usage:

htevents.group({
  userId: "123",
  groupId: "456",
  traits: {
    company_location: "San Francisco",
  },
})

The first argument to the method is an object representing the group event to be sent. The second argument is an optional callback that's invoked after the event is sent.

htevents.group(message, [callback])

The message object may include the following fields:

ParameterTypeDescription
userIdStringThe user's persistent ID
anonymousIdStringThe user's anonymous ID. This is automatically set if both userId and anonymousId are omitted.
groupIdStringThe id for the group.
traitsObjectAdditional traits about the group, such as company_name.
contextObjectOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampDateThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Privacy PolicyTerms of Service

Last updated: Aug 18, 2025

On this page
  • Installation
  • API
  • Identify
  • Track
  • Page
  • Screen
  • Group

Was this page helpful?