Code Reference

Initialization

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

Initialize the plugin (Simple)

Make sure your config/defaultengine.ini file includes your CustomerID key!

//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();

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
//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
analytics.Get()->StartSession();
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
TArray<FAnalyticsEventAttribute> attributes;
cognitive.Get()->StartSession(attributes);
End a session
//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
analytics.Get()->EndSession();
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive.Get()->EndSession();

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.

//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
analytics.Get()->SetUserID("UniqueUserID");
analytics.Get()->SetGender("Male");
analytics.Get()->SetAge(20);
//these values are registered when StartSession is called
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive.Get()->SetUserID("UniqueUserID");
cognitive.Get()->SetGender("Male");
cognitive.Get()->SetAge(20);
//these values are registered when StartSession is called

It can be useful to include properties about your users. UpdateUserState can be called at any time you learn details about your users, even after the session begins.

//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
TSharedPtr<FJsonObject> properties = MakeShareable(new FJsonObject);
properties->SetStringField("hair color", "black");
properties->SetNumberField("height", 180);
cognitive.Get()->core_utils->UpdateUserState("UniqueUserID", properties);
//this can be called at any time

Device Info

This is sent automatically when the session is started.

Transactions

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

Instant Transaction
//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
analytics.Get()->RecordEvent("An Event Happened");
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive.Get()->transaction->BeginEnd("EventName");
Begin Extended Transaction
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive.Get()->transaction->Begin("EventName",NULL,"UniqueTransactionID");
End Extended Transaction
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive.Get()->transaction->End("EventName", NULL, "UniqueTransactionID");
Multiple Transaction Properties
//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
TArray<FAnalyticsEventAttribute> attributes;
attributes.Add(FAnalyticsEventAttribute("MyBoolean", false));
attributes.Add(FAnalyticsEventAttribute("NumbersNotSupported", FString("5")));
attributes.Add(FAnalyticsEventAttribute("MyString", FString("Words")));
analytics.Get()->RecordEvent("EventName", attributes);
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
TSharedPtr<FJsonObject> properties = MakeShareable(new FJsonObject);
properties->SetStringField("MyStrin", "stringvalue");
properties->SetNumberField("MyNumber", 5);
properties->SetBoolField("MyBoolean", true);
cognitive.Get()->transaction->BeginEnd("EventName", properties);

Collections

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

//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
double newValue = 5;
double change = 1;
bool isCurrency = false;
cognitive.Get()->core_utils->UpdateCollection("collectionname", newValue, change, isCurrency);

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. A Tuning Value is returned as FString, but can be cast to bool or int32

bool myBool = false;
FAnalyticsProviderCognitiveVR *cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider().Get();
if (cognitive != NULL)
{
    CognitiveVRResponse resp = cognitive->tuning->GetValue("MyTuningBool", "false");

    if (resp.IsSuccessful() && resp.GetContent().TryGetBoolField("MyTuningBool",myBool))
    {
        UE_LOG(LogTemp, Log, TEXT("MyTuningBool is: %s"), myBool ? TEXT("true") : TEXT("false"));
    }
}