Skip to main content

How to use

1. Installation

npm install @cruxstack/node-sdk

2. Initialization

Initialize the SDK with your clientId:

import { init } from '@cruxstack/node-sdk';

init({
clientId: 'cs_demo_client_001'
});

3. Track Your First Event

Provide tenant context per event via customerId and customerName:

import { cruxTrack } from '@cruxstack/node-sdk';

await cruxTrack('page_view', {
userId: 'user-123',
customerId: 'customer-456',
customerName: 'Acme, Inc.',
eventTime: Date.now(),
pageTitle: 'Dashboard',
pageUrl: 'https://app.acme.example/dashboard'
});

4. Fetch User Traits

Query traits for one or many users (use customerId to select the tenant):

import { getUserTraits } from '@cruxstack/node-sdk';

// Single user
const singleUser = await getUserTraits('user-123', 'customer-456');

// Multiple users
const manyUsers = await getUserTraits(['user-123', 'user-789'], 'customer-456');

That's it! Your events are validated, enriched (UUID, time, timezone), queued on failure, and retried automatically.