@leanbase.com/js
v0.1.2
Published
Leanbase browser SDK - event tracking, autocapture, and session replay
Readme
Leanbase SDK
Lightweight browser SDK for Leanbase - event tracking, autocapture, and session replay.
Installation
npm install @leanbase.com/js
# or
pnpm add @leanbase.com/jsQuick Start
import { Leanbase } from '@leanbase.com/js'
// Initialize with your API key
const leanbase = new Leanbase('your-api-key')
// Track events
leanbase.capture('button_clicked', {
button_name: 'signup',
page: 'homepage'
})
// Identify users
leanbase.identify('user-123', {
email: '[email protected]',
name: 'John Doe'
})CDN / Script Tag
Include the prebuilt IIFE bundle from a CDN and use the global leanbase object. Call leanbase.init('<apiKey>', options) once, then use leanbase.capture(...) and friends.
<script src="https://unpkg.com/@leanbase.com/js/dist/leanbase.iife.js"></script>
<script>
// Initialize with your API key
leanbase.init('your-api-key', { host: 'https://i.leanbase.co' })
// Track an event
leanbase.capture('pageview')
</script>Alternatively via jsDelivr:
<script src="https://cdn.jsdelivr.net/npm/@leanbase.com/js/dist/leanbase.iife.js"></script>Configuration
const leanbase = new Leanbase('your-api-key', {
host: 'https://i.leanbase.co', // default
autocapture: true, // default - automatically capture clicks and form interactions
preloadFeatureFlags: true, // default - fetch feature flags on initialization
})API Reference
leanbase.capture(event, properties?, options?)
Track custom events.
leanbase.capture('purchase_completed', {
amount: 99.99,
currency: 'USD',
product_id: 'abc-123'
})leanbase.identify(distinctId?, properties?, options?)
Identify users and set user properties.
leanbase.identify('user-456', {
email: '[email protected]',
plan: 'premium'
})leanbase.group(groupType, groupKey, properties?)
Associate users with groups (teams, organizations, etc).
leanbase.group('company', 'acme-corp', {
name: 'Acme Corporation',
plan: 'enterprise'
})leanbase.alias(alias)
Create an alias for the current user.
leanbase.alias('user-123')Publishing
Version Bumping
This monorepo uses Changesets for versioning.
To bump the version:
- Create a changeset:
pnpm changeset add- Select
@leanbase.com/jspackage - Choose version bump type (patch, minor, major)
- Add a description of changes
- Select
- Commit the changeset file (
.changeset/*.md) - Run
pnpm changeset versionto update versions - Commit the version changes
Example changeset file (.changeset/example-changes.md):
---
"@leanbase.com/js": patch
---
Added IIFE build for script-tag usage and improved documentation.Publishing to NPM
- Ensure you have an NPM token with publish permissions
- Set the token:
export NPM_TOKEN=your_token - Publish:
pnpm [email protected]/js publish - Or test first:
pnpm [email protected]/js exec npm publish --dry-run
The package will be published to https://www.npmjs.com/package/@leanbase.com/js
License
Copyrighted by Leanflag Limited
