@splitbee/web

The Splitbee JavaScript library is an optional extension for our Splibee.js tracking script. It offers a couple of advantages.

  • Available instantly. No need to wait for Splitbee.js to load
  • Auto-complete support. Thanks to the TypeScript typings
  • It automatically injects Splitbee.js for you

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.

Installation

Use npm or yarn to install the package @splitbee/web

yarn add @splitbee/web

Basic Usage

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.js
splitbee.init()
// Track a custom event
splitbee.track("Sign Up")
// Track an event with custom data
splitbee.track("Choose Plan", {
plan: "Business"
})
// Attach data to the current user
splitbee.user.set({
})

Advanced options

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 settings
token: 'YOUR_TOKEN',
// Enable cookie-less mode. Defaults to `false`
disableCookie: false,
// Set custom urls when using proxying
scriptUrl: "https://cdn.splitbee.io/sb.js",
apiUrl: "https://hive.splitbee.io",
})

If you want to send data to Splitbee from your Node.js server, check out @splitbee/node.