AnalyticsService
AnalyticsService is a collection of methods that allows developers to track how users interact with their experiences, specifically player progression, in-experience economy, funnels, and custom events.
Summary
Properties
PlayFab API key. Must be set in order to use FireEvent.
Methods
Fires a custom event with a custom event name and data.
Report a custom event to PlayFab.
- FireInGameEconomyEvent(player : Instance,itemName : string,economyAction : Enum.AnalyticsEconomyAction,itemCategory : string,amount : number,currency : string,location : Variant,customData : Variant):()
Fire an event used to track player actions pertaining to the in-game economy.
- FireLogEvent(player : Instance,logLevel : Enum.AnalyticsLogLevel,message : string,debugInfo : Variant,customData : Variant):()
Fire a log event used to track errors and warnings experienced by players.
- FirePlayerProgressionEvent(player : Instance,category : string,progressionStatus : Enum.AnalyticsProgressionStatus,location : Variant,statistics : Variant,customData : Variant):()
Fire an event used to track player progression through the game.
Logs an event used to track custom metrics of a user in experience.
- LogEconomyEvent(player : Player,flowType : Enum.AnalyticsEconomyFlowType,currencyType : string,amount : number,endingBalance : number,transactionType : string,itemSku : string,customFields : Dictionary):()
Logs an event used to track player actions related in experience.
- LogFunnelStepEvent(player : Player,funnelName : string,funnelSessionId : string,step : number,stepName : string,customFields : Dictionary):()
Logs an event used to track user actions stepping through a pre-planned funnel.
- LogOnboardingFunnelStepEvent(player : Player,step : number,stepName : string,customFields : Dictionary):()
Logs an event used to track user actions stepping through an onboarding funnel.
- LogProgressionCompleteEvent(player : Player,progressionPathName : string,level : number,levelName : string,customFields : Dictionary):()
Logs an event for when a user has completed a level attempt.
- LogProgressionEvent(player : Player,progressionPathName : string,status : Enum.AnalyticsProgressionType,level : number,levelName : string,customFields : Dictionary):()
Logs an event for when a user has started, completed, or failed a level attempt.
- LogProgressionFailEvent(player : Player,progressionPathName : string,level : number,levelName : string,customFields : Dictionary):()
Logs an event for when a user has failed a level attempt.
- LogProgressionStartEvent(player : Player,progressionPathName : string,level : number,levelName : string,customFields : Dictionary):()
Logs an event for when a user has started a level attempt.
Properties
Methods
FireCustomEvent
This function triggers a custom event with a custom event name data.
Limits of events
Each game server is allowed a certain number of standard events API calls based on the number of players present (more players means more events will be needed). The events that exceed the limit will be dropped and log an error to the developer console. - Per minute limit: 120 + numPlayers * 20, all events shared this limit. - Cooldown: refresh every 10 seconds
Limits of parameters
Limit the size of parameters. The event that exceeds the limit will be dropped and log an error to the developer console.
Parameters | Maximum Number of Characters |
---|---|
customData Variant | 500 after serialized |
other string types | 50 |
See also:
- AnalyticsService:FirePlayerProgressionEvent(), triggers an event used to track player progression through the game
- AnalyticsService:FireInGameEconomyEvent(), triggers an event used to track player actions pertaining to the in-game economy
- AnalyticsService:FireLogEvent(), triggers an event used to track errors and warnings experienced by players
Parameters
The player who triggered the custom event. nil if not player related.
User defined category. This should be the name of the event.
Optional. User defined data, could be a string, a number or a table.
Returns
Code Samples
local AnalyticsService = game:GetService("AnalyticsService")
local Players = game:GetService("Players")
-- server event, report a new server started
local serverInfo = {
Time = os.time(),
PlaceId = game.PlaceId,
}
AnalyticsService:FireCustomEvent(nil, "ServerStart", serverInfo)
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local customData = {
Time = os.time(),
Message = message,
}
AnalyticsService:FireCustomEvent(player, "PlayerChatted", customData)
end)
end)
FireEvent
FireEvent reports a custom event to PlayFab. The event is reported using a category and value, where the category is a string and the value can be a string or table. In order to use PlayFab, you must have a valid ApiKey set.
Possible Errors
- "AnalyticsService can only be executed by game server." – Tracking can only be done on the server through a Script or ModuleScript required by a script. See RunService:IsServer().
- "The ApiKey is invalid." – The ApiKey has been set, but it's invalid. Check that it is set to the correct value.
- "AnalyticsService can only accept valid UTF-8 characters." – Thrown when the value can't be serialized as UTF-8 characters. This can happen if you pass a value which has unicode characters, like emojis.
- "AnalyticsService failed in parse event value. Error: ..." – Thrown when there is an issue when serializing the provided value into a string.
- "AnalyticsService: , " and \r\n are not allowed in category." – The comma ,, the double quote ", and newline characters \r\n cannot be used in the category parameter.
- "AnalyticsService: The event value you fired is too long." – Thrown if the value parameter was too long after serialization. The length limit is 1 KB, or 1024 bytes.
Parameters
'The category of event to report. Cannot contain the following characters: comma ,, double quote " or newline characters \r\n'.
A value to be serialized and reported. Serialized length must not exceed 1 KB, or 1024 bytes.
Returns
FireInGameEconomyEvent
This function triggers an event used to track player actions pertaining to the in-game economy.
For example, it should be called to track when players acquire or spend virtual items within the economy like currency.
Limits of events
Each game server is allowed a certain number of standard events API calls based on the number of players present (more players means more events will be needed). The events that exceed the limit will be dropped and log an error to the developer console. - Per minute limit: 120 + numPlayers * 20, all events shared this limit. - Cooldown: refresh every 10 seconds
Limits of parameters
Limit the size of parameters. The event that exceeds the limit will be dropped and log an error to the developer console.
Parameters | Maximum Number of Characters |
---|---|
customData Variant | 500 after serialized |
other string types | 50 |
See also:
- AnalyticsService:FirePlayerProgressionEvent(), triggers an event used to track player progression through the game
- AnalyticsService:FireLogEvent(), triggers an event used to track errors and warnings experienced by players
- AnalyticsService:FireCustomEvent(), triggers an event used to emit a custom event
Parameters
The player who triggered the economy event.
The name of the item.
Indicates the acquisition or spending of an in game resource.
A user defined category for items such as "Vehicle," "Weapon.".
The amount of the currency.
The currency used. Examples: 'gold', 'gems', 'life.'.
The event location. A dictionary that each key-value represents an entry of location data. The key-value is a string-string pair. With this you can query which are the most popular "stores" then maybe you want to increase/lower the price for the stores.
See the example below:
local location = {["placeDesc"] = "Dungeon1",["levelDesc"] = "level2",["mapDesc"] = "LeftChamberMap",["storeName"] = "DarkSmith",["userDefindKey"] = "0005"}
Optional. User defined data, could be a string, a number or a table.
Returns
No return.
Code Samples
local AnalyticsService = game:GetService("AnalyticsService")
local gold = script.Parent
gold.Touched:Connect(function(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player == nil then
return
end
local location = {
["Map"] = "someMap",
["Position"] = tostring(gold.Position),
}
AnalyticsService:FireInGameEconomyEvent(
player,
"Sword", -- item name
Enum.AnalyticsEconomyAction.Spend,
"Weapon", -- itemCategory
2020, -- amount of Gold
"Gold", -- currency
location,
{ SomeCustomKey = "SomeCustomValue" }
) -- optional customData
end)
FireLogEvent
This function triggers an event used to track errors and warnings experienced by players.
For example, it could be called to indicate when a function call fails - such as a datastore save or TeleportService:Teleport(). See the example below.
Limits of events
Each game server is allowed a certain number of standard events API calls based on the number of players present (more players means more events will be needed). The events that exceed the limit will be dropped and log an error to the developer console. - Per minute limit: 120 + numPlayers * 20, all events shared this limit. - Cooldown: refresh every 10 seconds
Limits of parameters
Limit the size of parameters. The event that exceeds the limit will be dropped and log an error to the developer console.
Parameters | Maximum Number of Characters |
---|---|
FireLogEvent stackTrace | 1000 |
FireLogEvent message | 500 |
customData Variant | 500 after serialized |
other string types | 50 |
See also:
- AnalyticsService:FireInGameEconomyEvent(), triggers an event used to track player actions pertaining to the in-game economy
- AnalyticsService:FirePlayerProgressionEvent(), triggers an event used to track player progression through the game
- AnalyticsService:FireCustomEvent(), triggers an event used to emit a custom event
Parameters
The player who triggered the error event, nil if not player related.
The specified log level (e.g. Debug, Error).
User defined message.
Optional. A dictionary which contains predefined keys including "errorCode" and "stackTrace". Both keys values are strings. stackTrace is a traceback of the current function call stack.
local debugInfo = {errorCode = '123',stackTrace = debug.traceback()}
Optional. User defined data, could be a string, a number or a table.
Returns
No return.
Code Samples
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local AnalyticsService = game:GetService("AnalyticsService")
local placeId = game.PlaceId
local player = Players:GetPlayerByUserId(123)
xpcall(function()
TeleportService:Teleport(placeId, player)
end, function(errorMessage)
local debugInfo = {
errorCode = "TeleportFailed",
stackTrace = debug.traceback(), -- the function call stack
}
AnalyticsService:FireLogEvent(
player,
Enum.AnalyticsLogLevel.Error, -- log level
errorMessage, -- message
debugInfo, -- optional
{
PlayerId = player.UserId,
PlaceId = placeId,
}
) -- customData optional
end)
FirePlayerProgressionEvent
This function triggers an event used to track player progression through the game.
For example, it should be called when a player starts an in-game tutorial and again that player finishes the tutorial. Another example (see below) includes tracking when a player gains experience, collects objects, and levels up.
Limits of events
Each game server is allowed a certain number of standard events API calls based on the number of players present (more players means more events will be needed). The events that exceed the limit will be dropped and log an error to the developer console. - Per minute limit: 120 + numPlayers * 20, all events shared this limit. - Cooldown: refresh every 10 seconds
Limits of parameters
Limit the size of parameters. The event that exceeds the limit will be dropped and log an error to the developer console.
Parameters | Maximum Number of Characters |
---|---|
FirePlayerProgressionEvent location | 5 pairs of Key and Value, each Key and Value are 50 |
FirePlayerProgressionEvent statistics | 5 pairs of Key and Value, each Key and Value are 50 |
customData Variant | 500 after serialized |
other string types | 50 |
See also:
- AnalyticsService:FireInGameEconomyEvent(), triggers an event used to track player actions pertaining to the in-game economy
- AnalyticsService:FireLogEvent(), triggers an event used to track errors and warnings experienced by players
- AnalyticsService:FireCustomEvent(), triggers an event used to emit a custom event
Parameters
The player who triggered the event.
A user defined category for progression.
Indicates the status of the progression.
The event location. A dictionary that each key-value represents an entry of location data. The key-value is a string-string pair. With this developers can query where is the most frequent location for a specific progression event category. For example, the category could be "LevelUp".
local location = {["placeDesc"] = "Dungeon1",["levelDesc"] = "level2",["mapDesc"] = "LeftChamberMap",["ProgresionType"] = "LevelUp",["userDefindKey5"] = "0005"}
Optional. A dictionary that each key-value represents an entry of statistics data that allows developers to track any specific data that they want to collect as players progress through their game. Key-Value is a string-number pair.
local statistics = {["numberOfKills"] = 111,["numberOfExp"] = 222,["userDefindKey3"] = number,["userDefindKey4"] = number,["userDefindKey5"] = number}
Optional. User defined data, could be a string, a number or a table.
Returns
No return.
Code Samples
local AnalyticsService = game:GetService("AnalyticsService")
local Players = game:GetService("Players")
local wisdomStone = script.Parent
wisdomStone.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player == nil then
return
end
local location = {
["placeDesc"] = "Dungeon1",
["mapDesc"] = "LeftChamberMap",
}
local statistics = {
["amountOfExp"] = 1337,
["amountOfGold"] = 1337,
["kills"] = 1337,
}
AnalyticsService:FirePlayerProgressionEvent(
player,
Enum.AnalyticsProgressionStatus.Complete, -- progressionStatus
"LevelUp", -- category
location,
statistics, -- optional
{ AcquireType = "PickUp" }
) -- customData optional
end)
LogCustomEvent
Logs an event used to track custom metrics of a user in experience. For additional information, see Custom Events.
Parameters
The user who triggered the event.
The name of the custom event.
The value of the event that will be used in aggregation.
Optional dictionary of custom fields that will provide breakdowns in Roblox-provided charts. Only specific keys, provided by Enum.AnalyticsCustomFieldKeys, will be used for these breakdowns. Limited to 8,000 unique combinations of values across the three custom fields per experience.
Returns
Code Samples
This example uses AnalyticsService:LogCustomEvent() to log two custom events: MissionStarted and MissionCompletedDuration.
local AnalyticsService = game:GetService("AnalyticsService")
-- Log when the mission starts
AnalyticsService:LogCustomEvent(
player,
"MissionStarted" -- Custom event name
)
-- Log when the mission is completed with the time it took
AnalyticsService:LogCustomEvent(
player,
"MissionCompletedDuration", -- Custom event name
120 -- Event value used in aggregation
)
LogEconomyEvent
Logs an event used to track player actions related in experience.
Parameters
The user who triggered the event.
Should specify the direction that currency is flowing using Enum.AnalyticsEconomyFlowType.
The name of the currency being added or removed, for example "gold", "gems", or "energy". Limited to 5 unique currency types per experience.
The amount of currency being added or removed. This value should always be positive.
The user's balance after the currency has been added or removed. This value should always be greater than or equal to 0.
The type of transaction that occurred. While you're free to use any transaction type, it's recommended to use the provided types from Enum.AnalyticsEconomyTransactionType such as "IAP" or "ContextualPurchase" to enable future insights from Roblox tools and charts.
Because this field type is a string, you'll need to pass the Name value of the enum. For example Enum.AnalyticsEconomyTransactionType.IAP.Name.
Limited to 20 unique types per experience.
Optional SKU of the item or bundle being purchased. This is a unique identifier for the item being purchased. Limited to 100 unique SKUs per experience.
Optional dictionary of custom fields that will provide breakdowns in Roblox-provided charts. Only specific keys, provided by Enum.AnalyticsCustomFieldKeys, will be used for these breakdowns. Limited to 8,000 unique combinations of values across the three custom fields per experience.
Returns
Code Samples
The following sample tracks a Robux purchase of a 1000-coin bundle, using the IAP (in-app purchase) transaction type. Note the item name provided as an optional parameter when compared to the previous sample.
local AnalyticsService = game:GetService("AnalyticsService")
AnalyticsService:LogEconomyEvent(
player,
Enum.AnalyticsEconomyFlowType.Source,
"Coins",
1000, -- How many coins are in the bundle
1020, -- balance after transaction
Enum.AnalyticsEconomyTransactionType.IAP.Name,
"1000CoinBundle" -- Unique identifier of the coin bundle
)
LogFunnelStepEvent
Logs an event used to track user actions stepping through a pre-planned funnel. Funnel breakdowns will only consider the user and event values from the first step in a funnel session.
Parameters
The user who triggered the event.
The name of the funnel. This should be the same for all steps in the funnel. Limited to 10 unique funnels per experience.
Optional unique identifier for the funnel session. This should be the same for all steps in the funnel.
Note that this field is only necessary for recurring funnels, for example a purchase flow funnel or an item upgrade funnel. If you don't have a natural funnel session identifier, it's recommended to use HttpService:GenerateGUID().
The step number in the funnel. This should be unique for each step in the funnel. All funnels start at step 1. Limited to steps 1-100.
Repeated steps by the same user in the same funnel session, or when funnelSessionId is nil will be ignored.
Note that if any steps are skipped, the intermediate steps will be considered completed.
Optional name of the step in the funnel. This field is only used for display purposes in Roblox-provided charts.
Optional dictionary of custom fields that will provide breakdowns in Roblox-provided charts. Only specific keys, provided by Enum.AnalyticsCustomFieldKeys, will be used for these breakdowns. Limited to 8,000 unique combinations of values across the three custom fields per experience.
Returns
Code Samples
The following sample tracks some basic events for each user beginning the process to buy an item from an "armory" shop. Note the funnelSessionId used to distinguish between different sessions of the same user opening the shop.
local AnalyticsService = game:GetService("AnalyticsService")
local HttpService = game:GetService("HttpService")
funnelSessionId = HttpService:GenerateGUID()
-- Log when the user opens the store
AnalyticsService:LogFunnelStepEvent(
player,
"ArmoryCheckout", -- Funnel name used to group steps together
funnelSessionId, -- Funnel session id for this unique checkout session
1, -- Step number
"Opened Store" -- Step name
)
-- Log when the user views an item
AnalyticsService:LogFunnelStepEvent(
player,
"ArmoryCheckout", -- Funnel name used to group steps together
funnelSessionId, -- Funnel session id for this unique checkout session
2, -- Step number
"Viewed Item" -- Step name
)
-- Log when the user views adds to cart
AnalyticsService:LogFunnelStepEvent(
player,
"ArmoryCheckout", -- Funnel name used to group steps together
funnelSessionId, -- Funnel session id for this unique checkout session
3, -- Step number
"Added to Cart" -- Step name
)
LogOnboardingFunnelStepEvent
Logs an event used to track user actions stepping through an onboarding funnel. Funnel breakdowns will only consider the user and event values from the first step in a funnel session.
Parameters
The user who triggered the event.
The step number in the funnel. This should be unique for each step in the funnel. All funnels start at step 1. Limited to steps 1-100.
Note that if any steps are skipped, the intermediate steps will be considered completed.
Optional name of the step in the funnel. This field is only used for display purposes in Roblox-provided charts.
Optional dictionary of custom fields that will provide breakdowns in Roblox-provided charts. Only specific keys, provided by Enum.AnalyticsCustomFieldKeys, will be used for these breakdowns. Limited to 8,000 unique combinations of values across the three custom fields per experience.
Returns
Code Samples
The following sample demonstrates how to log two steps of an onboarding funnel. An onboarding funnel typically introduces players to the game's core loop.
local AnalyticsService = game:GetService("AnalyticsService")
-- Log the first step of the FTUE
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
1, -- Step number
"Joined Game" -- Step name
)
-- Log the second step of the FTUE
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
2, -- Step number
"Choose Class" -- Step name
)
LogProgressionCompleteEvent
Logs an event for when a user has completed a level attempt. This event does not currently display in any Roblox-provided charts.
Parameters
The player who triggered the event.
Returns
LogProgressionEvent
Logs an event for when a user has started, completed, or failed a level attempt. This event does not currently display in any Roblox-provided charts.
Parameters
The player who triggered the event.
Returns
LogProgressionFailEvent
Logs an event for when a user has failed a level attempt. This event does not currently display in any Roblox-provided charts.
Parameters
The user who triggered the event.
Returns
LogProgressionStartEvent
Logs an event for when a user has started a level attempt. This event does not currently display in any Roblox-provided charts.
Parameters
The player who triggered the event.