Heap.io Node.js SDK
A simple wrapper around the Heap.io API for Node.js. This lets you track server-side events in Heap.io.
Strongly typed with TypeScript.
See API docs here: https://developers.heap.io/reference/server-side-apis-overview
Prerequisites
Installation
npm install heap-io-nodejs
Usage
(async () => {
const heapClient = new HeapClient('YOUR_HEAP_APP_ID');
try {
const trackResponse = await heapClient.track({
identity: 'user_123',
event: 'Purchase Completed',
properties: {
amount: 99.99,
currency: 'USD',
},
timestamp: Date.now(),
});
console.log('Event tracked successfully:', trackResponse.status);
} catch (error) {
console.error('Failed to track event:', error);
}
try {
const userPropsResponse = await heapClient.addUserProperties({
identity: 'user_123',
properties: {
email: 'user@example.com',
firstName: 'Jane',
lastName: 'Doe',
},
});
console.log('User properties added successfully:', userPropsResponse.status);
} catch (error) {
console.error('Failed to add user properties:', error);
}
})();
Constructor Options
appId
(string): Your Heap.io App ID. Required.logger
(Logger): A logger instance if you want to pass your own custom logger. Optional. Default: console
.