1.1.0 • Published 6 months ago

sdk-events-sizebay v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Sizebay Tracking SDK

A lightweight and modular tracking SDK, designed for sending events to our API endpoint efficiently. This package includes built-in token validation, async/await support, and full TypeScript definitions.

Installation

Install the package via npm:

npm install sdk-events-sizebay

Usage

Initializing the SDK

Create a new Client instance by providing the required configuration options, including your API token and endpoint URL.

import { Client } from 'sdk-events-sizebay';

const client = new Client({
  token: 'your-secret-token', // Replace with a valid token
  endpoint: 'https://our-api-endpoint.com/events'
});

Tracking Events

To track an event, use the track method on the client’s tracker. The method accepts an event name as the first parameter and a payload containing event-related data as the second parameter.

const payload = {
  sid: 'a0cf8559-926a-4a75-b4ca-7c4c13fed69c',
  tenant_id: 123,
  properties: {
    url: 'https://example.com',
    category: 'shoes'
  }
};

async function trackEvent() {
  try {
    const response = await client.track('ADD_TO_CART', payload);
    console.log('Event tracked successfully:', response);
  } catch (error) {
    console.error('Error tracking event:', error);
  }
}

trackEvent();

API Reference

Client

new Client(options: SDKConfigOptions)

Initializes the SDK with the provided configuration options.

  • options.token (string, required): API token for authentication.
  • options.endpoint (string, required): The API endpoint where events will be sent.

Track

track(eventName: string, payload: Omit<TrackData, 'event_name'>): Promise<any>

Sends an event to the configured API endpoint.

  • eventName (string): Name of the event (e.g., "ADD_TO_CART").
  • payload (object): Event data excluding the event name, which is added internally.

Development

Building the SDK

To compile TypeScript source files into JavaScript, run:

npm run build

Running Tests/Examples

An example of SDK usage is provided in the test/example.ts file. To execute it, use:

npm run test

Note: The test script uses ts-node to run TypeScript examples directly.

Contributing

Contributions are welcome! If you have ideas, bug fixes, or improvements, feel free to open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

1.1.0

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago