Lightweight analytics SDK for mobile games. Collects gameplay events and sends them to a backend service.
- Offline-first: events are queued locally and synced when connected
- Anonymous data only (GDPR compliant)
- Automatic session tracking
- Batch sending with retry and exponential backoff
- No external dependencies
- Unity 2021.3 or later
- Android or iOS target platform
Add the package via Git URL in Unity Package Manager:
https://github.com/yourcompany/analytics-sdk-unity.git
Or add to Packages/manifest.json:
{
"dependencies": {
"com.yourcompany.analytics": "https://github.com/yourcompany/analytics-sdk-unity.git"
}
}- Create a config asset: Right-click in Project > Create > Analytics > Config
- Fill in your
gameId,gameVersion, andapiEndpoint - Initialize the SDK at game startup:
using YourCompany.Analytics;
public class GameManager : MonoBehaviour
{
[SerializeField] private AnalyticsConfig analyticsConfig;
void Awake()
{
Analytics.Initialize(analyticsConfig);
}
}// Simple event
Analytics.Track("button_clicked");
// Event with payload
Analytics.Track("level_completed", new {
level_id = 5,
score = 1000,
duration_seconds = 45.5f
});Use snapshots for periodic state saves:
Analytics.Snapshot("player_state", new PlayerStateData {
currency = 500,
level = 10
});Sessions are managed automatically, but you can control them manually:
Analytics.StartSession();
Analytics.EndSession("level_change");Analytics.Flush();| Option | Default | Description |
|---|---|---|
gameId |
- | Unique identifier for your game |
gameVersion |
- | Current build version |
apiEndpoint |
- | Backend URL |
apiKey |
- | Optional API key for authentication |
syncIntervalSeconds |
30 | How often to sync with backend |
batchSize |
50 | Max events per batch |
maxQueueSize |
1000 | Max events stored locally |
maxRetryAttempts |
3 | Retry attempts on failure |
enableDebugLogs |
false | Enable console logging |
disableInEditor |
true | Disable in Unity Editor |
Open Window > Analytics > Debug Window to:
- View current identifiers
- Inspect the event queue
- Send test events
- Clear local data
The SDK sends batches to POST {apiEndpoint}/api/v1/events:
{
"batch_id": "uuid",
"sent_at": 1234567890,
"records": [
{
"schema_version": 1,
"sdk_version": "0.1.0",
"game_id": "your-game",
"game_version": "1.0.0",
"player_id": "uuid",
"install_id": "uuid",
"session_id": "uuid",
"timestamp": 1234567890,
"timezone_offset": 60,
"record_type": "event",
"event_name": "level_completed",
"payload": "{\"level_id\":5}"
}
]
}MIT License