Unreal SDK
Install the SDK
Download the latest version ofAmplitudeUnreal.zip from the GitHub releases page. Unzip the file into a folder inside your Unreal project's Plugins directory.bash
mkdir -p Plugins/AmplitudeUnreal
unzip AmplitudeUnreal.zip -d Plugins/AmplitudeUnreal
Enable the SDK plugin in the editor
Open your project in the UE4 editor. Go to Settings > Plugins > Project > Analytics and enable AmplitudeUnreal.
Enable Amplitude as the analytics provider
Go to Settings > Project Settings > Analytics > Amplitude and fill in the fields with your API key.
Include the required analytics modules
In any file that involves instrumentation, include the Unreal Engine analytics headers.
cpp
#include "Runtime/Analytics/Analytics/Public/Analytics.h"
#include "Runtime/Analytics/Analytics/Public/Interfaces/IAnalyticsProvider.h"
Track events and user properties
The Amplitude Unreal API follows the analytics provider interface that Unreal Engine defines.Log basic events
Events represent how users interact with your app. For example, you can track a Game Started event.
cpp
FAnalytics::Get().GetDefaultConfiguredProvider()->StartSession();
FAnalytics::Get().GetDefaultConfiguredProvider()->RecordEvent(TEXT("Game started"));
FAnalytics::Get().GetDefaultConfiguredProvider()->EndSession();
Log events with properties
Events can contain properties. Properties give context about the event.
cpp
TArray<FAnalyticsEventAttribute> AppendedAttributes;
AppendedAttributes.Emplace(TEXT("Test Event Prop key1"), TEXT("Test Event value1"));
AppendedAttributes.Emplace(TEXT("Test Event Prop key2"), TEXT("Test Event value2"));
FAnalytics::Get().GetDefaultConfiguredProvider()->RecordEvent(TEXT("Game Started"), AppendedAttributes);
Set user properties
User properties describe your users at the time they take an action in your app.
The generic Unreal EngineIAnalyticsProvider supports a limited number of user properties.cpp
FAnalytics::Get().GetDefaultConfiguredProvider()->SetLocation(TEXT("Test location"));
FAnalytics::Get().GetDefaultConfiguredProvider()->SetGender(TEXT("Test gender"));
FAnalytics::Get().GetDefaultConfiguredProvider()->SetAge(TEXT(27));
Set custom user IDs
If your app has its own login system, use SetUserId to set a custom user ID.
cpp
FAnalytics::Get().GetDefaultConfiguredProvider()->SetUserID(TEXT("test123@test.com"));
Was this helpful?