Auto-tracking
1. Auto-tracked events
The TDAnalytics SDK currently supports auto-tracking of three events:
- ta_app_install: Game install. This event is collected when the game is opened for the first time after installation
- ta_app_start: This event is collected when the game enters the foreground
- ta_app_end: This event is collected when the game moves to the background
Call EnableAutoTrack to enable auto-tracking:
// Enable auto-tracking
UTDAnalytics::EnableAutoTrack();
Note: If you need a custom distinct ID, make sure you call the Identify API to set the distinct ID before you enable auto-tracking.
You can also manually pass in the auto-tracked events you want to enable:
TArray<FString> EventTypeList;
EventTypeList.Emplace(TEXT("ta_app_install"));
EventTypeList.Emplace(TEXT("ta_app_start"));
EventTypeList.Emplace(TEXT("ta_app_end"));
UTDAnalytics::EnableAutoTrackWithType(EventTypeList, AppID);
2. Set custom properties
Starting from v1.4.1, you can set custom properties for auto-tracked events. When a specified event is collected, the custom properties are merged into its event properties and reported.
TArray<FString> EventTypeList;
EventTypeList.Emplace(TEXT("ta_app_install"));
EventTypeList.Emplace(TEXT("ta_app_start"));
EventTypeList.Emplace(TEXT("ta_app_end"));
UTDAnalytics::EnableAutoTrackWithTypeAndProperties(EventTypeList, TEXT("{\"autoTrackKey1\":\"autoTrackvalue1\",\"autoTrackKey2\":\"autoTrackvalue2\"}"), AppID);
3. Set an auto-tracking callback
Starting from v1.5.0, you can set a callback for auto-tracked events. When a specified event is collected, the callback notifies you and passes back the event properties the event currently carries. You can forward the data as needed, or return new event properties.
//Define the callback
FString UTAUserWidget::TAAutoTrackProperties(FString AutoTrackEventType, FString Properties)
{
//AutoTrackEventType: auto-tracked event type
//Properties: event properties carried by the current event
//Processing logic
FDateTime TDateTime = FDateTime::Now();
int64 SecondTimestamp = TDateTime.ToUnixTimestamp();
int32 MillisecondPart = TDateTime.GetMillisecond();
FString TimeStr = *FString::Printf(TEXT("%llu"), SecondTimestamp);
TimeStr += *FString::Printf(TEXT("%lld"), MillisecondPart);
return "{\"auto_property1_name\":\"" + AutoTrackEventType + "\",\"auto_property2_time\":\"" + TimeStr + "\"}";
}
//Set the callback
void UTAUserWidget::Call_TA_SetAutoTrackEventListener()
{
TArray<FString> EventTypeList;
EventTypeList.Emplace(TEXT("ta_app_install"));
EventTypeList.Emplace(TEXT("ta_app_start"));
EventTypeList.Emplace(TEXT("ta_app_end"));
UTDAnalytics::SetAutoTrackEventListener(this, &UTAUserWidget::TAAutoTrackProperties, EventTypeList, AppID);
}

