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, 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 once as an identify event for the user's profile and segments.
track(name, properties?)
track(name: string, properties?: Record<string, unknown>): voidProduct 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.
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.
reset()
reset(): voidClears the current user, typically on logout. Events become anonymous; the install ID is kept.
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 is accepted but not sent today.
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 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, 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.3.0. See the release notes.