NuTracking: The API Guide

Posted by on Aug 13, 2011

The API of NuTracking is quite simple. Use the following code to initialize NuTracking and create the singleton:

        NuTracking.Instance.Startup(
            "UA-24576515-1"/*your account code*/, 
            "http://nutracking-001.premiereliaison.com"/*your domain name*/, 
            "nutracking-001"/*short name of your game*/, 
            true/*wantObfuscateGlobalIP*/, 
            true/*wantMonitorEditor*/, 
            true/*wantLog*/);

And here is the interface of the NuTracking class:

// this is not the actual code

public class NuTracking : MonoBehaviour

{
    // add a custom event

    public void AddGenericEvent(string _object, string _action,
        string _label = null, int? _value = null);

    public void AddGenericEvent(string _pageTitle, string _pageUrl,
        string _object, string _action,
        string _label = null, int? _value = null);


    // add a custom transaction

    public void AddGenericTransaction(string _productSku,
        string _productName, float _price, int _quantity);

    public void AddGenericTransaction(string _pageTitle, string _pageUrl,
        string _productSku, string _productName, float _price, int _quantity);
}

The function AddGenericEvent() could trigger a customized event tracking. This kind of events could carry meaningful gameplay information, and could be analyzed by Google Analytics’ custom report system. You could find some detailed information here.

The function AddGenericTransaction() is used for record transactions, like in-app purchase.

Here is a sample of how these functions are used:

public class Example : MonoBehaviour {

    // Use this for initialization
    void Start () {
        NuTracking.Instance.Startup("UA-24576515-1", "http://nutracking-001.premiereliaison.com", "nutracking-001", true/*wantObfuscateGlobalIP*/, true/*wantMonitorEditor*/, true/*wantLog*/);
    }
    
    // Update is called once per frame
    int frameCount = 0;
    void Update () {
        if (frameCount == 15)
        {
            Purchase();
        }
        
        if (frameCount == 30)
        {
            SaveGame();
        }
        ++ frameCount;
    }
    
    void Purchase()
    {
        NuTracking.Instance.AddGenericTransaction("SKU001", "Item 001", 0.99f, 1);
        NuTracking.Instance.AddGenericTransaction("SKU002", "Item 002", 1.99f, 2);
    }
    
    void SaveGame() {
        string sessionName = "GameSession0";
        
        NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameDurationInSeconds", Random.Range(10, 20));
        NuTracking.Instance.AddGenericEvent(sessionName, "Result", "GameScore", Random.Range(1000, 10000));
        NuTracking.Instance.AddGenericEvent(sessionName, "GamePlay", "Event0Triggered", Random.Range(0, 2));
        NuTracking.Instance.AddGenericEvent(sessionName, "GamePlay", "Event1Triggered", Random.Range(0, 2));
        NuTracking.Instance.AddGenericEvent(sessionName, "GamePlay", "Event2Triggered", Random.Range(0, 2));
    }
}