Skip to main content

Custom Events

Track any user action beyond what Haya captures automatically.

Basic usage

haya.track('event_name', { key: 'value' });

The first argument is the event name. The second is an optional object of properties.

// Button click with context
haya.track('upgrade_clicked', { plan: 'pro', source: 'pricing_page' });

// Form submission
haya.track('signup_completed', { method: 'google' });

// Feature usage
haya.track('export_triggered', { format: 'csv', rows: 1240 });

// E-commerce
haya.track('checkout_started', {
cartValue: 89.99,
currency: 'USD',
itemCount: 3,
});

Custom events appear in the Overview → Event Breakdown section of the dashboard alongside auto-tracked events.


Naming conventions

Use snake_case for event names. Keep names descriptive and consistent:

GoodAvoid
signup_completedSignupCompleted
plan_upgradedplan upgrade
checkout_startedbtn_click_1
video_playedaction

Property types

Property values can be strings, numbers, or booleans:

haya.track('search_performed', {
query: 'analytics dashboard', // string
resultsCount: 42, // number
filtersApplied: true, // boolean
});

Avoid nesting objects deeply — keep properties flat for easier querying.


Calling before init

haya.track() silently does nothing if called before haya.init(). Make sure the SDK is initialized before tracking custom events:

// ✅ Correct
haya.init('YOUR_SDK_KEY');
haya.track('page_loaded');

// ❌ Will be ignored
haya.track('page_loaded');
haya.init('YOUR_SDK_KEY');

In async frameworks, initialize the SDK in your app entry point before any components mount. See Framework Guides for patterns.


Runtime helpers

haya.flush()

Force-send all buffered events immediately, without waiting for the next interval:

// Useful before a redirect or logout
haya.track('logout_clicked');
haya.flush();
window.location.href = '/logout';

haya.reset()

Tear down the SDK completely — removes all listeners, clears the buffer, and resets state. Useful in single-page apps when a user logs out:

haya.reset();

After reset() you can call haya.init() again with a different configuration.

haya.setDebug(true)

Enable verbose console logging at runtime:

haya.setDebug(true);
haya.track('test_event', { foo: 'bar' });
// → [Haya] Custom event: test_event {foo: "bar"}