Skip to content

Unity Analytics SDK - A lightweight, offline-first analytics solution for mobile games. Features automatic session tracking, batched sync with retry, and anonymous identifiers for GDPR compliance. No external dependencies. 🤖 Generated entirely by Claude Code (claude.com/claude-code)

License

Notifications You must be signed in to change notification settings

RaspY737/analytics-sdk-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Analytics SDK for Unity

Lightweight analytics SDK for mobile games. Collects gameplay events and sends them to a backend service.

Features

  • 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

Requirements

  • Unity 2021.3 or later
  • Android or iOS target platform

Installation

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"
  }
}

Setup

  1. Create a config asset: Right-click in Project > Create > Analytics > Config
  2. Fill in your gameId, gameVersion, and apiEndpoint
  3. Initialize the SDK at game startup:
using YourCompany.Analytics;

public class GameManager : MonoBehaviour
{
    [SerializeField] private AnalyticsConfig analyticsConfig;

    void Awake()
    {
        Analytics.Initialize(analyticsConfig);
    }
}

Usage

Track Events

// Simple event
Analytics.Track("button_clicked");

// Event with payload
Analytics.Track("level_completed", new {
    level_id = 5,
    score = 1000,
    duration_seconds = 45.5f
});

Snapshots (State)

Use snapshots for periodic state saves:

Analytics.Snapshot("player_state", new PlayerStateData {
    currency = 500,
    level = 10
});

Manual Session Control

Sessions are managed automatically, but you can control them manually:

Analytics.StartSession();
Analytics.EndSession("level_change");

Force Sync

Analytics.Flush();

Configuration Options

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

Debug Tools

Open Window > Analytics > Debug Window to:

  • View current identifiers
  • Inspect the event queue
  • Send test events
  • Clear local data

Backend API

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}"
    }
  ]
}

License

MIT License

About

Unity Analytics SDK - A lightweight, offline-first analytics solution for mobile games. Features automatic session tracking, batched sync with retry, and anonymous identifiers for GDPR compliance. No external dependencies. 🤖 Generated entirely by Claude Code (claude.com/claude-code)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages