Analytics SDK

Delivery and the debugger

How the SDK queues, batches, retries and flushes events, what happens on shutdown, and how to read rejected events in the SDK debugger.

Tracking calls never send anything themselves. They add an event to an in-memory queue, and the SDK's own thread sends the queue in batches. This page explains that pipeline end to end, so you know what to expect when the network is slow, the API is unreachable or a server shuts down.

#The queue

  • Every event is added to the end of one queue per server.
  • The queue holds at most 5,000 events. When it is full, the oldest event is dropped to make room, the SDK warns once (Event queue full; dropping oldest events until the API is reachable) and the drop is counted in Analytics:GetStats().dropped.
  • The queue lives in memory only. If a server crashes, or Roblox closes it without running BindToClose, events still in the queue are lost.

At normal rates the queue is nearly empty: it is sent every few seconds. It only fills when the API can't be reached for a long time.

#Batching

A loop on the SDK's own thread wakes once a second. It flushes when either:

  • the flush interval has passed since the last flush (default 10 seconds, 2–60), or
  • the queue holds at least a full batch (default 200 events, 10–500).

A flush sends batches of up to the maximum batch size, one after another, until the queue is empty or a send fails. Each batch is one POST /v1/ingest request (see send events). The dashboard's Flush interval (seconds) and Maximum batch size override the values in your script once the server has loaded its remote configuration.

With the defaults, a busy server sends about one request every 10 seconds, plus one configuration fetch every 5 minutes.

#Retries and backoff

What happens to a batch depends on the response:

Response What the SDK does
2xx The batch is removed from the queue and the backoff resets.
No response (network error, HTTP requests not allowed, timeout) Kept and retried with backoff.
429 Too Many Requests Kept and retried with backoff.
5xx Kept and retried with backoff.
Any other status (400, 401, 413 …) Dropped. Retrying can't help with a bad key or an invalid payload. The SDK warns once per status code: API rejected a batch (<status>): <response body>.

The backoff starts at 2 seconds and doubles on each consecutive failure (2, 4, 8, 16, 32) up to 60 seconds, where it stays until a send succeeds. While backing off, no batches are sent; events keep queuing up to the 5,000 limit.

A retried batch contains the same events with the same ids. The API remembers event ids for two days and ignores duplicates, so a batch that reached the API but whose response was lost is never counted twice.

#Shutdown flush

The SDK binds a game:BindToClose handler. When the server closes, it:

  1. ends every open session, queuing a $session_end for each player still in the server;
  2. queues $server_stop;
  3. ignores any backoff and flushes, retrying once a second, for up to 20 seconds or until the queue is empty.

Roblox gives all BindToClose handlers 30 seconds in total, so the SDK leaves room for your own save code. If you also save player data in BindToClose, the two run side by side.

#What the API accepts

The API checks each batch in two stages.

  1. The batch. The key and project id must be valid (otherwise 401), the body at most 1 MB, and the envelope well formed with 1–500 events (otherwise 400, and the whole batch is rejected). Each project may make up to 3,000 ingest requests a minute; beyond that the API answers 429 and the SDK backs off.
  2. Each event. Events are checked one by one, so one bad event doesn't cost the rest of its batch. The response is 202 with the counts, for example { "accepted": 198, "rejected": 2 }. The SDK doesn't read the counts: rejected events are listed in the debugger instead.

Events are then checked against your project's settings: tracking switches, currencies, blocked events and the rules for each reserved event. Timestamps more than 30 days old are rejected; timestamps more than 5 minutes in the future are replaced by the time the batch arrived.

#The SDK debugger

The Debugger panel on the SDK page shows whether events are arriving and why any were rejected. It refreshes every 10 seconds.

Field Meaning
Status Receiving batches when a batch arrived in the last 2 minutes; otherwise Last batch with how long ago, or Waiting for the first batch.
Accepted events Events stored.
Rejected events Events rejected, with the share of all events.
Batches received Batches the API accepted for processing.
Batches rejected Batches rejected as a whole.
Last batch When the latest batch arrived.
SDK version The Analytics.Version of the server that sent it.
Last server The server key (JobId) of that server.
First event When this project received its first event.

Recent problems lists the latest 50 rejection reasons, newest first, kept for 7 days. Select Clear to empty it (this needs the Edit project settings and SDK keys permission). The reasons you are most likely to see:

Reason Cause and fix
Unknown currency "Gold" — add it in SDK settings Your currency list doesn't include this name. Add it, or fix the name in code.
economy tracking disabled The Economy switch is off. Also session tracking disabled, purchase tracking disabled, custom events disabled.
blocked The custom event's name is in Blocked events.
$economy: category Too big: … A property is longer than the API allows (here category, at most 64 characters). The event name and property are shown first.
$funnel requires userId A player event was sent without a player.
Invalid event name "…" Only possible from a modified SDK: the official one checks names before queuing.
<name>: timestamp older than 30 days The server's clock is wrong, or events were held for a very long time.
Rejected batch: … / Rejected 2 of 200 events: … The batch or some events didn't match the wire format. The path shows where, for example events.12.props.

If Rejected events climbs but Recent problems is empty, someone may have cleared it. New rejections reappear within a batch or two.

#Checking from the server

Analytics:GetStats() returns the server's own view:

local stats = Analytics:GetStats()
print(stats.queued, stats.dropped, stats.enabled, stats.backoff)
Field Meaning
queued Events waiting to be sent.
dropped Events dropped because the queue was full.
enabled Whether the SDK is sending. false when the configuration was rejected or in Studio without TrackInStudio.
backoff The current retry delay in seconds; 0 when the last send succeeded.

Analytics:Flush() sends the queue immediately, for example before you teleport everyone out of a server. Unlike the tracking calls it yields while requests are in flight, so call it from a thread that can wait. It does nothing while another flush is running or during backoff.

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local Analytics = require(game.ServerScriptService.Analytics)

local LOBBY_PLACE_ID = 0 -- your lobby's place id

Analytics:TrackEvent("RoundEnded", { Map = "Forest" })
Analytics:Flush()
TeleportService:TeleportAsync(LOBBY_PLACE_ID, Players:GetPlayers())