Analytics SDK
Configure the SDK
Every field you can pass to Analytics:Start and Analytics:Init, with types, defaults and validation rules.
You configure the SDK with one table passed to Analytics:Start (or Analytics:Init). Only WriteKey and ApiUrl are required. Everything else has a default, and most behaviour can also be changed later from the dashboard through remote configuration.
local HttpService = game:GetService("HttpService")
local Analytics = require(game.ServerScriptService.Analytics)
Analytics:Start({
WriteKey = HttpService:GetSecret("bloxlytics_write_key"),
ApiUrl = "https://api.bloxlytics.app",
TrackInStudio = false,
Debug = false,
})#Start and Init
Analytics:Start(config)starts analytics and, when you passCmdr, the Cmdr bridge. Use this one.Analytics:Init(config)starts analytics only and ignores the bridge fields.
Both return true when the configuration is usable and false when it isn't, and both may be called only once per server; a second call warns Init/Start called twice; ignoring the second call and returns false. Start returns the analytics result: a bridge problem only turns the bridge off.
The SDK keeps the table you pass and changes two fields in place: trailing slashes are removed from ApiUrl, and ProjectID is replaced by the resolved Universe ID as a string.
#All fields
#Analytics
| Field | Type | Default | Meaning |
|---|---|---|---|
WriteKey |
string or Secret |
required | The project's write key. As a string it must start with bxw_. A Secret from HttpService:GetSecret is used as it is. |
ApiUrl |
string |
required | The Bloxlytics API, https://api.bloxlytics.app. Must start with http:// or https://; trailing slashes are removed. |
ProjectID |
string or number |
game.GameId |
The experience's Universe ID. Leave it out; set it only to test an unpublished place. See project ID. |
TrackInStudio |
boolean |
false |
Queue and send events in Studio sessions. Off by default so testing doesn't count towards your numbers. |
AutoTrackSessions |
boolean |
true |
Start a session when a player joins and end it when they leave. false turns off $session_start and $session_end from this server entirely. |
AutoTrackGamePasses |
boolean |
true |
Record game pass purchase prompts as $purchase events. Developer product prompts are recorded either way. |
FlushInterval |
number |
10 |
Seconds between sends, clamped to 2–60. Replaced by the dashboard's value when remote configuration loads. |
MaxBatchSize |
number |
200 |
Events per request, clamped to 10–500. Replaced by the dashboard's value when remote configuration loads. |
Debug |
boolean |
false |
Print sends, retries and configuration loads to the output, prefixed [Bloxlytics]. |
#Cmdr bridge
These fields are only read by Analytics:Start, which passes them to CmdrBridge:Init. Their full behaviour is on the bridge reference.
| Field | Type | Default | Meaning |
|---|---|---|---|
Cmdr |
Cmdr server module | none | Your server Cmdr module. Passing it turns the bridge on. |
BridgeKey |
string or Secret |
none | The project's bridge key. Required when Cmdr is passed. As a string it must start with bxb_. |
AllowedGroups |
{ string } |
all groups | The Cmdr groups Bloxlytics may run. Commands in any other group (or in no group) are refused. |
AllowSystemCommands |
boolean |
true |
false: Cmdr commands only run as the sender's own player, when they are in this server. |
AllowKick |
boolean |
true |
Allow kicks sent from Bloxlytics. |
OnWarn |
(Player, string) -> () |
none | Shows a warning to a player. Passing it enables warnings from Bloxlytics. |
OnAnnounce |
(string) -> () |
none | Shows a server-wide announcement. Passing it advertises the announce capability. |
EnableBridgeInStudio |
boolean |
true |
Run the bridge in Studio sessions, so you can test commands. |
Debug, ProjectID and ApiUrl are shared with the bridge.
#Keys and secrets
Each project has two keys, shown on the SDK page under Keys:
| Key | Prefix | Used by | Can do |
|---|---|---|---|
| Write key | bxw_ |
Analytics |
Submit events and fetch the SDK's remote configuration. It can't read analytics. |
| Bridge key | bxb_ |
CmdrBridge |
Register a server, receive commands and report results. |
Neither is a Roblox Open Cloud key, and neither works in place of the other: the SDK checks the prefix of a string key before it sends anything.
Both modules accept a key as a plain string or as a Secret returned by HttpService:GetSecret. With a Secret, the SDK builds the Authorization header with Secret:AddPrefix("Bearer "), so the key itself is never turned into a string in your code. To use secrets, add bloxlytics_write_key (and bloxlytics_bridge_key) under Secrets for your experience in Creator Hub, restricted to api.bloxlytics.app.
#Rotating a key
Use the rotate button next to a key on the SDK page. The old key stops working immediately: running servers have their batches rejected with 401 (or lose the bridge) until you update the secret or the script and the servers restart. With secrets, you only update the secret; no publish is needed, but existing servers keep the old value until they restart.
#Project ID
A Bloxlytics project is one experience, and its id is the experience's Universe ID. A running server knows that as game.GameId, so you normally leave ProjectID out.
ProjectID |
Place | Result |
|---|---|---|
| left out | published | Uses game.GameId. |
| left out | unpublished (game.GameId is 0) |
Not started: this place isn't published, so it has no Universe ID yet; publish it, or set ProjectID to the experience's Universe ID. |
| digits (string or number) | unpublished | Uses the value you give. Handy for testing a new place in Studio. |
| digits (string or number) | published, matches game.GameId |
Uses it. |
| digits (string or number) | published, different from game.GameId |
Not started: ProjectID … isn't this experience's Universe ID (…); leave ProjectID out to use it automatically. This stops one experience's servers reporting into another project. |
| a project id from before projects were keyed by Universe ID (a UUID) | any | Still accepted, for older installs. |
| anything else | any | Not started: ProjectID must be the experience's Universe ID (or leave it out to use game.GameId). |
The project id is sent with every request in the X-Bloxlytics-Project header. See authentication.
#API URL
Set ApiUrl to https://api.bloxlytics.app, which is also the API URL shown under Keys. The SDK adds the paths itself (/v1/ingest, /v1/config, /v1/bridge/…), so give the bare address with no path; trailing slashes are removed for you.
The SDK only checks that the value starts with http:// or https://. Always use the https:// address: keys travel in the Authorization header, and the address is what an experience secret is restricted to.
#Validation order
Start and Init check the configuration in this order and stop at the first problem:
- It is running on the server.
- It hasn't already been called on this server.
- The configuration is a table (
pass a configuration table). ProjectIDresolves (see the table above).WriteKeyis a string starting withbxw_or aSecret.ApiUrlstarts withhttp://orhttps://.
If everything passes in Studio without TrackInStudio, Init returns true and stops there: nothing is tracked, no remote configuration is fetched and no shutdown handler is bound. Otherwise the SDK starts its loop, binds its PlayerAdded, PlayerRemoving, marketplace and BindToClose handlers, and fetches remote configuration.
The bridge has its own checks, which run after analytics in Start. See the bridge reference.