AnalyticsService
Note This service should only be used by developers who are enrolled in the PlayFab program.
The AnalyticsService provides developers with out-of-the-box analytics so they can improve their games.
Developers can report events and see visual analysis results on the PlayFab webpage.
Summary
Properties
Methods
Fires a custom event with a custom event name and data.
Fire an event used to track player actions pertaining to the in-game economy.
Fire a log event used to track errors and warnings experienced by players.
Fire an event used to track player progression through the game.
Events
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)
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)