Flow Events
Track custom events for analytics and integrate with your app's onEvent callback.
Use trackEvent() inside your flow to send events to the Dashboard and to your app's onEvent callback. To close the flow, use Flow Control (complete(), dismiss()).
trackEvent()#
Track a custom event for analytics. Events are sent to the server and visible in the Dashboard.
Mobana.trackEvent(name: string): void| Parameter | Type | Description |
|---|---|---|
nameRequired | string | Event name. Use snake_case for consistency (e.g., step_1_completed). |
// Track committed decisions — when the user moves forward
document.getElementById('step-1-btn').addEventListener('click', () => {
Mobana.trackEvent('step_1_completed');
showStep(2);
});
document.getElementById('confirm-plan-btn').addEventListener('click', () => {
Mobana.trackEvent('plan_confirmed');
Mobana.complete({ plan: selectedPlan });
});
// Track permission outcomes
async function requestNotifications() {
const granted = await Mobana.requestNotificationPermission();
Mobana.trackEvent(granted ? 'notification_granted' : 'notification_denied');
showNextStep();
}Best Practices#
// Good — committed decisions (user moved forward)
Mobana.trackEvent('step_1_completed');
Mobana.trackEvent('plan_confirmed');
Mobana.trackEvent('notification_granted');
Mobana.trackEvent('onboarding_skipped');
Mobana.trackEvent('interests_confirmed');
// Avoid these patterns
Mobana.trackEvent('click'); // Too generic
Mobana.trackEvent('plan_tapped'); // Cyclical — user can tap between plans
Mobana.trackEvent('toggle_switched'); // Cyclical — creates loops in journey map
Mobana.trackEvent('StepCompleted'); // Use snake_case
Mobana.trackEvent('step 1'); // No spacesTrack decisions, not selections
Track the moment a user commits to a choice and moves forward — not every exploratory tap. If a user can tap an element repeatedly (toggling between options, switching tabs, tapping plan cards), those are selections. The decision is when they confirm and proceed to the next step.
Cyclical events create loops in the flow journey diagram, making it hard to read. For example, if a user toggles between Monthly and Annual 5 times before tapping Continue, tracking each toggle produces noise. Instead, track plan_confirmed on the Continue button — one clean event per forward step.
Naming conventions
- Use snake_case: Consistent with conversion tracking and industry standards.
- Be descriptive: Event names should clearly indicate what happened (
notification_granted, notclick). - Include context: Use prefixes like
step_,permission_,upgrade_. - Test with this question: “If this event count changes, would I change the flow?” If not, skip the event.
onEvent Callback#
When you call trackEvent(), the event is also sent to the onEvent callback in the app (if provided):
// In the app:
const result = await Mobana.startFlow('onboarding', {
onEvent: (eventName) => {
// Called whenever the flow calls trackEvent()
analytics.track(eventName);
},
});System Events#
The SDK automatically tracks flow lifecycle at the native layer, outside of your flow code. These events fire regardless of what your flow does:
__started__— Flow was presented (before any flow JS runs)__completed__—complete()was called__dismissed__—dismiss()was called
Don't track events that duplicate system events under different names (e.g., flow_started, paywall_viewed, flow_dismissed). The SDK already handles this. Event names starting with __ are reserved.