AnalyticsService

Show Deprecated
Not Creatable
Service
Not Replicated

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

  • Deprecated
    Local User Security
    Read Parallel

    PlayFab API key. Must be set in order to use FireEvent.

Methods

Properties

ApiKey

Deprecated
Local User Security
Read Parallel

The ApiKey property contains the game's PlayFab API key. It must be set and valid in order to use FireEvent. It can be set by pasting and editing the following line of code into the Command bar:


game:GetService("AnalyticsService").ApiKey = "API_KEY"

Methods

FireCustomEvent

()
Deprecated

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.

Default Value: ""
eventCategory: string

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

Default Value: ""
customData: Variant

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

Default Value: ""

Returns

()

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)

FireEvent

()
Deprecated

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

category: string

'The category of event to report. Cannot contain the following characters: comma ,, double quote " or newline characters \r\n'.

Default Value: ""
value: Variant

A value to be serialized and reported. Serialized length must not exceed 1 KB, or 1024 bytes.

Default Value: ""

Returns

()

FireInGameEconomyEvent

()
Deprecated

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.

Default Value: ""
itemName: string

The name of the item.

Default Value: ""

Indicates the acquisition or spending of an in game resource.

Default Value: ""
itemCategory: string

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

Default Value: ""
amount: number

The amount of the currency.

Default Value: ""
currency: string

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

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

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

Default Value: ""

Returns

()

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

()
Deprecated

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.

Default Value: ""

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

Default Value: ""
message: string

User defined message.

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

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

Default Value: ""

Returns

()

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

()
Deprecated

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.

Default Value: ""
category: string

A user defined category for progression.

Default Value: ""

Indicates the status of the progression.

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

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

Default Value: ""

Returns

()

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)

LogCustomEvent

()

Logs an event used to track custom metrics of a user in experience. For additional information, see Custom Events.

Parameters

player: Player

The user who triggered the event.

Default Value: ""
eventName: string

The name of the custom event.

Default Value: ""
value: number

The value of the event that will be used in aggregation.

Default Value: 1
customFields: Dictionary

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.

Default Value: "nil"

Returns

()

Code Samples

This example uses AnalyticsService:LogCustomEvent() to log two custom events: MissionStarted and MissionCompletedDuration.

Log Custom Event

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

player: Player

The user who triggered the event.

Default Value: ""

Should specify the direction that currency is flowing using Enum.AnalyticsEconomyFlowType.

Default Value: ""
currencyType: string

The name of the currency being added or removed, for example "gold", "gems", or "energy". Limited to 5 unique currency types per experience.

Default Value: ""
amount: number

The amount of currency being added or removed. This value should always be positive.

Default Value: ""
endingBalance: number

The user's balance after the currency has been added or removed. This value should always be greater than or equal to 0.

Default Value: ""
transactionType: string

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.

Default Value: ""
itemSku: string

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.

Default Value: ""
customFields: Dictionary

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.

Default Value: "nil"

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.

Tracking an in-app purchase

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

player: Player

The user who triggered the event.

Default Value: ""
funnelName: string

The name of the funnel. This should be the same for all steps in the funnel. Limited to 10 unique funnels per experience.

Default Value: ""
funnelSessionId: string

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().

Default Value: ""
step: number

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.

Default Value: 1
stepName: string

Optional name of the step in the funnel. This field is only used for display purposes in Roblox-provided charts.

Default Value: ""
customFields: Dictionary

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.

Default Value: "nil"

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.

Tracking Shop steps

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

player: Player

The user who triggered the event.

Default Value: ""
step: number

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.

Default Value: ""
stepName: string

Optional name of the step in the funnel. This field is only used for display purposes in Roblox-provided charts.

Default Value: ""
customFields: Dictionary

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.

Default Value: "nil"

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.

Tracking onboarding steps

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

player: Player

The player who triggered the event.

Default Value: ""
progressionPathName: string
Default Value: ""
level: number
Default Value: ""
levelName: string
Default Value: ""
customFields: Dictionary
Default Value: "nil"

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

player: Player

The player who triggered the event.

Default Value: ""
progressionPathName: string
Default Value: ""
Default Value: ""
level: number
Default Value: ""
levelName: string
Default Value: ""
customFields: Dictionary
Default Value: "nil"

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

player: Player

The user who triggered the event.

Default Value: ""
progressionPathName: string
Default Value: ""
level: number
Default Value: ""
levelName: string
Default Value: ""
customFields: Dictionary
Default Value: "nil"

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

player: Player

The player who triggered the event.

Default Value: ""
progressionPathName: string
Default Value: ""
level: number
Default Value: ""
levelName: string
Default Value: ""
customFields: Dictionary
Default Value: "nil"

Returns

()

Events