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"}

Track form submissions

It is simple to track form submissions using Splitbee. Simply set the data-splitbee-event property to a form element like in the following example

<form data-splitbee-event="Submit Newsletter Form">
  <input name="email" type="email" />
  <button type="submit">Submit</button>
</form>

If a user now submits the form, the event Submit Newsletter Form is submitted. The event data {"email":"[email protected]"}