SDKs
Client libraries for sending events and managing identity from your applications. All SDKs share the same mental model — init once, track events, identify users.
Platform support
Web
Browser analytics with auto-tracking, batching, and sessions — @poluruprvn/pug-web. Available now.
Web docs →Start with the Web SDK for browser analytics. Mobile platforms can integrate via the Events API until native SDKs ship.
Shared mental model
Every SDK follows the same lifecycle:
init(projectId, options) ← once at app startup
│
├── track(name, props) ← throughout the app
├── identify(id, traits) ← after sign-in
└── reset() ← on sign-outInitialization
Call init once at app startup with your project ID and SDK API key:
init('YOUR_PROJECT_ID', {
apiKey: 'YOUR_SDK_API_KEY',
endpoint: 'https://api.pug.sh'
})See Initialization for all options.
Tracking
track('event_name', { property: 'value' })
track('purchase', { revenue: 29.99, currency: 'USD' }, { immediate: true })Custom event names are accepted. Well-known events are schema-validated for richer dashboard support.
Identity
identify('user-123', { email: 'user@example.com', plan: 'pro' })Merges anonymous activity into a known profile. Call after sign-in; call reset() on sign-out.
Sessions
Sessions group events within a visit. SDKs manage session IDs automatically:
- New session after inactivity timeout (default 30 minutes)
- Session extended on each event within the window
- Web SDK syncs session ID across browser tabs via
localStorage
Batching
Events are queued and flushed in batches for performance:
- Default batch size and flush interval are tuned for browser/mobile
- Priority events bypass the queue with
{ immediate: true } - Web SDK persists the queue in
localStorageacross page reloads
Failed batches are retried automatically. Events are never silently dropped unless dryRun: true.
Auto-properties
SDKs attach context automatically:
| Property | Source |
|---|---|
$url, $referrer, UTM params | Web SDK |
$screen, $sdkVersion | All SDKs |
$geo.*, $browser, $botScore | Server enrichment |
See Auto-properties.
Choosing an integration path
| I want to… | Start here |
|---|---|
| Track website visitors | Web SDK quickstart |
| Track a React/Next.js app | Installation → Next.js |
| Send events from my backend | Events API |
| Query analytics programmatically | Insights API with shared key |
| Track a Flutter/Android/iOS app | Mobile interim guides |
Authentication
SDKs use the SDK API key from project settings. Never expose a shared/private key in client code.
Authorization: Bearer <sdk-api-key>
x-project-id: <project-id>See Authentication.
Further reading
- Quickstart — first event in 5 minutes
- Core concepts — events, profiles, sessions
- Well-known events — typed event schemas