Configuration

Client options for createClient()

createClient

import { createClient } from '@realanalytics/sdk'

const analytics = createClient({
  publicKey: 'pk_live_xxx',
  endpoint: 'https://ingest.realanalytics.dev',
  autocapture: true,
  retry: {
    maxRetries: 3,
    baseDelay: 1000,
    maxDelay: 30000,
  },
  onError: (error, events) => {
    console.error(error.message, events.length)
  },
  onSuccess: (events) => {
    console.log('sent', events.length)
  },
})

Option reference

OptionTypeDefaultNotes
publicKeystringRequiredYour project public key
endpointstringhttps://ingest.realanalytics.devCustom ingest URL
autocaptureboolean | AutocaptureOptionstrueEnable all or selected built-in tracking
retryPartial<RetryConfig>3 / 1000 / 30000Retries 429/5xx/network failures
onError(error, events) => voidNoneCalled after final retry fails
onSuccess(events) => voidNoneCalled when a batch is accepted

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-After header when present
  • 5xx/network errors: exponential backoff with jitter
  • 4xx (except 429): no retry

Next Steps