📚 Event Tracking Guide
Learn how to structure and send events to Tokebi for optimal analytics and data quality.
Based on analysis of your existing event data, here are the patterns and best practices we've observed.
⚠️ Important Note
You can track ANY event type you want! The examples below are just suggestions based on your current data.
The only requirement is that your payload must be valid JSON. You have complete freedom to:
- • Create custom event types with any name you choose
- • Structure your payload data however makes sense for your game
- • Include any fields and data types that are relevant to your analytics
- • Track business-specific events unique to your game mechanics
This guide shows patterns from your existing data to help you maintain consistency, but you're not limited to these examples.
🎮 Roblox SDK Integration
⚙️ Setup & Installation
Server Script Setup
Use the server module for tracking events that need validation and security.
-- In ServerScriptService
local Tokebi = require(game.ServerScriptService:WaitForChild("TokebiServer"))
-- Track server-side events
Tokebi.track("player_added", {
timestamp = tick(),
is_new_player = false
}, player.UserId)Client Script Setup
Use the client module for immediate feedback and UI-related events.
-- In LocalScript
local Tokebi = require(game.ReplicatedStorage:WaitForChild("TokebiClient"))
-- Track client-side events
Tokebi.track("ui_interaction", {
button_name = "ShopButton",
screen = "MainMenu"
}, game.Players.LocalPlayer.UserId)📝 Basic Usage Pattern
-- Basic syntax
Tokebi.track(event_type, payload_data, player_id)
-- Example from your current data
Tokebi.track("loot_collected", {
Apple = 3,
Orange = 1
}, player.UserId)
-- You can create ANY event type you want!
Tokebi.track("custom_boss_defeated", {
boss_name = "Dragon King",
difficulty = "legendary",
players_involved = 4,
time_taken = 325
}, player.UserId)event_type
String describing what happened (your choice!)
payload_data
Table with event-specific data (must be valid JSON)
player_id
player.UserId (number)
🎨 Creative Event Examples
Here are some creative event types you could track based on your game mechanics:
👤 Player Events
Player Joins Game
-- When player joins
game.Players.PlayerAdded:Connect(function(player)
Tokebi.track("player_added", {
timestamp = os.time(),
is_new_player = player.AccountAge < 7,
spawn_location = "DefaultSpawn",
device_type = "Desktop" -- or detect device
}, player.UserId)
end)Player Leaves Game
-- When player leaves
game.Players.PlayerRemoving:Connect(function(player)
local sessionTime = os.time() - player.joinTime
Tokebi.track("player_leaving", {
session_duration = sessionTime,
reason = "disconnect",
level_reached = player.leaderstats.Level.Value,
coins_earned = player.SessionCoins or 0
}, player.UserId)
end)🎁 Loot Events
Loot Created
-- When loot spawns
local function spawnLoot(itemType, quantity, location)
Tokebi.track("loot_created", {
item_type = itemType,
quantity = quantity,
location = location,
rarity = getLootRarity(itemType),
spawn_method = "natural" -- or "event", "boss_drop"
}, nil) -- No specific player for spawn events
end
spawnLoot("Apple", 3, "Forest_Area_1")Loot Collected
-- When player collects loot
local function collectLoot(player, itemType, quantity)
local currentTotal = player.Inventory[itemType] or 0
Tokebi.track("loot_collected", {
item_type = itemType,
quantity = quantity,
total_collected = currentTotal + quantity,
collection_method = "pickup",
inventory_full = isInventoryFull(player)
}, player.UserId)
end
collectLoot(player, "Apple", 1)⚔️ Combat Events
Player Attack
-- When player attacks
local function playerAttack(attacker, target, damage)
Tokebi.track("combat_attack", {
weapon_type = attacker.EquippedWeapon.Name,
damage_dealt = damage,
target_type = target.ClassName,
critical_hit = damage > 50,
player_level = attacker.Level.Value
}, attacker.UserId)
endBoss Defeated
-- Custom boss event
local function bossDefeated(players, bossName, difficulty)
for _, player in pairs(players) do
Tokebi.track("boss_defeated", {
boss_name = bossName,
difficulty = difficulty,
party_size = #players,
time_taken = getBattleTime(),
damage_dealt = player.BattleStats.Damage,
survived = player.Character.Humanoid.Health > 0
}, player.UserId)
end
end💰 Economy Events
Purchase
-- When player buys something
local function purchaseItem(player, itemName, cost)
local currentCoins = player.leaderstats.Coins.Value
Tokebi.track("item_purchased", {
item_name = itemName,
cost = cost,
currency_type = "coins",
balance_before = currentCoins,
balance_after = currentCoins - cost,
shop_category = "weapons",
purchase_location = "MainShop"
}, player.UserId)
endAchievement Unlocked
-- Custom achievement event
local function achievementUnlocked(player, achievementName)
Tokebi.track("achievement_unlocked", {
achievement_name = achievementName,
player_level = player.Level.Value,
total_achievements = getTotalAchievements(player),
time_to_unlock = getPlayerPlayTime(player),
rarity = getAchievementRarity(achievementName)
}, player.UserId)
end⭐ Roblox SDK Best Practices
✅ Do This
- • Use server scripts for important events (purchases, deaths)
- • Include contextual data (location, time, state)
- • Use consistent naming conventions
- • Track both success and failure events
- • Include player progression data when relevant
- • Use descriptive event names like "weapon_upgraded"
- • Ensure your payload data is valid JSON
❌ Avoid This
- • Tracking every single player movement
- • Using client scripts for sensitive events
- • Sending empty or null payload data
- • Generic event names like "event" or "action"
- • Tracking events too frequently (spam)
- • Missing player.UserId in important events
- • Invalid JSON in payload data
🚀 Advanced Patterns
Session Tracking
-- Track player sessions with detailed data
local PlayerSessions = {}
game.Players.PlayerAdded:Connect(function(player)
PlayerSessions[player.UserId] = {
joinTime = os.time(),
actionsPerformed = 0,
areasVisited = {},
itemsCollected = {}
}
-- Initial session event
Tokebi.track("session_started", {
device_type = getUserDeviceType(player),
is_premium = player.MembershipType == Enum.MembershipType.Premium,
account_age_days = player.AccountAge,
previous_sessions = getPlayerSessionCount(player)
}, player.UserId)
end)
game.Players.PlayerRemoving:Connect(function(player)
local session = PlayerSessions[player.UserId]
if session then
Tokebi.track("session_ended", {
duration_seconds = os.time() - session.joinTime,
actions_performed = session.actionsPerformed,
areas_visited = session.areasVisited,
items_collected = session.itemsCollected,
engagement_score = calculateEngagement(session)
}, player.UserId)
end
end)⚠️ Error Handling
-- Wrap tracking calls in pcall for error handling
local function safeTrack(eventType, payload, playerId)
local success, error = pcall(function()
Tokebi.track(eventType, payload, playerId)
end)
if not success then
warn("Failed to track event:", eventType, error)
end
end
-- Use safeTrack instead of direct Tokebi.track
safeTrack("player_action", { action = "jump" }, player.UserId)🚀 Quick Start
Required Fields
- •
event_type- What happened - •
player_id- Who did it - •
game_id- Which game - •
timestamp- When it happened
Optional Fields
- •
payload- Event-specific data - •
environment- production/development - •
is_returning- Player return status
🏗️ Payload Structure Best Practices
✅ Good Payload Structure
{
"event_type": "loot_created",
"player_id": "1468608969",
"game_id": "3b677ac8-349d-4060-ad91-97dbc5c164ec",
"payload": {
"item_type": "Apple",
"quantity": 3,
"rarity": "common",
"location": "Forest_1"
},
"timestamp": "2025-07-06T23:20:48.527Z",
"environment": "production"
}- • Consistent field naming (snake_case)
- • Structured payload with clear types
- • ISO timestamp format
- • Meaningful event type names
❌ Poor Payload Structure
{
"event_type": "thing",
"player_id": "",
"payload": {
"data": "Apple,3,common",
"info": true,
"misc": null
},
"time": 1625097648
}- • Vague event type names
- • Missing required fields
- • Unstructured data in strings
- • Inconsistent timestamp format
📊 Event Types in Your Games
Based on analysis of your actual event data, here are the event types we've observed. Remember: you can create any event types you want!
👤 Player Events
player_added
When a player joins the game
{
"event_type": "player_added",
"player_id": "1468608969",
"game_id": "your-game-id",
"payload": {
"timestamp": 1735757634604,
"is_new_player": false
},
"timestamp": "2025-07-06T23:19:14.004Z"
}player_leaving
When a player leaves the game
{
"event_type": "player_leaving",
"player_id": "1468608969",
"game_id": "your-game-id",
"payload": {
"session_duration": 534,
"reason": "disconnect"
},
"timestamp": "2025-07-06T23:27:22.761Z"
}🎮 Game Events
loot_created
When loot is generated in the game
{
"event_type": "loot_created",
"player_id": "1468608969",
"game_id": "your-game-id",
"payload": {
"item_type": "Apple",
"quantity": 1,
"location": "Forest_Area_1"
},
"timestamp": "2025-07-06T23:20:50.411Z"
}loot_collected
When a player picks up loot
{
"event_type": "loot_collected",
"player_id": "1468608969",
"game_id": "your-game-id",
"payload": {
"item_type": "Apple",
"quantity": 1,
"total_collected": 5
},
"timestamp": "2025-07-03T17:55:04.391Z"
}🎮 Roblox SDK Integration
⚙️ Setup & Installation
Server Script Setup
Use the server module for tracking events that need validation and security.
-- In ServerScriptService
local Tokebi = require(game.ServerScriptService:WaitForChild("TokebiServer"))
-- Track server-side events
Tokebi.track("player_added", {
timestamp = tick(),
is_new_player = false
}, player.UserId)Client Script Setup
Use the client module for immediate feedback and UI-related events.
-- In LocalScript
local Tokebi = require(game.ServerScriptService:WaitForChild("TokebiClient"))
-- Track client-side events
Tokebi.track("ui_interaction", {
button_name = "ShopButton",
screen = "MainMenu"
}, game.Players.LocalPlayer.UserId)📝 Basic Usage Pattern
-- Basic syntax
Tokebi.track(event_type, payload_data, player_id)
-- Example from your current data
Tokebi.track("loot_collected", {
Apple = 3,
Orange = 1
}, player.UserId)
-- You can create ANY event type you want!
Tokebi.track("custom_boss_defeated", {
boss_name = "Dragon King",
difficulty = "legendary",
players_involved = 4,
time_taken = 325
}, player.UserId)event_type
String describing what happened (your choice!)
payload_data
Table with event-specific data (must be valid JSON)
player_id
player.UserId (number)
🎨 Creative Event Examples
Here are some creative event types you could track based on your game mechanics:
👤 Player Events
Player Joins Game
-- When player joins
game.Players.PlayerAdded:Connect(function(player)
Tokebi.track("player_added", {
timestamp = os.time(),
is_new_player = player.AccountAge < 7,
spawn_location = "DefaultSpawn",
device_type = "Desktop" -- or detect device
}, player.UserId)
end)Player Leaves Game
-- When player leaves
game.Players.PlayerRemoving:Connect(function(player)
local sessionTime = os.time() - player.joinTime
Tokebi.track("player_leaving", {
session_duration = sessionTime,
reason = "disconnect",
level_reached = player.leaderstats.Level.Value,
coins_earned = player.SessionCoins or 0
}, player.UserId)
end)🎁 Loot Events
Loot Created
-- When loot spawns
local function spawnLoot(itemType, quantity, location)
Tokebi.track("loot_created", {
item_type = itemType,
quantity = quantity,
location = location,
rarity = getLootRarity(itemType),
spawn_method = "natural" -- or "event", "boss_drop"
}, nil) -- No specific player for spawn events
end
spawnLoot("Apple", 3, "Forest_Area_1")Loot Collected
-- When player collects loot
local function collectLoot(player, itemType, quantity)
local currentTotal = player.Inventory[itemType] or 0
Tokebi.track("loot_collected", {
item_type = itemType,
quantity = quantity,
total_collected = currentTotal + quantity,
collection_method = "pickup",
inventory_full = isInventoryFull(player)
}, player.UserId)
end
collectLoot(player, "Apple", 1)⚔️ Combat Events
Player Attack
-- When player attacks
local function playerAttack(attacker, target, damage)
Tokebi.track("combat_attack", {
weapon_type = attacker.EquippedWeapon.Name,
damage_dealt = damage,
target_type = target.ClassName,
critical_hit = damage > 50,
player_level = attacker.Level.Value
}, attacker.UserId)
endBoss Defeated
-- Custom boss event
local function bossDefeated(players, bossName, difficulty)
for _, player in pairs(players) do
Tokebi.track("boss_defeated", {
boss_name = bossName,
difficulty = difficulty,
party_size = #players,
time_taken = getBattleTime(),
damage_dealt = player.BattleStats.Damage,
survived = player.Character.Humanoid.Health > 0
}, player.UserId)
end
end💰 Economy Events
Purchase
-- When player buys something
local function purchaseItem(player, itemName, cost)
local currentCoins = player.leaderstats.Coins.Value
Tokebi.track("item_purchased", {
item_name = itemName,
cost = cost,
currency_type = "coins",
balance_before = currentCoins,
balance_after = currentCoins - cost,
shop_category = "weapons",
purchase_location = "MainShop"
}, player.UserId)
endAchievement Unlocked
-- Custom achievement event
local function achievementUnlocked(player, achievementName)
Tokebi.track("achievement_unlocked", {
achievement_name = achievementName,
player_level = player.Level.Value,
total_achievements = getTotalAchievements(player),
time_to_unlock = getPlayerPlayTime(player),
rarity = getAchievementRarity(achievementName)
}, player.UserId)
end⭐ Roblox SDK Best Practices
✅ Do This
- • Use server scripts for important events (purchases, deaths)
- • Include contextual data (location, time, state)
- • Use consistent naming conventions
- • Track both success and failure events
- • Include player progression data when relevant
- • Use descriptive event names like "weapon_upgraded"
- • Ensure your payload data is valid JSON
❌ Avoid This
- • Tracking every single player movement
- • Using client scripts for sensitive events
- • Sending empty or null payload data
- • Generic event names like "event" or "action"
- • Tracking events too frequently (spam)
- • Missing player.UserId in important events
- • Invalid JSON in payload data
🚀 Advanced Patterns
Session Tracking
-- Track player sessions with detailed data
local PlayerSessions = {}
game.Players.PlayerAdded:Connect(function(player)
PlayerSessions[player.UserId] = {
joinTime = os.time(),
actionsPerformed = 0,
areasVisited = {},
itemsCollected = {}
}
-- Initial session event
Tokebi.track("session_started", {
device_type = getUserDeviceType(player),
is_premium = player.MembershipType == Enum.MembershipType.Premium,
account_age_days = player.AccountAge,
previous_sessions = getPlayerSessionCount(player)
}, player.UserId)
end)
game.Players.PlayerRemoving:Connect(function(player)
local session = PlayerSessions[player.UserId]
if session then
Tokebi.track("session_ended", {
duration_seconds = os.time() - session.joinTime,
actions_performed = session.actionsPerformed,
areas_visited = session.areasVisited,
items_collected = session.itemsCollected,
engagement_score = calculateEngagement(session)
}, player.UserId)
end
end)⚠️ Error Handling
-- Wrap tracking calls in pcall for error handling
local function safeTrack(eventType, payload, playerId)
local success, error = pcall(function()
Tokebi.track(eventType, payload, playerId)
end)
if not success then
warn("Failed to track event:", eventType, error)
end
end
-- Use safeTrack instead of direct Tokebi.track
safeTrack("player_action", { action = "jump" }, player.UserId)🔢 Data Types & Validation
Strings
event_typeUse descriptive names
player_idConsistent ID format
item_typeClear item names
Numbers
quantityInteger amounts
timestampUnix timestamps
durationTime in seconds
Booleans
is_returningPlayer status
is_new_playerFirst time player
successAction outcomes
🎯 Common Payload Patterns
These are just examples - you can structure your payload however makes sense for your game!
Item/Inventory Events
"payload": {
"item_type": "Apple",
"quantity": 3,
"rarity": "common",
"location": "Forest_1",
"source": "tree_harvest"
}Player Progress Events
"payload": {
"level": 5,
"experience_gained": 150,
"total_experience": 2340,
"achievement": "Explorer"
}Session Events
"payload": {
"duration_seconds": 534,
"actions_performed": 23,
"areas_visited": ["Forest", "Cave"],
"exit_reason": "user_quit"
}Economic Events
"payload": {
"currency_type": "coins",
"amount": 100,
"balance_before": 450,
"balance_after": 550,
"transaction_type": "reward"
}💎 Data Quality Tips
✅ Do This
- • Use consistent field names across all events
- • Include context in payload (location, source, etc.)
- • Use descriptive event type names
- • Send timestamps in ISO format
- • Validate payloads before sending
- • Use appropriate data types (numbers for quantities)
- • Ensure payload data is valid JSON
- • Create meaningful custom event types
❌ Avoid This
- • Empty or null player_ids
- • Inconsistent field naming (camelCase vs snake_case)
- • Storing multiple values in single string fields
- • Generic event type names like "event" or "action"
- • Missing required fields
- • Sending malformed JSON
- • Overly complex nested structures
- • Tracking too many events (spam)
🎨 Custom Event Ideas
Here are some creative event types you might want to track in your games:
🎮 Game Mechanics
- •
puzzle_solved- Player completes a puzzle - •
area_discovered- New area exploration - •
mini_game_completed- Mini-game results - •
quest_started- Quest initiation - •
skill_upgraded- Skill tree progression - •
teleport_used- Fast travel usage
👥 Social Features
- •
team_formed- Players team up - •
friend_invited- Friend system usage - •
chat_message_sent- Communication tracking - •
guild_joined- Guild membership - •
trade_completed- Player-to-player trades - •
emote_used- Expression system
🏆 Achievements
- •
milestone_reached- Progress milestones - •
rare_item_found- Rare discoveries - •
speed_record_set- Performance records - •
daily_login_streak- Retention tracking - •
perfect_score_achieved- Skill mastery - •
collection_completed- Collection systems
🔧 Technical Events
- •
bug_encountered- Error tracking - •
performance_issue- Performance monitoring - •
feature_used- Feature adoption - •
settings_changed- User preferences - •
tutorial_completed- Onboarding flow - •
crash_occurred- Stability tracking
✅ JSON Validation
The only technical requirement is that your payload must be valid JSON. Here are some tips:
✅ Valid JSON Examples
-- Simple values
{ health = 100, level = 5 }
-- Nested objects
{
player_stats = {
health = 100,
mana = 50
},
location = "Forest"
}
-- Arrays
{
items_collected = {"Apple", "Sword", "Potion"},
quest_ids = {1, 2, 3}
}
-- Mixed types
{
success = true,
score = 1250,
message = "Well done!",
timestamp = os.time()
}❌ Invalid JSON
-- Functions (not serializable)
{ callback = function() end }
-- Userdata (Roblox objects)
{ part = workspace.Part }
-- Circular references
local t = {}
t.self = t -- Creates circular reference
-- Mixed array/object
{
[1] = "item1",
name = "test" -- Don't mix numeric and string keys
}Stick to basic data types: strings, numbers, booleans, tables (arrays/objects), and nil.
Need help with event tracking? Check your Schema Insights dashboard for data quality analysis.
This guide is based on analysis of your actual event data and will be updated as your tracking evolves.
🎯 Remember
You have complete creative freedom! Track any events that matter to your game. The examples above are just to inspire you - create events that fit your unique game mechanics.