oakdata-js
v1.4.1
Published
OakData web analytics SDK — drop-in tracker for browser + Next.js apps.
Downloads
790
Maintainers
Readme
oakdata-js
OakData's browser analytics SDK — a drop-in tracker for any web app. Pageviews, autocaptured clicks, web vitals, errors, sessions, and optional session replay, with zero config.
For trusted server-side events, use the companion
oakdata-node.
Full docs: https://oakdata.co/docs
Install
npm install oakdata-jsNext.js (App Router)
Create instrumentation-client.ts at your project root:
import oak from 'oakdata-js'
oak.init(process.env.NEXT_PUBLIC_OAK_KEY!, {
api_host: process.env.NEXT_PUBLIC_OAK_HOST,
})Add to .env.local:
NEXT_PUBLIC_OAK_KEY=oak_pub_xxxxxxxxxxxxxxxxxxxxxxxx
NEXT_PUBLIC_OAK_HOST=https://oakdata.coPageviews and autocapture start immediately. No bundler? Use the script-tag snippet shown in your dashboard.
Identify signed-in users
oak.identify(user.id, { email: user.email, name: user.name })
oak.reset() // on sign-outCalls made before init() are queued and replayed once the tracker boots, so
it's safe to call these from anywhere.
API
oak.init(key, options)
oak.capture('signup_completed', { plan: 'pro' })
oak.identify(userId, { email })
oak.page()
oak.set({ plan: 'enterprise' })
oak.group('company', 'acme-co', { name: 'Acme' })
oak.reset()
oak.flush()
oak.getDistinctId()
oak.getSessionId()init options
| Option | Type | Default |
| ------------------- | -------------------------- | -------------- |
| api_host | string | current origin |
| autocapture | boolean | true |
| capture_pageview | boolean | true |
| respect_dnt | boolean | false |
| debug | boolean | false |
| property_denylist | string[] | [] |
| before_send | (event) => event \| null | — |
| loaded | (oak) => void | — |
License
MIT
