Code Reference

Initialization

These steps are for advanced users who want to more closely integrate our API calls with their projects.

By default, CognitiveVR_Manager is Initialized on Start() with the correct settings. You only need to manually initialize the plugin if you are NOT using this prefab.

Use the namespace (optional)
using CognitiveVR;
Initialize the plugin (Simple)
CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create(
   "yourcompanyname1234-productname-test"
);

CognitiveVR.Core.init(initParams, delegate(CognitiveVR.Error initError) {
    CognitiveVR.Plugins.Session.Transaction().begin();
});
Initialize the plugin (Advanced)
CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create(
        "yourcompanyname1234-productname-test",

        CognitiveVR.EntityInfo.createUserInfo("John Smith"),

        CognitiveVR.EntityInfo.createDeviceInfo().setProperty(" SomeDeviceProperty", true)
        );

CognitiveVR.Core.init(initParams, delegate(CognitiveVR.Error initError) {
    if(CognitiveVR.Error.Success == initError)
        Debug.Log("onCognitiveVRInitComplete: " + initError.ToString());
    else
        Debug.LogError("onCognitiveVRInitComplete: " + initError.ToString());    
});

Sessions

A Session Transaction should begin from your main menu. It will help contextualize game events and could contain nested transactions (such as "level"). For an explanation about nested transactions, refer to the Transactions page.

Begin a session
    CognitiveVR.Plugins.Session.Transaction().begin();
End a session
    CognitiveVR.Plugins.Session.Transaction().end();

User Info

This can be used to track a user across multiple devices. A user's unique Steam ID is a good value to use as the userID.

CognitiveVR.EntityInfo myNewUser = CognitiveVR.EntityInfo.createUserInfo(
    "John Smith",
    properties: new Dictionary<string, object> {
        { "PremiumUser", true },
        { "SignUpPromotionUsed", "FreeMonthTrial" }
    }
);

CognitiveVR.Core.registerUser(myNewUser, delegate(CognitiveVR.Error registerError) {});

Device Info

This is sent automatically during Core.Init().

Transactions

For an explanation about transactions, refer to the Transactions page.

Instant Transaction
CognitiveVR.Instrumentation.Transaction("A Transaction Happened").beginAndEnd();
Begin Extended Transaction
CognitiveVR.Instrumentation.Transaction("Extended Transaction").begin();
End Extended Transaction
CognitiveVR.Instrumentation.Transaction("Extended Transaction").end();
One Transaction Property
CognitiveVR.Instrumentation.Transaction("A Transaction Happened")
    .setProperty("Enemy_Killed", "Wolf")
    .beginAndEnd();
Multiple Transaction Properties
CognitiveVR.Instrumentation.Transaction("A Transaction Happened")
    .setProperty("Enemy_Killed", "Wolf")
    .setProperty("Powerup", "Super_Speed")
    .beginAndEnd();
CognitiveVR.Instrumentation.Transaction("An Event Happened")
    .setProperties(new Dictionary<string, object> {
      { "Enemy_Killed", "Wolf" },
      { "Powerup", "Super_Speed" }
    })
    .beginAndEnd();

Collections

Collections can be used to update variables, such as in-game currency

//after the player has bought an item
CognitiveVR.Instrumentation.updateCollection("gems", currentGemCount, -itemCost, true);

Tuning Variables

Tuning variables allow you to adjust your experience based on a segment of your users. Tuning variables are defined in the cognitiveVR Dashboard

if (CognitiveVR.Tuning.getVar<bool>("premium", false))
{
    Debug.Log(CognitiveVR.Tuning.getVar<float>("welcomeTime", 3.0f));
}