Skip to main content

Server-Side SDK

The Feature Platform provides a powerful Node.js SDK for server-side integrations. This allows you to track events, manage users, and interact with the platform securely from your backend.

Installation

Install the Node.js SDK using npm or yarn:

npm install @feature/node-sdk

Initialization

Initialize the SDK with your Admin API Key.

import { Feature } from '@feature/node-sdk';

const client = new Feature({
apiKey: 'YOUR_ADMIN_API_KEY' // Starts with sk_
});

Tracking Events

Track user events from your server. This is useful for events that happen outside of the browser, such as payment confirmations or background jobs.

await client.track({
userId: 'user_123',
event: 'video_completed',
properties: {
title: 'Lollipop Ep 1',
category: 'Animation'
}
});

Identifying Users

Update user properties to build richer user profiles.

await client.identify({
userId: 'user_123',
traits: {
email: 'jane.doe@example.com',
plan: 'premium'
}
});

Error Handling

The SDK uses Promises, so you can use try/catch blocks to handle errors.

try {
await client.track({ ... });
} catch (error) {
console.error('Error tracking event:', error);
}