Guarantees for every function
Never throws into your page. Safe to call beforeinit (it does nothing). Never does network work on the calling path. Callable from anywhere, including server-rendered modules.@codeskop/tracker
import { init, identify, track, screen, reset, recordException, setEnabled, flush } from "@codeskop/tracker";init(config)
init(config: CodeskopConfig): voidStarts the SDK. Returns immediately; all setup happens in the background. A secret or malformed apiKey leaves the SDK switched off. Calling init again tears down the current setup and starts fresh with the new config. See Configuration for every option.
identify(userId, traits?)
identify(userId: string, traits?: Record<string, unknown>): voidAttaches later events to a signed-in user. Use your own stable ID, not an email. Repeating the same ID is fine. With product analytics (Growth and Scale, 1.3+), traits are sent as an identify event for the user's profile and segments. From 1.5.0, the first identify after a new anonymous ID always sends that event, even without traits, so what the browser did before sign-in is linked to the user.
track(name, properties?, options?)
track(name: string, properties?: Record<string, unknown>, options?: TrackOptions): void type TrackOptions = { category?: TrackCategory };type TrackCategory = "lifecycle" | "navigation" | "interaction" | "identity" | "conversion";Product analytics: records a custom event, e.g. track("order_completed", { value: 49.99 }). Properties may be text, numbers, booleans, null or lists of those. Since 1.3. See Track events & screens.
options.category (1.5.0+) says what kind of step the event is. Without it, the server works one out from the name. An unknown category is left out with a console warning and the event is still sent. Names starting with $ are reserved for the SDK's own events and are dropped, like an empty name. See the event model.
screen(name, properties?)
screen(name: string, properties?: Record<string, unknown>): voidProduct analytics: records a screen view. Pages are recorded automatically unless capturePageViews: false. Since 1.3. From 1.5.0 the SDK adds previous_screen, and on the first screen of a page load the referrer (origin and path only) and load_ms.
reset()
reset(): voidClears the current user, typically on logout. Events become anonymous; the install ID is kept. From 1.5.0 it also starts a new anonymous ID, so the next person on a shared computer isn't linked to this one. Call it on logout only, not on every page load for signed-out visitors.
recordException(error, attributes?)
recordException(error: unknown, attributes?: Record<string, unknown>): voidReports an error your code caught. Accepts any thrown value; non-Error values are recorded too. Handled exceptions are never sampled away. attributes are sent with the error (1.4.3+): scalars and lists of scalars, with nested objects dropped. The message is sent as [REDACTED] unless captureExceptionMessages is on (1.6.0+).
setEnabled(enabled)
setEnabled(enabled: boolean): voidPauses (false) or resumes (true) capture for this page session, for example when a user opts out. Works independently of the remote kill-switch: if either is off, nothing is captured. The next init starts enabled again.
flush()
flush(): Promise<boolean>Asks the SDK to send queued events now. Resolves true if a send attempt ran, and false before init or if a send was already in progress. Never rejects. Rarely needed outside debugging; sending is automatic.
Types
CodeskopConfig, TrackOptions and TrackCategory (1.5.0+), and the event model types (EventType, Severity, CodeskopEvent and friends) are exported for TypeScript users.
@codeskop/tracker-react
import { CodeskopProvider, CodeskopErrorBoundary, useCodeskop } from "@codeskop/tracker-react";CodeskopProvider
| Option | Type | Description |
|---|---|---|
| config | CodeskopConfig | Passed to init once, on mount. Later changes are ignored. |
| children | ReactNode | Your app. |
CodeskopErrorBoundary
| Option | Type | Description |
|---|---|---|
| children | ReactNode | The subtree to protect. |
| fallback | ReactNode | (error: Error, reset: () => void) => ReactNode | Rendered after a render error. The function form receives a reset that re-renders the children. |
| onError | (error: Error, errorInfo: ErrorInfo) => void | Called alongside the report. |
Reports render errors as handled exceptions. Only catches errors thrown during render.
useCodeskop()
useCodeskop(): { identify, reset, recordException, track, screen, setEnabled, flush}Returns the core functions above. Works with or without a CodeskopProvider in the tree.
Versioning
Both packages follow semantic versioning: breaking changes to anything on this page only happen in a major release. The current version is 1.5.0. See the release notes.