JavaScript API
Track dynamic interactions that HTML attributes cannot express
Most tracking works with data attributes. You do not need JavaScript for that. Use this API for dynamic data that HTML attributes cannot express.
sendCustomEvent
Section titled “sendCustomEvent”Use this to track interactions where the data is known only at runtime.
Syntax: Fusionaly.sendCustomEvent(eventName, metadata)
- eventName (string): A unique name for your event. For example:
trial_started,file_downloaded. - metadata (object): Extra data about the event. Add any key-value pairs, for example
{ plan: "premium", fileName: "report.pdf" }. This data appears in your analytics.
Example:
Fusionaly.sendCustomEvent("video_played", { videoTitle: "Product Demo", durationWatched: "60s",});Manual Page Views
Section titled “Manual Page Views”If your SPA does not trigger automatic page views, call this function yourself:
window.Fusionaly.sendPageView();Common Use Cases
Section titled “Common Use Cases”Track Form Submissions
Section titled “Track Form Submissions”This is the simplest way. You do not need JavaScript:
<form data-fusionaly-event-name="contact_form_submitted"> ...</form>See Tracking for details.
For dynamic form data that HTML attributes cannot express:
Fusionaly.sendCustomEvent('form_submitted', { form_name: 'contact_form', plan_selected: selectedPlan});Track Video Engagement
Section titled “Track Video Engagement”video.addEventListener('play', function() { Fusionaly.sendCustomEvent('video_started', { video_id: 'demo-video', video_title: 'Product Demo' });});
video.addEventListener('ended', function() { Fusionaly.sendCustomEvent('video_completed', { video_id: 'demo-video', video_title: 'Product Demo' });});Track Feature Usage
Section titled “Track Feature Usage”function onFeatureUsed(featureName) { Fusionaly.sendCustomEvent('feature_used', { feature: featureName, timestamp: new Date().toISOString() });}