@wyvrn-analytics/core
v0.1.1
Published
Vanilla TS analytics client for the Wyvrn Analytics ingest endpoint.
Maintainers
Readme
@wyvrn-analytics/core
Vanilla TypeScript analytics client for Wyvrn Analytics. Zero runtime dependencies, batched + retried over fetch, sendBeacon on unload, offline queue in localStorage.
Install
pnpm add @wyvrn-analytics/coreFor React apps you'll usually want @wyvrn-analytics/react instead, which wraps this with a Provider + hooks.
Quick start
import { init, track, page, identify } from '@wyvrn-analytics/core'
init({
apiKey: 'pk_xxxxx',
endpoint: 'https://analytics.your-domain',
autoCapturePageView: true,
})
track('signup_started', { plan: 'pro' })
page()
identify('user-123', { email: '[email protected]' })API
init(options)— configure the singleton clientcreateClient(options)— factory for non-singleton usagetrack(eventName, properties?)page(name?, properties?)— records$pageviewwith$pathname/$url/$title/$referreridentify(userId, traits?)— attaches a user_id to the anonymous_idreset()— clear user_id and re-seed anonymous_id (call on logout)flush()— force immediate send
Options
| Key | Default | Notes |
|---|---|---|
| apiKey | — | Public key (pk_…) |
| endpoint | — | Base URL; /e appended if not already present |
| flushAt | 20 | Send when buffer hits this many events |
| flushInterval | 10000 | Timer-based flush in ms |
| respectDoNotTrack | true | If browser signals DNT, SDK becomes inert |
| autoCapturePageView | false | Fire $pageview on init |
| debug | false | Console logs |
Reliability
- Events are persisted to
localStorageon transport failure and re-sent on next flush pagehide/visibilitychange='hidden'triggers asendBeaconflush- Each event carries a UUID v4
eventIdfor server-side dedup on retry
