Analytics Service
Summary
Methods
FireCustomEvent(player: Instance,eventCategory: string,customData: Variant):() |
FireInGameEconomyEvent(player: Instance,itemName: string,economyAction: Enum.AnalyticsEconomyAction,itemCategory: string,amount: number,currency: string,location: Variant,customData: Variant):() |
FireLogEvent(player: Instance,logLevel: Enum.AnalyticsLogLevel,message: string,debugInfo: Variant,customData: Variant):() |
FirePlayerProgressionEvent(player: Instance,category: string,progressionStatus: Enum.AnalyticsProgressionStatus,location: Variant,statistics: Variant,customData: Variant):() |
GetPlayerSegmentsAsync(player: Player):Dictionary |
LogCustomEvent(player: Player,eventName: string,value: number,customFields: Dictionary):() |
LogEconomyEvent(player: Player,flowType: Enum.AnalyticsEconomyFlowType,currencyType: string,amount: number,endingBalance: number,transactionType: string,itemSku: string,customFields: Dictionary):() |
LogFunnelStepEvent(player: Player,funnelName: string,funnelSessionId: string,step: number,stepName: string,customFields: Dictionary):() |
LogJourneyEvent(player: Player,journeyName: string,nodeName: string,journeySessionId: string,customFields: Dictionary):() |
LogOnboardingFunnelStepEvent(player: Player,step: number,stepName: string,customFields: Dictionary):() |
LogProgressionCompleteEvent(player: Player,progressionPathName: string,level: number,levelName: string,customFields: Dictionary):() |
LogProgressionEvent(player: Player,progressionPathName: string,status: Enum.AnalyticsProgressionType,level: number,levelName: string,customFields: Dictionary):() |
LogProgressionFailEvent(player: Player,progressionPathName: string,level: number,levelName: string,customFields: Dictionary):() |
LogProgressionStartEvent(player: Player,progressionPathName: string,level: number,levelName: string,customFields: Dictionary):() |
API Reference
Properties
Api Key
Methods
Fire Custom Event
Fire Event
Fire In Game Economy Event
Fire Log Event
Fire Player Progression Event
Get Player Segments Async
Parameters
Returns
Code Samples
Configure server-side experiences with player segments
local Players = game:GetService("Players")
local AnalyticsService = game:GetService("AnalyticsService")
local function configurePlayerExperience(player)
local segments = AnalyticsService:GetPlayerSegmentsAsync(player)
if not segments.HasData then
return
end
if segments.WhenUserFirstPlayed == Enum.WhenUserFirstPlayed.Days0To30 then
print("Show additional onboarding for", player.Name)
end
if segments.ActivePayerStatus == Enum.ActivePayerStatus.Top15Percent then
print("Show high-value offer to", player.Name)
end
end
Players.PlayerAdded:Connect(configurePlayerExperience)Log Custom Event
Analytics Service: Log Custom Event(
):()
Parameters
| Default Value: 1 |
| Default Value: nil |
Returns
()
Code Samples
Log Custom Event
local AnalyticsService = game:GetService("AnalyticsService")
local Players = game:GetService("Players")
local missionBoard = script.Parent
local missionStartTimes: { [Player]: number } = {}
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Mission"
prompt.Parent = missionBoard
prompt.Triggered:Connect(function(player)
local startTime = missionStartTimes[player]
if startTime == nil then
-- The player accepts the mission
missionStartTimes[player] = os.clock()
AnalyticsService:LogCustomEvent(
player,
"MissionStarted" -- Custom event name
)
else
-- The player turns the mission in
missionStartTimes[player] = nil
AnalyticsService:LogCustomEvent(
player,
"MissionCompletedDuration", -- Custom event name
os.clock() - startTime -- Event value used in aggregation: seconds the mission took
)
end
end)
Players.PlayerRemoving:Connect(function(player)
missionStartTimes[player] = nil
end)Log Economy Event
Analytics Service: Log Economy Event(
player:Player, flow Type:Enum.AnalyticsEconomyFlowType, currency Type:string, amount:number, ending Balance:number, transaction Type:string, item Sku:string, custom Fields:Dictionary
):()
Parameters
| Default Value: nil |
Returns
()
Code Samples
Tracking an in-app purchase
local AnalyticsService = game:GetService("AnalyticsService")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local COIN_BUNDLE_PRODUCT_ID = 123456 -- Replace with the ID of your developer product
local COINS_IN_BUNDLE = 1000
-- Stand-in for your own data storage: how many coins each player has
local coinBalances: { [Player]: number } = {}
MarketplaceService.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == COIN_BUNDLE_PRODUCT_ID then
local balance = (coinBalances[player] or 0) + COINS_IN_BUNDLE
coinBalances[player] = balance
AnalyticsService:LogEconomyEvent(
player,
Enum.AnalyticsEconomyFlowType.Source,
"Coins",
COINS_IN_BUNDLE, -- How many coins are in the bundle
balance, -- balance after transaction
Enum.AnalyticsEconomyTransactionType.IAP.Name,
"1000CoinBundle" -- Unique identifier of the coin bundle
)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
endLog Funnel Step Event
Returns
()
Code Samples
Tracking Shop steps
local AnalyticsService = game:GetService("AnalyticsService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FUNNEL_NAME = "ArmoryCheckout" -- Funnel name used to group steps together
-- Step number and name for each action the client can report
local STEPS = {
OpenStore = { number = 1, name = "Opened Store" },
ViewItem = { number = 2, name = "Viewed Item" },
AddToCart = { number = 3, name = "Added to Cart" },
}
-- The client fires this with "OpenStore", "ViewItem" or "AddToCart" as the shop UI is used
local shopActionEvent = Instance.new("RemoteEvent")
shopActionEvent.Name = "ShopAction"
shopActionEvent.Parent = ReplicatedStorage
local funnelSessionIds: { [Player]: string } = {}
shopActionEvent.OnServerEvent:Connect(function(player, action)
local step = STEPS[action]
if step == nil then
return
end
if action == "OpenStore" then
-- Every time the shop opens starts a new checkout session
funnelSessionIds[player] = HttpService:GenerateGUID()
end
local funnelSessionId = funnelSessionIds[player]
if funnelSessionId == nil then
return
end
AnalyticsService:LogFunnelStepEvent(
player,
FUNNEL_NAME,
funnelSessionId, -- Funnel session ID for this unique checkout session
step.number, -- Step number
step.name -- Step name
)
end)
Players.PlayerRemoving:Connect(function(player)
funnelSessionIds[player] = nil
end)Log Journey Event
Analytics Service: Log Journey Event(
player:Player, journey Name:string, node Name:string, journey Session Id:string, custom Fields:Dictionary
):()
Parameters
| Default Value: nil |
Returns
()
Log Onboarding Funnel Step Event
Analytics Service: Log Onboarding Funnel Step Event(
):()
Parameters
| Default Value: nil |
Returns
()
Code Samples
Tracking onboarding steps
local AnalyticsService = game:GetService("AnalyticsService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- The client fires this once the player picks a class in the onboarding UI
local chooseClassEvent = Instance.new("RemoteEvent")
chooseClassEvent.Name = "ChooseClass"
chooseClassEvent.Parent = ReplicatedStorage
Players.PlayerAdded:Connect(function(player)
-- Log the first step of the FTUE
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
1, -- Step number
"Joined Game" -- Step name
)
end)
chooseClassEvent.OnServerEvent:Connect(function(player)
-- Log the second step of the FTUE
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
2, -- Step number
"Choose Class" -- Step name
)
end)Log Progression Complete Event
Analytics Service: Log Progression Complete Event(
):()
Parameters
| Default Value: nil |
Returns
()
Log Progression Event
Analytics Service: Log Progression Event(
player:Player, progression Path Name:string, status:Enum.AnalyticsProgressionType, level:number, level Name:string, custom Fields:Dictionary
):()
Parameters
| Default Value: nil |
Returns
()
Log Progression Fail Event
Analytics Service: Log Progression Fail Event(
):()
Parameters
| Default Value: nil |
Returns
()
Log Progression Start Event
Analytics Service: Log Progression Start Event(
):()
Parameters
| Default Value: nil |
Returns
()