Reference
Analytics API reference
Every public function and field of the Analytics module, with parameters, return values, behaviour and an example for each.
This is the complete public API of the Analytics module, version 1.0.0. Require it from server code only:
Unless a function says otherwise:
- it returns nothing and never yields: it validates its arguments and adds an event to the queue;
- an invalid argument drops the call, usually with a warning printed once per server per distinct problem (prefixed
[Bloxlytics]); - before
Start, after a failedStart, or in Studio withoutTrackInStudio, it does nothing.
Every function is called with a colon (Analytics:TrackEvent(…)).
| Function | Section |
|---|---|
Start, Init, Flush, GetStats |
Lifecycle |
SetServerTag |
Server tags |
TrackEvent, TrackFunnel, TrackProgression |
Events |
TrackCurrencyEarned, TrackCurrencySpent, TrackBalance, TrackCurrencyTransfer |
Economy |
WrapProcessReceipt, SetProductNames |
Purchases |
SetPlayerProperty, SetPlayerProperties, SetPlayerRole |
Player properties |
GetVariant |
Experiments |
Version, ServerKey |
Fields |
#Lifecycle
#Start
Starts analytics and, when config.Cmdr is set, the Cmdr bridge. Call it once, from a server Script, as early as possible.
configtablebodyrequiredThe configuration. WriteKey and ApiUrl are required; every field is listed on configuration.
returnsbooleantrue when analytics started (including in Studio, where it then stays idle without TrackInStudio). false when the configuration was rejected, Start or Init was already called, or it isn't running on the server. Bridge problems never change the result.
Behaviour:
- Runs
Initwith the same table. - If
config.Cmdris set, finds a ModuleScript namedCmdrBridgeinside theAnalyticsmodule or next to it, and callsCmdrBridge:InitwithCmdr,BridgeKey,ApiUrl,ProjectID,AllowedGroups,AllowKick,OnWarn,OnAnnounce,AllowSystemCommands,Debug,EnableInStudio = (EnableBridgeInStudio ~= false)andAnalyticsitself. This happens whether or not analytics started, so the bridge can run even when analytics is off. - In Studio, prints this session's server key:
[Bloxlytics] Studio session. Target this server from the website with server "studio-…".
Bridge warnings, each of which leaves analytics unaffected:
Cmdr was passed but the CmdrBridge module wasn't found next to or inside Analytics; remote commands are offCmdr was passed without BridgeKey; remote commands are offCmdr bridge didn't start: <error>, plus the bridge's own[Bloxlytics bridge] Not started: …warnings.
#Init
Starts analytics only. Bridge fields in config are ignored. Prefer Start; use Init if you start CmdrBridge yourself.
configtablebodyrequiredThe same table as Start.
returnsbooleantrue when the configuration is usable, false otherwise.
Behaviour:
- Refuses to run on a client (
The SDK only runs on the server; require it from a server Script) and refuses a second call (Init/Start called twice; ignoring the second call). - Checks the configuration (see validation order). On a problem:
Not started: <problem>. Your game keeps running without analytics. - Removes trailing slashes from
config.ApiUrland replacesconfig.ProjectIDwith the resolved Universe ID, in the table you passed. - In Studio without
TrackInStudio, returnstruehere without starting anything. - Otherwise: applies
FlushInterval(clamped 2–60) andMaxBatchSize(clamped 10–500); on a new thread fetches remote configuration, queues$server_startand starts sessions for players already in the server; connectsPlayerAddedandPlayerRemoving(unlessAutoTrackSessions = false),PromptGamePassPurchaseFinished(unlessAutoTrackGamePasses = false) andPromptProductPurchaseFinished; starts the once-a-second loop for heartbeats, configuration refreshes and flushes; and binds the shutdown flush withgame:BindToClose.
#Flush
Sends queued events now instead of waiting for the next flush interval. Yields while requests are in flight.
It sends batches until the queue is empty or a send fails. It returns immediately if a flush is already running, the SDK isn't enabled, or the SDK is backing off after a failure. You rarely need it: the SDK flushes every few seconds and on shutdown. It is useful just before you teleport every player out of a server. See delivery.
#GetStats
Returns a snapshot of the SDK's state on this server. Works at any time, including before Start.
queuednumberEvents waiting to be sent.
droppednumberEvents dropped since start-up because the queue reached 5,000.
enabledbooleanWhether the SDK is queuing and sending events.
backoffnumberThe current retry delay in seconds (2 to 60), or 0 when the last send succeeded.
#Server tags
#SetServerTag
Sets a short fact about this server, such as the map, mode or region. Tags appear on the server's card in Bloxlytics and can be searched in server pickers. Works before Start, so you can tag a server before its first event.
namestringbodyrequiredStarts with a letter; then letters, digits, spaces and _ . -; at most 32 characters. Otherwise dropped with SetServerTag: invalid tag name <name> (letters, digits, space . _ -, max 32).
valueanybodyConverted with tostring and cut to 64 characters. nil removes the tag.
A server can have at most 16 tags. Adding a 17th is dropped with SetServerTag: at most 16 tags per server; changing an existing tag is always allowed. Tags are sent with $server_start, every heartbeat (so changes appear within about 30 seconds) and every Cmdr bridge poll.
#Events
#TrackEvent
Tracks a custom event. If the first argument is a Player, the arguments are (player, name, properties); otherwise (name, properties, player).
playerPlayerbodyThe player the event is about. Leave it out for server-level events. Anything other than a Player drops the call: TrackEvent(<name>): player must be a Player.
namestringbodyrequiredStarts with a letter; then letters, digits, spaces and _ . : -; at most 64 characters. Otherwise: TrackEvent: invalid event name <name>.
propertiestablebodyUp to 32 properties. Keys start with a letter or _, then letters, digits, spaces and _ . -, at most 40 characters. Values: strings (cut to 256 characters), finite numbers, booleans; EnumItem and Instance values are converted with tostring. Other values are dropped with a warning. Full rules on custom events.
Dropped without a warning when Custom events is off or the name is in Blocked events in the dashboard.
#TrackFunnel
Records a funnel step as a $funnel event.
playerPlayerbodyrequiredFunnels are per player. Without one: TrackFunnel(<funnel>): pass the player so the step can be attributed.
funnelstringbodyrequiredNon-empty; cut to 64 characters.
stepstringbodyrequiredNon-empty; cut to 64 characters. An empty funnel or step: TrackFunnel: funnel and step must be non-empty strings.
indexnumberbodyOptional step number, rounded down, that orders steps in the funnel builder. Must not be negative.
#TrackProgression
Records a $progression event.
playerPlayerbodyrequiredThe player.
statusstringbodyrequired"start", "complete" or "fail".
pathstringbodyrequiredWhat was attempted, such as "World1:Level3". Cut to 128 characters.
scorenumberbodyOptional, finite.
Invalid arguments: TrackProgression(player, 'start'|'complete'|'fail', path, score?).
#Economy
All four functions send economy events, are dropped when Economy is off in the dashboard, and require currency to be a non-empty string (Economy: currency must be a non-empty string). If the dashboard defines currencies and this one isn't among them (ignoring case), the event is still sent but the SDK warns once: Currency "<name>" isn't configured in Bloxlytics → SDK settings; events will be rejected. A missing player or an invalid amount is dropped without a warning. See economy.
#TrackCurrencyEarned
Records a currency source: a $economy event with flow = "source".
playerPlayerbodyrequiredThe player who received the currency.
currencystringbodyrequiredCurrency key, at most 32 characters.
amountnumberbodyrequiredGreater than 0 and finite.
sourcestringbodyCategory, such as "Quests". At most 64 characters (not shortened by the SDK; longer values are rejected by the API).
itemstringbodyWhat earned it. At most 64 characters.
balancenumberbodyThe balance after the change. Finite.
#TrackCurrencySpent
Records a currency sink: a $economy event with flow = "sink". Parameters are the same as TrackCurrencyEarned, with sink in place of source. amount is positive.
#TrackBalance
Records a $balance snapshot without a change.
playerPlayerbodyrequiredThe player.
currencystringbodyrequiredCurrency key.
balancenumberbodyrequiredThe current balance. Finite; zero and negative values are allowed.
#TrackCurrencyTransfer
Records currency moving between players, as a $economy_transfer event belonging to from.
fromPlayerbodyrequiredThe sender.
toPlayer | numberbodyrequiredThe receiver, as a Player or a positive user id.
currencystringbodyrequiredCurrency key.
amountnumberbodyrequiredGreater than 0 and finite.
reasonstringbodySuch as "Trade" or "Gift". At most 64 characters.
#Purchases
Purchase tracking is dropped when Purchases is off in the dashboard. Game pass prompts and developer product prompt attempts are tracked automatically; see purchases.
#WrapProcessReceipt
Wraps your ProcessReceipt handler so granted developer product purchases are recorded.
handlerfunctionbodyrequiredYour existing handler. Anything else raises WrapProcessReceipt expects your ProcessReceipt function. This is the only SDK function that can raise an error.
returnsfunctionA function to assign to MarketplaceService.ProcessReceipt. It calls your handler, and when the decision is PurchaseGranted and the player is in the server, queues a completed $purchase with productId = receipt.ProductId, robux = receipt.CurrencySpent and receiptId = receipt.PurchaseId. It returns your handler's decision unchanged. Recording runs inside pcall; errors from your handler are not caught.
The first receipt for each product may yield while the product's name is looked up with GetProductInfo, unless you named it with SetProductNames.
#SetProductNames
Gives developer products names to use instead of looking them up with MarketplaceService:GetProductInfo. Works before Start.
names{ [number]: string }bodyrequiredDeveloper product id to name. Adds to or replaces names from earlier calls.
Applies to developer products only, not game passes. A product already looked up on this server keeps its cached name, so call it at start-up. Prompt attempts for a named product carry no robux price.
#Player properties
Player properties describe a player: level, rebirths, island, VIP, player type, role. Each one is sent as its own $property event and shown on the player's profile in Players; they can be used in segments and drive player banners. They aren't affected by any tracking switch.
#SetPlayerProperty
playerPlayerbodyrequiredThe player.
keystringbodyrequiredStarts with a letter or _; then letters, digits, spaces and _ . -; at most 40 characters. An invalid key (or a missing player) is dropped with SetPlayerProperty: invalid key <key>.
valuestring | number | booleanbodyrequiredStrings are cut to 256 characters; numbers must be finite. Any other type: SetPlayerProperty(<key>): value must be a string, number or boolean.
#SetPlayerProperties
Calls SetPlayerProperty for each entry, so each property is validated and sent as its own event. There is no 32-property limit here.
playerPlayerbodyrequiredThe player.
propertiestablebodyrequiredKey to value, with the same rules as SetPlayerProperty.
#SetPlayerRole
Reports a verified in-game role. Same as SetPlayerProperty(player, "Role", role). Combine it with a banner rule such as Role equals Moderator to show staff in Bloxlytics.
playerPlayerbodyrequiredThe player.
rolestringbodyrequiredThe role, such as "Moderator". Cut to 256 characters.
#Experiments
#GetVariant
Returns the player's variant of a running experiment, using the same deterministic assignment as Bloxlytics. Logs a $experiment_exposure the first time in each session. Doesn't yield. See experiments.
playerPlayerbodyrequiredThe player. Anything else returns nil, nil.
experimentKeystringbodyrequiredThe experiment's key from the dashboard.
variantstring?The variant key, or nil when the experiment isn't running on this server, the player is outside the allocation, or remote configuration hasn't loaded.
configtable?The variant's config from the dashboard, or nil with variant.
#Fields
Analytics.VersionstringThe module's version, "1.0.0". Sent with every batch and shown as SDK version in the debugger.
Analytics.ServerKeystringThis server's id in Bloxlytics: game.JobId in a live server, or studio- followed by 8 random hex characters in Studio. Set when the module is first required; the Cmdr bridge uses the same value.