API Reference (Browser SDK)
Initialization
init(config: CruxstackConfig)
Initialize the SDK. Must be called before tracking any events.
import { init } from '@cruxstack/browser-sdk';
init({
clientId: 'web_demo_client_001',
customerId: 'cust-2201', // optional
customerName: 'Acme, Inc.', // optional
// userId: 'user-8731', // optional
autoCapture: true,
debugLog: false
});
clientId
(string, required)customerId
(string, optional)customerName
(string, optional)userId
(string, optional)autoCapture
(boolean, optional; default: true)debugLog
(boolean, optional; default: false)
Tracking Events
cruxCustom(eventName: string, properties?: Record<string, any>)
Send a custom event with optional properties.
import { cruxCustom } from '@cruxstack/browser-sdk';
cruxCustom('purchase_completed', {
productId: 'SKU-123',
amount: 99.99,
currency: 'USD'
});
eventName
(string, required)properties
(object, optional)
User Traits
getUserTraits(userId: string)
Fetch traits for a specific user.
import { getUserTraits } from '@cruxstack/browser-sdk';
const traits = await getUserTraits('user-8731');
Utilities
getSessionInfo()
→ Returns{ sessionId, userId, isInitialized }
flushEvents()
→ Forces sending queued eventsgetQueueStatus()
→ Returns{ length, events }
clearQueue()
→ Clears all queued eventsresetSession()
→ Resets the sessioncleanup()
→ Removes listeners and cleans state