3. Events API
Capture and dispatch discrete, point-in-time player actions and game milestones to the telemetry backend.
API Cheat Sheet
Choose the right API tool depending on whether your data is persistent context, a generic timeline mark, or a business metric.
| API Surface | Data Nature | Ideal Game Dev Use Cases |
|---|---|---|
Attributes API Tracks the ongoing, rapidly changing runtime context of active gameplay. | Persistent State |
|
Events API Captures discrete, instantaneous milestones and actions down to the millisecond. | Point-in-Time |
|
Outcome Events API Labels explicit target states or conversion goals as a success or a failure. | Binary Outcome |
|
Points in Time vs. Persistent State
While Attributes track the continuous, ongoing state of a game session, Events represent specific, instantaneous occurrences.
An event triggers the exact millisecond something noteworthy happens - like a player firing a gun, purchasing an item, dying, or winning a match. Every event is automatically timestamped down to the millisecond by the SDK, ensuring accurate sequential processing.
Automatic Timestamping
You do not need to pass a timestamp yourself. The SDK automatically appends an ISO 8601 UTC timestamp (yyyy-MM-ddTHH:mm:ss.fffZ) to every event payload at the precise momentSendEvent is executed.
The API Surface
The SDK provides a straightforward method to dispatch events, allowing optional contextual data dictionaries to be attached to the payload.
1. Sending Simple Events
For basic occurrences that do not require extra metadata, you can call SendEvent with just an event name.
using NX10;
using UnityEngine;
public class MenuController : MonoBehaviour
{
public void OnSettingsOpened()
{
// Dispatches a simple event without additional metadata
NX10Manager.Instance.SendEvent("settings_opened");
}
}2. Sending Events with Metadata
To provide deep insights into an event, pass a flat dictionary as the second argument. This is crucial for tracking transaction amounts, enemy types, or specific match outcomes.
using NX10;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public void ResolveMatch(int amountWonOrLost)
{
// Instantiating custom event context
var eventData = new Dictionary<string, object>();
// Append transactional details
eventData.Add("amount", amountWonOrLost);
// Dispatches the event with payload and automatic timestamping
NX10Manager.Instance.SendEvent("player_won", eventData);
}
}Data Constraints
Supported Metadata Types
- Strings (e.g., "economy", "critical_hit")
- Integers & Longs (e.g., -50, 2500)
- Floats & Doubles (e.g., 4.25)
- Booleans (true, false)
- Null
Unsupported Types
Just like the Session and Attributes APIs, the Event payload enforces a flat structure.
- No nested dictionaries or JSON objects
- No Lists or Arrays within the eventData dictionary
- No custom class instances or Unity structs (e.g., Vector3)
