Analytics Service
摘要
方法
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 参考
属性
Api Key
方法
Fire Custom Event
Fire Event
Fire In Game Economy Event
Fire Log Event
Fire Player Progression Event
Get Player Segments Async
参数
代码示例
使用玩家细分配置服务器端体验
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("为", player.Name, "显示额外的入职培训")
end
if segments.ActivePayerStatus == Enum.ActivePayerStatus.Top15Percent then
print("向", player.Name, "展示高价值优惠")
end
end
Players.PlayerAdded:Connect(configurePlayerExperience)Log Custom Event
Analytics Service: Log Custom Event(
):()
参数
| 默认值:1 |
| 默认值:nil |
返回
()
代码示例
记录自定义事件
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 = "任务"
prompt.Parent = missionBoard
prompt.Triggered:Connect(function(player)
local startTime = missionStartTimes[player]
if startTime == nil then
-- 玩家接受任务
missionStartTimes[player] = os.clock()
AnalyticsService:LogCustomEvent(
player,
"MissionStarted" -- 自定义事件名称
)
else
-- 玩家提交任务
missionStartTimes[player] = nil
AnalyticsService:LogCustomEvent(
player,
"MissionCompletedDuration", -- 自定义事件名称
os.clock() - startTime -- 聚合中使用的事件值:任务所花费的秒数
)
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
):()
参数
| 默认值:nil |
返回
()
代码示例
跟踪应用内购买
local AnalyticsService = game:GetService("AnalyticsService")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local COIN_BUNDLE_PRODUCT_ID = 123456 -- 替换为您的开发者产品ID
local COINS_IN_BUNDLE = 1000
-- 代表您自己的数据存储:每个玩家拥有多少金币
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_IN_BUNDLE, -- 捆绑包中的金币数量
balance, -- 交易后的余额
Enum.AnalyticsEconomyTransactionType.IAP.Name,
"1000CoinBundle" -- 金币捆绑包的唯一标识符
)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
endLog Funnel Step Event
返回
()
代码示例
跟踪商店步骤
local AnalyticsService = game:GetService("AnalyticsService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FUNNEL_NAME = "ArmoryCheckout" -- 漏斗名称,用于将步骤分组在一起
-- 客户端可以报告的每个操作的步骤编号和名称
local STEPS = {
OpenStore = { number = 1, name = "打开商店" },
ViewItem = { number = 2, name = "查看物品" },
AddToCart = { number = 3, name = "添加到购物车" },
}
-- 客户端在使用商店 UI 时以 "OpenStore", "ViewItem" 或 "AddToCart" 触发此事件
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
-- 每次商店打开时开始一个新的结账会话
funnelSessionIds[player] = HttpService:GenerateGUID()
end
local funnelSessionId = funnelSessionIds[player]
if funnelSessionId == nil then
return
end
AnalyticsService:LogFunnelStepEvent(
player,
FUNNEL_NAME,
funnelSessionId, -- 此唯一结账会话的漏斗会话 ID
step.number, -- 步骤编号
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
):()
参数
| 默认值:nil |
返回
()
Log Onboarding Funnel Step Event
Analytics Service: Log Onboarding Funnel Step Event(
):()
参数
| 默认值:nil |
返回
()
代码示例
跟踪入职步骤
local AnalyticsService = game:GetService("AnalyticsService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- 客户端在玩家在入职 UI 中选择职业后触发此事件
local chooseClassEvent = Instance.new("RemoteEvent")
chooseClassEvent.Name = "ChooseClass"
chooseClassEvent.Parent = ReplicatedStorage
Players.PlayerAdded:Connect(function(player)
-- 记录 FTUE 的第一步
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
1, -- 步骤编号
"Joined Game" -- 步骤名称
)
end)
chooseClassEvent.OnServerEvent:Connect(function(player)
-- 记录 FTUE 的第二步
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
2, -- 步骤编号
"Choose Class" -- 步骤名称
)
end)Log Progression Complete Event
Analytics Service: Log Progression Complete Event(
):()
参数
| 默认值:nil |
返回
()
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
):()
参数
| 默认值:nil |
返回
()
Log Progression Fail Event
Analytics Service: Log Progression Fail Event(
):()
参数
| 默认值:nil |
返回
()
Log Progression Start Event
Analytics Service: Log Progression Start Event(
):()
参数
| 默认值:nil |
返回
()