The Splitbee JavaScript library is an optional extension for our Splibee.js tracking script. It offers a couple of advantages.
The library builds on top of the Splitbee.js script. There is no need to migrate if you don't see a benefit in the features listed above.
Use npm or yarn to install the package @splitbee/web
yarn add @splitbee/web
After the installation, you can initialize it by running splitbee.init()
. After that, Splitbee will track page views automatically. You can also use event tracking functions to track custom events as well as user properties.
Automatic page view tracking works with single-page applications out of the box. No matter if you use React, Vue.js, Angular, or any other front-end library that uses client-side routing.
import splitbee from '@splitbee/web';// This initiliazes Splitbee.jssplitbee.init()// Track a custom eventsplitbee.track("Sign Up")// Track an event with custom datasplitbee.track("Choose Plan", {plan: "Business"})// Attach data to the current usersplitbee.user.set({})// Clears all data. Should be used if an identified user logs out.splitbee.reset()
If you want to change the default settings, you can do so by providing them as argument to the init function.
import splitbee from '@splitbee/web';splitbee.init({// To use Splitbee on another subdomain.// Token can be found in project settingstoken: 'YOUR_TOKEN',// Enable cookie-less mode. Defaults to `false`disableCookie: false,// Set custom urls when using proxyingscriptUrl: "https://cdn.splitbee.io/sb.js",apiUrl: "https://hive.splitbee.io",})// Enable cookie based trackingsplitbee.enableCookie()// Enable cookie based tracking, and treat it as new usersplitbee.enableCookie(true)// Starts a new session/user (only works when cookie is enabeld) - Useful if a user logs outsplitbee.reset()
If you want to send data to Splitbee from your Node.js server, check out @splitbee/node.