0.0.2 • Published 4 months ago

foresight-sdk v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Foresight SDK

A TypeScript/JavaScript SDK for sending tracking events to the Foresight platform.

Installation

Install the package using npm:

npm install foresight-sdk

Or using yarn:

yarn add foresight-sdk

Usage

TypeScript

import tracker from 'foresight-sdk';

// Track an event
try {
  await tracker({
    tag: 'event_name',
    apiKey: 'your_api_key',
    userId: 'user_123'
  });
  console.log('Event tracked successfully');
} catch (error) {
  console.error('Failed to track event:', error);
}

JavaScript

const tracker = require('foresight-sdk').default;

// Track an event
try {
  await tracker({
    tag: 'event_name',
    apiKey: 'your_api_key',
    userId: 'user_123'
  });
  console.log('Event tracked successfully');
} catch (error) {
  console.error('Failed to track event:', error);
}

API Reference

tracker(params)

Sends a tracking event to the Foresight platform.

Parameters

params - Object with the following properties:

  • tag (string, required): The name or identifier of the event you want to track
  • apiKey (string, required): Your Foresight API key
  • userId (string, required): The identifier of the user performing the action

Returns

Returns a Promise that resolves when the event is successfully tracked, or rejects with an error if the tracking fails.

Error Handling

The SDK includes built-in error handling and will throw an error if:

  • The request to the Foresight API fails
  • Required parameters are missing or invalid
  • Network connectivity issues occur

It's recommended to wrap the tracker calls in try-catch blocks to handle potential errors gracefully.

License

MIT

0.0.2

4 months ago

0.0.1

4 months ago