AnalyticsService
無法建立
服務
未複製

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡。


概要

屬性
ApiKey:string
已棄用
方法
FireCustomEvent(player: Instance,eventCategory: string,customData: Variant):()
已棄用
FireEvent(category: string,value: 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):()
已棄用
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 參考
屬性
ApiKey
已棄用

方法
FireCustomEvent
已棄用

FireEvent
已棄用

FireInGameEconomyEvent
已棄用

FireLogEvent
已棄用

FirePlayerProgressionEvent
已棄用

GetPlayerSegmentsAsync
暫停
功能: Basic
AnalyticsService:GetPlayerSegmentsAsync(player:Player):Dictionary
參數
player:Player
範例程式碼
配置伺服器端體驗與玩家區段
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)

LogCustomEvent
功能: Basic
AnalyticsService:LogCustomEvent(
player:Player, eventName:string, value:number, customFields:Dictionary
):()
參數
player:Player
eventName:string
value:number
預設值:1
customFields:Dictionary
預設值: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)

LogEconomyEvent
功能: Basic
AnalyticsService:LogEconomyEvent(
player:Player, flowType:Enum.AnalyticsEconomyFlowType, currencyType:string, amount:number, endingBalance:number, transactionType:string, itemSku:string, customFields:Dictionary
):()
參數
player:Player
currencyType:string
amount:number
endingBalance:number
transactionType:string
itemSku:string
customFields: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
end

LogFunnelStepEvent
功能: Basic
AnalyticsService:LogFunnelStepEvent(
player:Player, funnelName:string, funnelSessionId:string, step:number, stepName:string, customFields:Dictionary
):()
參數
player:Player
funnelName:string
funnelSessionId:string
step:number
預設值:1
stepName:string
customFields:Dictionary
預設值:nil
返回
()
範例程式碼
追蹤商店步驟
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)

LogJourneyEvent
功能: Basic
AnalyticsService:LogJourneyEvent(
player:Player, journeyName:string, nodeName:string, journeySessionId:string, customFields:Dictionary
):()
參數
player:Player
journeyName:string
nodeName:string
journeySessionId:string
customFields:Dictionary
預設值:nil
返回
()

LogOnboardingFunnelStepEvent
功能: Basic
AnalyticsService:LogOnboardingFunnelStepEvent(
player:Player, step:number, stepName:string, customFields:Dictionary
):()
參數
player:Player
step:number
stepName:string
customFields:Dictionary
預設值: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)

LogProgressionCompleteEvent
功能: Basic
AnalyticsService:LogProgressionCompleteEvent(
player:Player, progressionPathName:string, level:number, levelName:string, customFields:Dictionary
):()
參數
player:Player
progressionPathName:string
level:number
levelName:string
customFields:Dictionary
預設值:nil
返回
()

LogProgressionEvent
功能: Basic
AnalyticsService:LogProgressionEvent(
player:Player, progressionPathName:string, status:Enum.AnalyticsProgressionType, level:number, levelName:string, customFields:Dictionary
):()
參數
player:Player
progressionPathName:string
level:number
levelName:string
customFields:Dictionary
預設值:nil
返回
()

LogProgressionFailEvent
功能: Basic
AnalyticsService:LogProgressionFailEvent(
player:Player, progressionPathName:string, level:number, levelName:string, customFields:Dictionary
):()
參數
player:Player
progressionPathName:string
level:number
levelName:string
customFields:Dictionary
預設值:nil
返回
()

LogProgressionStartEvent
功能: Basic
AnalyticsService:LogProgressionStartEvent(
player:Player, progressionPathName:string, level:number, levelName:string, customFields:Dictionary
):()
參數
player:Player
progressionPathName:string
level:number
levelName:string
customFields:Dictionary
預設值:nil
返回
()

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。