Adopture Docs
SDKsReact Native

Offline Support

How the Adopture React Native SDK handles offline scenarios and event persistence.

Local Storage

All events are persisted to AsyncStorage immediately when tracked. Events are never lost, even if the app crashes or is terminated.

The SDK uses the storage key @adopture/event_queue to persist queued events as JSON. On initialization, any previously persisted events are loaded and sent.

Automatic Retry

If an event batch fails to send, the SDK retries automatically:

  • Max retries: 5 attempts per batch
  • Backoff strategy: Exponential backoff with jitter
  • Max backoff: 30 seconds
  • Formula: min(2^attempt × 1000ms, 30000ms) + random jitter

Failed batches are re-queued at the front of the queue so they're retried first.

Batch Sending

Events are sent in batches for efficiency:

SettingDefaultDescription
flushIntervalMs30,000 msPeriodic flush timer
flushAt20 eventsFlush when queue reaches this size
Max batch size100 eventsMaximum events per HTTP request

Network Detection

Install @react-native-community/netinfo for automatic network-aware behavior:

npm install @react-native-community/netinfo

With NetInfo installed:

  • Event sending is paused when the device is offline
  • All queued events are flushed automatically when the connection is restored
  • No events are lost during offline periods

Without NetInfo, the SDK sends events regardless of network state and relies on retry logic for failures.

Queue Management

The queue has a configurable maximum size (default: 1000 events). When the limit is reached, the oldest events are evicted first to make room for new ones.

<AdoptureProvider
  appKey="ak_..."
  options={{ maxQueueSize: 500 }}
>

Manual Flush

Force all queued events to be sent immediately:

await Adopture.flush();

This is useful before important transitions, like navigating to a payment screen.

Idempotency

Each batch request includes a unique Idempotency-Key header. This prevents duplicate event processing on the server if a request is retried after a network timeout.

On this page