Skip to content
Docs
Loading documentation…
Open platform
Documentation

Configuration reference

Initialization options, runtime behavior, sampling, and delivery limits.

@askdepth/corev0.3.0
On this page

Askdepth.init(options) returns the Askdepth API object. Named imports such as init, track, and setConsent expose the same singleton functions.

Initialization options

OptionDefaultBehavior
writeKey: stringRequiredBrowser write key sent as x-askdepth-write-key.
endpoint?: stringNoneFull telemetry POST URL. Collection requires it, despite the optional TypeScript property.
consent?: ConsentState'unknown''granted', 'denied', or 'unknown'.
sampleRate?: number1Probability of sampling the runtime into collection; supply a value from 0 to 1.
environment?'production''production', 'staging', or 'development'.
allowRapidClickSelectors?: string[][]CSS selectors excluded from rage-click detection.
allowedTracingOrigins?: string[][]Additional destinations eligible for tracing; same-origin is eligible by default.
replay?Disabledtrue or { endpoint?: string; checkoutEveryNms?: number }. Requires the installed replay package.
projectId?: stringNoneDeprecated client metadata; it does not bind ownership or replace writeKey.
ts
import { init, type AskdepthInitOptions } from '@askdepth/core';

const options = {
  writeKey: 'YOUR_BROWSER_WRITE_KEY',
  endpoint: 'https://YOUR_COLLECTOR/v1/telemetry',
  consent: 'unknown',
  environment: 'staging',
  sampleRate: 0.25,
  allowRapidClickSelectors: ['[data-stepper]'],
} satisfies AskdepthInitOptions;

init(options);

Sampling and reconfiguration

Sampling is decided with Math.random() < sampleRate when a runtime is created. It is an in-memory decision, with no persisted assignment across page loads. The SDK does not validate or clamp the sampling value, so validate configuration in your application.

An identical init call leaves the runtime in place. A changed option tears down the previous collectors and queue, then creates a new runtime and sampling decision. Keep initialization stable; avoid calling it on every render.

For consent changes, use setConsent. Consent is also part of the initialization comparison key, so mixing prop changes and direct consent calls requires care.

Delivery behavior

The queue flushes every two seconds, when it reaches ten events, or immediately for high-priority anomalies. It retains up to 50 queued events and approximately 64 KiB of serialized event data. The envelope adds overhead, so this bound is not a promise that every request fits a browser's keepalive budget. Low-priority events are dropped first under pressure.

Requests use fetch with keepalive: true. Page hide and visibility changes attempt to send pending data. There is no durable offline queue. Retried batches retain their IDs; retries can produce duplicate network requests.

Collector responseSDK behavior
429 or 5xxRetry, honoring Retry-After when present; delay is capped at 30 seconds.
Network failureRetry with exponential backoff capped at 30 seconds.
Other responsesClear that pending batch, including ordinary 4xx rejections.
410, x-askdepth-kill: true, or JSON { "kill": true }Deactivate this runtime and clear its state.

The kill signal prevents reinitialization for the lifetime of the loaded module. Reloading the application creates a new module runtime. Inspect collector responses when initialization succeeds but data never appears.