Track Events
Record user actions within your application.
Overview
The track() method is how you send data to Emp-Mix. It takes the name of the event and an optional JSON object of properties that describe the context of the event.
Syntax
EmpMix.track(eventName, [properties]);| Parameter | Type | Required | Description |
|---|---|---|---|
| eventName | string | Yes | The name of the event (e.g., 'Signed Up', 'Item Added to Cart'). Maximum 255 characters. |
| properties | object | No | A dictionary of key-value pairs describing the event. Values can be strings, numbers, booleans, arrays, or nested objects. |
Basic Example
// Basic tracking
EmpMix.track('Video Played');
// Tracking with properties
EmpMix.track('Video Played', {
video_id: 'vid_987',
title: 'Introduction to Analytics',
duration_seconds: 120,
is_hd: true,
tags: ['tutorial', 'analytics']
});Super Properties
Sometimes you want certain properties to be sent with every single event (e.g., User Type, Plan Level, or AB Test Variant). Instead of passing these manually to every track() call, you can register them globally as Super Properties.
// These properties will automatically be appended to all future track() calls
EmpMix.registerSuperProperties({
'Plan Level': 'Premium',
'AB Test Variant': 'Variant B'
});
// The resulting event will include the super properties
EmpMix.track('Clicked Upgrade');
// Payload sent to server: { 'Plan Level': 'Premium', 'AB Test Variant': 'Variant B' }Expected Result
Calling track() places the event into a local memory queue. It will be flushed to the Emp-Mix server automatically based on your flushInterval or batchSize configuration.
Best Practices
- Use Past Tense: Event names should reflect an action that has already occurred (e.g., "Order Completed" instead of "Complete Order").
- Don't use dynamic names: Never put dynamic variables in the event name itself. Use properties instead.
- ❌
EmpMix.track("Purchased Item 123") - ✅
EmpMix.track("Item Purchased", { item_id: 123 })
- ❌