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, -- 步驟編號
"加入遊戲" -- 步驟名稱
)
end)
chooseClassEvent.OnServerEvent:Connect(function(player)
-- 記錄 FTUE 的第二步
AnalyticsService:LogOnboardingFunnelStepEvent(
player,
2, -- 步驟編號
"選擇職業" -- 步驟名稱
)
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 |
返回
()