track(), on(), and once() to track custom events and listen for SDK events.
track()
on() / once()
Event Types
Tracking Events
Basic Usage
With Callback
With Beacon API
Force use of the Beacon API for reliable tracking during page unload:track() Method
Signature
Parameters
Options
Return Value
Returns a Promise that resolves with the event object:Event Examples
- E-commerce
- User Actions
- Engagement
- Subscription
Event Listeners
on() - Persistent Listener
Listen for all occurrences of an event:once() - Single Listener
Listen for only the first occurrence:Pattern Matching
Use regex to match multiple event types:Removing Listeners
Store the listener reference to remove later:Standard Event Types
The SDK defines these standard event types:Standard events (Pageview, etc.) are tracked automatically by the web addon. Use
track() for custom events.SDK Events
Listen for internal SDK events:Best Practices
Use Descriptive Event Names
Use Descriptive Event Names
Include Relevant Properties
Include Relevant Properties
Track at the Right Time
Track at the Right Time
Don't Over-Track
Don't Over-Track
Track meaningful user actions, not every interaction:
Handle Errors
Handle Errors
Tracking on Page Unload
For events that must be tracked when the user leaves:The web addon automatically tracks
PageviewComplete on page unload, so you don’t need to track basic exit events manually.Debugging
Enable debug mode to see all tracked events:Troubleshooting
Events not appearing in dashboard
Events not appearing in dashboard
Problem:
track() called but no events in dashboard.Solutions:- Check consent is granted (if
consentRequired: true) - Verify SDK is initialized
- Enable debug mode to see if events are accepted
- Check for JavaScript errors before track call
- Allow processing time (events may take minutes to appear)
Callback not firing
Callback not firing
Problem: Success/error callbacks not called.Solutions:
- Verify callback functions are defined correctly
- Check for errors in callback code
- Ensure SDK is loaded before tracking
Properties missing from event
Properties missing from event
Problem: Event tracked but some properties missing.Solutions:
- Check property names match expected schema
- Verify property types are correct
- Look for undefined values being passed
- Check for typos in property names
Related Documentation
Event Properties
Structure event data
Pageview Tracking
Automatic pageview tracking
Cohorts
Events power cohort membership
Connectivity Events
Event schema documentation