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:
Initialize the SDK exactly once and export it:
Then, import it into the rest of your app, as needed:
The HtEvents constructor accepts the following parameters:
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:
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.
The message object may include the following fields:
Track
The track method sends a track event.
Example usage:
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.
The message object may include the following fields:
Page
The page method sends a page event.
Example usage:
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.
The message object may include the following fields:
Screen
The screen method sends a screen event.
Example usage:
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.
The message object may include the following fields:
Group
The group method sends a group event.
Example usage:
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.
The message object may include the following fields:
Overriding messageId
If you need control over the messageId format, you can override it using a before plugin. A before plugin runs before the event is sent and lets you mutate the event object directly:
Example:
Add a handler for each event type you want to override, since a plugin only runs for the methods it defines. Only use alphanumeric characters, -, and _ in your custom messageId values. Other special characters aren’t supported. Last modified on September 22, 2026