Skip to content

Code Reference

Initialization

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

Make sure you have entered your API and Developer keys in the CognitiveVR Preferences from the Unreal Project Settings!

Sessions

A Session Custom Event should begin from your main menu or at the start of the "main" portion of your project.

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. You should manage unique ids for your users.

//IAnalyticsProvider
TSharedPtr<IAnalyticsProvider> analytics = FAnalytics::Get().GetDefaultConfiguredProvider();
analytics->SetUserID("UniqueUserID");
analytics->SetGender("Male");
analytics->SetAge(20);
//FAnalyticsProviderCognitiveVR
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive->SetUserID("UniqueUserID");
cognitive->SetGender("Male");
cognitive->SetAge(20);
cognitive->SetUserProperty("Height", 180);

Custom Events

For an explanation about custom events, refer to the Custom Events page.

Session Name

You can set a custom name for a user's session. This can be useful for organizing sessions in SceneExplorer. If you do not provide a session name, one will be generated for you. This can be changed on the dashboard. You can set a session name before or after the session is initialized.

TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive->SetSessionName("VR Convention Spring 2018");

session name

Lobby

A LobbyId connects multiple user sessions together to display a multiplayer experience. Please get in contact to discuss your implementation details.

//game server pseudocode

map<string,string> headers;
headers.Add("Authorization","APIKEY:DATA " + APIKey);
auto response = http::post("https://data.cognitive3d.com/v0/lobbies",headers);
auto json = json::parse(response.Content);
string lobbyid = json["id"];
//send lobbyid to each client


//game client
TSharedPtr<FAnalyticsProviderCognitiveVR> cognitive = FAnalyticsCognitiveVR::Get().GetCognitiveVRProvider();
cognitive->SetLobbyId(lobbyid);

lobby id

To see more info on lobbies, go to the Lobby System page.