Skip to content

faizan-ali/heap-io-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: '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.

About

A strongly typed Node.js client for Heap.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published