BackendBatchAdapter

class BackendBatchAdapter(endpoint: String, authToken: String? = null) : EventAdapter

Adapter that delivers events to a first-party backend endpoint as batched HTTP POST requests.

Events are persisted to the local Room database before any network attempt. This adapter's deliver is a no-op — the dispatcher already wrote the event to the database as EventState.QUEUED. The actual network send happens in flush, which is triggered by FlushScheduler.

Retry policy: truncated exponential backoff with full jitter. Events that exhaust maxRetries are moved atomically to the dead-letter table. HTTP 400 responses move events to the DLQ immediately (the payload is structurally broken and will keep failing). HTTP 429 responses additionally halve the next batch size to reduce load on a recovering server.

Since

1.0.0

Parameters

endpoint

Full URL of the batch ingest endpoint, e.g. "https://api.example.com/v1/events".

authToken

Bearer token for the Authorization header, if required.

Constructors

Link copied to clipboard
constructor(endpoint: String, authToken: String? = null)

Properties

Link copied to clipboard
open override val id: String

Stable, unique identifier for this destination (e.g. "firebase", "backend").

Functions

Link copied to clipboard
open override fun accepts(event: TrackEvent): Boolean

Decide whether this adapter wants the given event.

Link copied to clipboard
open suspend override fun deliver(event: TrackEvent): DeliveryOutcome

No-op: the event is already in the DB as QUEUED when this is called.

Link copied to clipboard
open suspend override fun flush(): DeliveryOutcome

Drains the queue: reads batches of effectiveBatchSize and POSTs them until the queue is empty or a non-retryable error halts further sends.

Link copied to clipboard
open suspend fun identify(userId: String?, traits: Map<String, Any?>)

Forwarded user identification. Called when the host app calls in.singhangad.eventtracker.EventTracker.identify. Default is a no-op.

Link copied to clipboard
open override fun initialize(context: Context, logger: EventLogger)

Called once during in.singhangad.eventtracker.EventTracker.initialize. Use this to initialise any underlying SDK, open connections, or set up resources.

Link copied to clipboard
open fun onOptOut()

Called when the host opts out and local data is being cleared. Implementations should clear any locally cached user state.