Kairoengine analytics library. Sends data to the Mixpanel service.

James Peret 342dcbaad4 Upgraded package dependecies and bumped version to 0.2.0 2 years ago
Runtime 342dcbaad4 Upgraded package dependecies and bumped version to 0.2.0 2 years ago
.gitignore 3ed48675b6 Initial commit 2 years ago
Readme.md 342dcbaad4 Upgraded package dependecies and bumped version to 0.2.0 2 years ago
Readme.md.meta 3ed48675b6 Initial commit 2 years ago
Runtime.meta 3ed48675b6 Initial commit 2 years ago
package.json 342dcbaad4 Upgraded package dependecies and bumped version to 0.2.0 2 years ago
package.json.meta f9dcea68d0 Updated analytics library 2 years ago


📦 KairoEngine.Analytics.v0.2.0

The Analytics package uses the Mixpanel service to store analytics. It can be easly changed to use another service without having to change the actual event tracking inside the game.

Required packages

  • Mixpanel.Unity (github)
  • KairoEngine.Core


  • KairoEngine.Analytics



  • Analytics - The analytics system component that needs to be filled out with the mixpanel Key.

Getting Started

Create a new class called GameAnalytics or use the name of the current game and add the following libraries:

using KairoEngine.Core;
using KairoEngine.Utilities;
using KairoEngine.Analytics;

/// <summary>Listen to game events and emmit analytic events.</summary>
public class GameAnalytics : MonoBehaviour


Then to start tracking a player, use these snippets:

// Get or create a Player ID
var randomID = KairoEngine.Core.Utilities.RandomString(12);
var playerID = PlayerPrefs.GetString("PlayerID", randomID);
PlayerPrefs.SetString("PlayerID", playerID);
// Set the ID for all tracking done from now on
// Set App Version
Analytics.Register("App Version", Application.version);
// Send data to the server in 2 seconds
StartCoroutine(Timer.Start(2f, false, () => { Analytics.Flush(); }));

To track stuff:

// Simple event
Analytics.Track("Game Initialized");
// Event with payload
var data = new Dictionary<string, System.Object>();
data.Add("Level", level);
Analytics.Track("Level Started", data);
// Timed event
Analytics.StartTimedEvent("Level Finished");
StartCoroutine(Timer.Start(10f, false, () => { 
    Analytics.Track("Level Finished", data); 

To send analytics before quitting the application:

// On game init, run this function that adds an 
// event listener for when the game wants to quit
static void RunOnStart() => Application.wantsToQuit += OnApplicationQuit;

// Singleton for this component so that it can be 
// referenced in a Lambda function
public static GameAnalytics instance;

// When quitting the application:
// Cancel quitting, send quit event, flush analytics, 
// wait 2 seconds and finally quit the application.
static bool OnApplicationQuit() 
    // Finished the Timed event
    // Send data to the Analytics server
    // This takes about one second to happen
    // If the app quits now data might not be sent
    if(instance != null) 
        instance.StartCoroutine(Timer.Start(2f, false, () => { 
            // Actualy close the application
        // Remove the event listener so no bugs pop up
        Application.wantsToQuit -= OnApplicationQuit;
        // Return false so that the app doesn't quit
        return false;
    // If there is no instance return true so that the app can quit
    return true;


  • Upgraded GameModule system


Back Log

  • Create a module that loads the analytics component on init and holds its data