Documentation
Configuration
Client options for createClient()
createClient
Collection is denied by default until you pass the visitor's consent decision. Calls made before analytics consent is granted are discarded. See Browser & Consent for setup.
import { createClient } from '@realanalytics/sdk'
const analytics = createClient({
publicKey: 'pk_live_xxx',
endpoint: 'https://realanalytics-ingest.ryanerkal1.workers.dev',
autocapture: true,
consent: {
default: 'denied',
respectGlobalPrivacyControl: true,
respectDoNotTrack: true,
},
retry: {
maxRetries: 3,
baseDelay: 1000,
maxDelay: 30000,
},
onError: (error, events) => {
console.error(error.message, events.length)
},
onSuccess: (_events, receipt) => {
console.log('newly accepted', receipt.accepted)
console.log('duplicates in batch', receipt.duplicatesInBatch)
console.log('duplicates already stored', receipt.duplicatesPreviouslyAccepted)
},
})Option reference
| Option | Type | Default | Notes |
|---|---|---|---|
publicKey | string | Required | Your project public key |
endpoint | string | https://realanalytics-ingest.ryanerkal1.workers.dev | Custom ingest URL |
autocapture | boolean | AutocaptureOptions | true | Enable all or selected built-in tracking after analytics consent |
consent | ConsentConfig | Denied; privacy signals respected | Initial consent and privacy signal handling; see below |
retry | Partial<RetryConfig> | 3 / 1000 / 30000 | Retries 429/5xx/network failures |
onError | (error, events) => void | None | Called after final retry fails |
onSuccess | (events, receipt) => void | None | Receipt separates newly accepted events, in-batch duplicates, and previously accepted duplicates |
Consent options
consent.default?: ConsentInputdefaults to'denied'. A stored consent decision takes precedence. Use a real recorded decision if supplying an initial value.consent.respectGlobalPrivacyControl?: booleandefaults totrue. An active Global Privacy Control signal forces consent to remain denied.consent.respectDoNotTrack?: booleandefaults totrue. An active Do Not Track signal forces consent to remain denied.
Respected privacy signals take precedence over stored decisions and API calls. Pass consent manager changes to setConsent; never grant consent automatically. For example, call this handler when your consent manager supplies a decision:
import type { ConsentUpdate } from '@realanalytics/sdk'
function onConsentDecision(decision: ConsentUpdate) {
analytics.setConsent(decision)
}See the consent methods reference for input types and return values, and Browser & Consent for consent manager mapping.
Autocapture options
const analytics = createClient({
publicKey: 'pk_live_xxx',
autocapture: {
pageviews: true,
pageleave: true,
clicks: true,
scrollDepth: true,
forms: true,
errors: true,
webVitals: true,
outboundLinks: true,
fileDownloads: true,
rageClicks: true,
},
})Retry behavior
- 429: uses
Retry-Afterheader when present - 5xx/network errors: exponential backoff with jitter
- 4xx (except 429): no retry