SDKs and API

Web

Install @rabolic/web from npm or a script tag. Options, automatic page views and page leaves, campaigns, sessions, identity, consent, cookieless mode and limits.

@rabolic/web is Rabolic for the browser. It has no runtime dependencies, and the CDN build is under 8 KB gzip. Source: github.com/rabolic/sdks/js/web.

Use the project's publishable key (rb_pub_…). Secret keys (rb_live_, rb_test_) are refused in the browser.

Install

The quickest way is npx rabolic init in your project. By hand:

Terminal
npm install @rabolic/web
import { rabolic } from '@rabolic/web'

rabolic.init({ projectKey: 'rb_pub_…', trackRoutes: true })

// after signup or login
rabolic.identify(user.id, { plan: 'pro' })

rabolic.track('signup_completed', { method: 'google' })

createRabolic() returns an independent instance if you need more than the rabolic singleton. Calls made before init are kept (up to 100) and replayed.

Options

Pass them to init().

OptionDefault
projectKeyrequiredPublishable key, rb_pub_…
hosthttps://ingest.rabolic.comFor a first-party proxy or self-hosting
trackRoutestrue$pageview on SPA navigation (pushState, replaceState, popstate)
trackPageLeavetrue$page_leave with active_ms and scroll_depth
persistence'localStorage''memory': cookieless, ids last one page lifetime
cookieDomaincurrent hostSuch as .example.com, to share rb_aid across subdomains
consent'granted''pending' until your cookie banner answers
debugfalseLog every call
flushAt20Send when this many events are queued (1–500)
flushIntervalMs5000Send at least this often

At start the SDK fetches remote config (GET /v1/config, cached for 5 minutes). Today it sets the session timeout from your project settings. The protocol has more switches, but no project setting controls them yet.

API

MethodDoes
init(options)Starts the SDK. Logs and does nothing for a missing, invalid or secret key
track(event, properties?)Custom event. snake_case; names starting with $ are reserved
page(properties?)A manual $pageview
identify(userId, traits?)Sets user_id on this and later events; sends $identify with traits
reset()Logout: new anonymous id and session, no user id, no super properties
register(properties) / unregister(key)Super properties, sent with every later event (event properties win)
setConsent('granted' | 'pending' | 'denied')Changes consent at runtime
optOut() / optIn()setConsent('denied') / setConsent('granted')
flush()Sends the queue now. Never rejects
getAnonymousId()The anonymous id, or null before init
appLink(url)Adds rb_aid=<anonymous id> to a store or deep link (needs consent)

No method throws into your page. Pass debug: true to see why a call was dropped.

Automatic events

EventWhen
$pageviewOne on load and one per SPA route. Same-URL and hash-only changes are ignored
$page_leaveOne per page view, on route change or the first time the page is hidden. With active_ms and scroll_depth
  • Active time: active_ms counts time the page was visible and interacted with in the last 30 s. scroll_depth is the furthest point seen, from 0 to 1.
  • Page hide: on visibilitychange to hidden or pagehide, queued events go out with navigator.sendBeacon.
  • Campaigns: utm_* and the click id type (gclid, fbclid, ttclid, msclkid) from the landing URL go in context.campaign.
  • Context: platform: 'web', locale, time zone, screen size and density, page URL, path, title and referrer, and the user agent.

Sessions

  • Sessions are shared across tabs through localStorage.
  • A new session starts after 30 minutes without events, or the web session timeout set in your project settings.
  • A landing with different campaign parameters starts a new session.
  • reset() starts a new session.

See Sessions.

Identity

Call identify() after signup and after every login, with your own stable user id. Use the same id on every platform:

rabolic.identify(user.id, { plan: 'pro' })

Call reset() when someone logs out, so the next person on that device starts fresh:

rabolic.reset()

See Identity.

rabolic.appLink(url) adds rb_aid=<anonymous id> to a store or deep link. The React Native and Flutter SDKs report it in $deep_link as linked_anonymous_id. Rabolic stores it, but doesn't link the web visitor to the app user by it yet. To join them today, call identify() with the same user id on both sides.

consentWhat happens
'granted' (default)Tracks and sends normally
'pending'Writes no cookie and nothing to storage, and sends nothing. Events wait in memory until setConsent('granted')
'denied'Drops the queue and removes everything stored, cookie included
rabolic.init({ projectKey: 'rb_pub_…', consent: 'pending' })

// when your cookie banner answers
rabolic.setConsent('granted') // or 'denied'

Cookieless mode. persistence: 'memory' keeps the ids in memory only, for one page lifetime. Nothing is written to cookies or localStorage.

What the SDK stores, with the default persistence:

  • the anonymous id, a random UUID, in localStorage (rb_aid), mirrored to a first-party rb_aid cookie (SameSite=Lax, Secure on https, one year);
  • the session id and last activity, in localStorage;
  • the unsent queue, in localStorage (rb_queue).

The SDK never reads form fields, the clipboard or location, and does no fingerprinting. See Consent and privacy.

Delivery and limits

Requeststext/plain with the key in the body and no credentials, so the browser sends no CORS preflight
QueueUp to 1,000 events in localStorage (rb_queue). It survives reloads. When full, the oldest go first
BatchUp to 500 events or 900 KB
One event32 KB (32,768 bytes of UTF-8 JSON). Larger events are dropped
Event ageEvents older than 7 days are dropped before sending

See Limits.