@radiate-so/js-sdk
v0.1.1
Published
Isomorphic tracking SDK for the Radiate CDP — browser, Node, and Cloudflare Workers.
Maintainers
Readme
@radiate-so/js-sdk
Isomorphic tracking SDK for the Radiate CDP. Works identically in the
browser, Node, and Cloudflare Workers — uses only globalThis.fetch
and crypto.randomUUID(), no environment-specific code paths.
This is the core SDK: a thin, stateless HTTP client around
/v1/track, /v1/identify, and /v1/profile. It does not manage
queues, anonymous-ID storage, session lifecycles, or unload flushing —
those belong in the future @radiate-so/browser-sdk (and downstream
framework wrappers like @radiate-so/react-sdk).
Install
pnpm add @radiate-so/js-sdkUsage
Browser (public key)
import { Radiate } from '@radiate-so/js-sdk'
const radiate = new Radiate({ publicKey: 'pk_...' })
await radiate.track({
event: 'page_view',
properties: { path: '/pricing' },
anonymous_id: 'a-id-from-caller-storage',
})The Origin header is set automatically by the browser; the server
checks it against the public key's allowlist.
Server (secret key)
import { Radiate } from '@radiate-so/js-sdk'
const radiate = new Radiate({ secretKey: process.env.RADIATE_KEY! })
await radiate.identify({
user_id: 'usr_123',
email: '[email protected]',
traits: { plan: 'pro' },
})
await radiate.trackBatch([
{ event: 'signup', user_id: 'usr_123', properties: { plan: 'pro' } },
{ event: 'welcome_seen', user_id: 'usr_123' },
])
const profile = await radiate.profile({ user_id: 'usr_123' })API
| Method | Notes |
|---|---|
| track(event) | Single event. Wire: POST /v1/track with [event]. |
| trackBatch(events) | Array of events in one POST. |
| identify(payload) | Secret-key only. |
| profile(identifiers) | Secret-key only. Returns the resolved profile. |
The SDK fills in message_id (UUID v4) and timestamp (ms epoch)
when missing — gives stable idempotency keys for retries.
Why no queue / storage / unload?
The browser-specific lifecycle (queue events, batch them on size /
interval / unload, persist anonymous_id in localStorage) belongs
in a per-environment wrapper. Keeping the core slim means it ships
the same in Workers (where queueing across requests is wrong) and
Node (where caller-controlled lifecycles are the norm).
@radiate-so/browser-sdk will compose this package and add those
behaviours.
