BetterAnalyticsService - An AnalyticsService API Wrapper

Roblox recently introduced Economy and Funnel dashboards under Creator Analytics along with some new APIs for AnalyticsService. These events let developers keep track of how in-game currency is being used and monitor player behaviour (For example, 20% of players left the game at stage 7).

I decided to write a simple module that acts as a wrapper for AnalyticsService. It implements better error handling with Pcalls and comes with a debug mode in the config to examine the data being published.

You can get the model on the Creator Store or on Github.

Usage:
local ServerScriptService = game:GetService("ServerScriptService")
local BetterAnalyticsService = require(ServerScriptService.BetterAnalyticsService)

BetterAnalyticsService:LogEconomyEvent(
	player, -- Player Instance
	"Source", -- Flow Type: Can be "Source" or "Sink"
	"Cash", -- Currency
	100, -- Amount Of Currency
	player.leaderstats.Cash.Value, -- Current balance
	"Gameplay", -- Transaction Type: Can be "IAP", "Shop", "Gameplay", "ContextualPurchase", "TimedReward" or "Onboarding"
	"Winner" -- Item SKU: Optional
)

-- One-Time/Onboarding Funnel
BetterAnalyticsService:LogOnboardingFunnelStepEvent(
	player, --Player Instance
	1, -- Step Number
	"Picked Starter Character" -- Step Name
)

-- Recurring Funnel
BetterAnalyticsService:LogFunnelStepEvent(
	player, -- Player Instance
	"Starter Pack", -- Funnel Name
	nil, -- Funnel Session ID: Optional, Module uses HttpService:GenerateGUID() as fallback 
	1, --Step Number
	"Opened Shop" --Step Name
)

Find Out More: Event Types | Documentation - Roblox Creator Hub
AnalyticsService: AnalyticsService | Documentation - Roblox Creator Hub
Economy Flow Types: AnalyticsEconomyFlowType | Documentation - Roblox Creator Hub
Economy Transaction Types: AnalyticsEconomyTransactionType | Documentation - Roblox Creator Hub

I plan to update this with more functionality over time as these analytics events are fairly new. While this isn’t something revolutionary, here are a few reasons to use this rather than directly using the service:

  • Better error handling
  • The module handles enumeration
  • Lower API calls, AnalyticsService has Rate Limits

This module uses the GPLv3 license. You can copy, modify, convey, adapt, and/or redistribute this work.

Bug reports and constructive criticism is highly appreciated, Thank you.

7 Likes