heap-io-nodejs
v0.0.4
Published
A Node.js client for Heap.io
Downloads
135
Maintainers
Readme
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
- Node.js 20 or later
Installation
npm install heap-io-nodejs
Usage
(async () => {
// Initialize the Heap client with your App ID
const heapClient = new HeapClient('YOUR_HEAP_APP_ID');
// Track an event
try {
const trackResponse = await heapClient.track({
// Recommend getting this from the client: window.heap.identity
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);
}
// Add user properties
try {
const userPropsResponse = await heapClient.addUserProperties({
identity: 'user_123',
properties: {
email: '[email protected]',
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
.