← Back

Track Events

Page views are tracked automatically but you can also track custom user events. There are two ways to do this.

Track events using JavaScript

The Splitbee JS library is exposed on the global window object called splitbee.

Use the splitbee.track() function to log events for the active user. Provide the name of the event as first argument. Optionally you can add data to your event by providing an object as second argument. This data can be viewed inside the dashboard.

 
window.splitbee.track("Submit Contact Form")
window.splitbee.track("Select Plan", {type: "enterprise"})
 

Track clicks with HTML attributes

It's also possible to automatically track events using HTML attributes. Just add the data-splitbee-event to any HTML Element.

<button data-splitbee-event="Press Subscribe">Subscribe</button>

You can also add event data using attributes

<button data-splitbee-event="Click Plan" data-splitbee-event-type="Business">Subscribe Business</button>
<button data-splitbee-event="Click Plan" data-splitbee-event-type="Enterprise">Subscribe Enterprise</button>

This will add following data to the Click Plan event.

{"type": "Business"}