AnalyticsService

Show Deprecated
Service
Deprecated

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 PlayFab webpage. For more information on how to enroll in the PlayFab Program, take a look at this DevForum post.

Summary

Properties

Methods

FireCustomEvent(player: Instance, eventCategory: string, customData: Variant): void  

Fires a custom event with a custom event name and data.

FireInGameEconomyEvent(player: Instance, itemName: string, economyAction: AnalyticsEconomyAction, itemCategory: string, amount: number, currency: string, location: Variant, customData: Variant): void  

Fire an event used to track player actions pertaining to the in-game economy.

FireLogEvent(player: Instance, logLevel: AnalyticsLogLevel, message: string, debugInfo: Variant, customData: Variant): void  

Fire a log event used to track errors and warnings experienced by players.

FirePlayerProgressionEvent(player: Instance, category: string, progressionStatus: AnalyticsProgressionStatus, location: Variant, statistics: Variant, customData: Variant): void  

Fire an event used to track player progression through the game.

Events

Properties

Methods

FireCustomEvent

void

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.

ParametersMaximum Number of Characters
customData Variant500 after serialized
other string types50

See also:

Parameters

player: Instance

The player who triggered the custom event. nil if not player related.

eventCategory: string

User defined category. This should be the name of the event.

customData: Variant

Optional. User defined data, could be a string, a number or a table.


Returns

void

Code Samples

Analytics Event - Custom

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

void

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.

ParametersMaximum Number of Characters
customData Variant500 after serialized
other string types50

See also:

Parameters

player: Instance

The player who triggered the economy event.

itemName: string

The name of the item.

economyAction: AnalyticsEconomyAction

Indicates the acquisition or spending of an in game resource.

itemCategory: string

A user defined category for items such as "Vehicle," "Weapon.".

amount: number

The amount of the currency.

currency: string

The currency used. Examples: 'gold', 'gems', 'life.'.

location: Variant

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"
}
customData: Variant

Optional. User defined data, could be a string, a number or a table.


Returns

void

No return.

Code Samples

Analytics Event - Economy

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

void

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.

ParametersMaximum Number of Characters
FireLogEvent stackTrace1000
FireLogEvent message500
customData Variant500 after serialized
other string types50

See also:

Parameters

player: Instance

The player who triggered the error event, nil if not player related.

The specified log level (e.g. Debug, Error).

message: string

User defined message.

debugInfo: Variant

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()
}
customData: Variant

Optional. User defined data, could be a string, a number or a table.


Returns

void

No return.

Code Samples

Analytics Event - Log

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

void

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.

ParametersMaximum Number of Characters
FirePlayerProgressionEvent location5 pairs of Key and Value, each Key and Value are 50
FirePlayerProgressionEvent statistics5 pairs of Key and Value, each Key and Value are 50
customData Variant500 after serialized
other string types50

See also:

Parameters

player: Instance

The player who triggered the event.

category: string

A user defined category for progression.

progressionStatus: AnalyticsProgressionStatus

Indicates the status of the progression.

location: Variant

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"
}
statistics: Variant

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
}
customData: Variant

Optional. User defined data, could be a string, a number or a table.


Returns

void

No return.

Code Samples

Analytics Event - Progression

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)

Events