Skip to main content

Send events

Last updated on September 21, 2023
note

Game telemetry is not available on AGS Starter tier.

Overview

The Game Telemetry service, you can track and log players' actions within the game by sending an event. This event will be tracked to the game's streaming pipeline. To track those actions a Player Session is required, so you must enable your players to create an account in your game before you can use this feature.

Preparation before sending events

By default, telemetry events will be sent to a game's streaming pipeline as a batch after a set amount of time. This amount of time should be configured before telemetry events can be sent. Any events that should be sent immediately should also be added to the immediate event list. Here is an example of how to configure your telemetry events.

TArray < FString > ImmediateEventList = {
"ITEM_SOURCE",
"ITEM_SINK",
"SPECIALISED_ABILITY"
};

FTimespan Interval = FTimespan::FromSeconds(30);

// set for game client
FRegistry::GameTelemetry.SetImmediateEventList(ImmediateEventList);
FRegistry::GameTelemetry.SetBatchFrequency(Interval);

// set for game server
FRegistry::ServerGameTelemetry.SetImmediateEventList(ImmediateEventList);
FRegistry::ServerGameTelemetry.SetBatchFrequency(Interval);

Send events using the client SDKs

The following function signature can also be used to send an event. The returned data will be displayed in your data warehouse, where you'll be able to customize its visualization.

FJsonObject Payload;
Payload.SetStringField("someString", "someString");
Payload.SetNumberField("someInt", i);
Payload.SetBoolField("someBool", true);

FAccelByteModelsTelemetryBody TelemetryBody;
TelemetryBody.EventName = "ExampleEvent";
TelemetryBody.EventNamespace = "GameNamespace";
TelemetryBody.Payload = MakeShared < FJsonObject > (Payload);

bool bTelemetryEventSent = false;

FRegistry::GameTelemetry.Send(
TelemetryBody,
FVoidHandler::CreateLambda([ & ]() {
UE_LOG(LogTemp, Log, TEXT(" Success"));
}),

FErrorHandler::CreateLambda([](int32 ErrorCode,
const FString & ErrorMessage) {
UE_LOG(LogTemp, Fatal, TEXT(" Error. Code: %d, Reason: %s"), ErrorCode, * ErrorMessage);
})
);

Send events using APIs

Use the Protected Save Events: POST - /game-telemetry/v1/protected/events endpoint. Event message size is limited to 1 MB.

Fill in the Request Body.

  • Input the EventNamespace with the game namespace.
  • Input the EventName with the name of the event. For example "player_killed" or "mission_accomplished".
  • Input the Payload with an arbitrary JSON of the event.

Here are some examples of the payload for different use cases.

If you want to track player logins and logouts, you can use the following reference for your request body.

Login:

{
"EventName" : "player_logged_in",
"EventNamespace" : "abshooter", // Game Namespace
"Payload": {
"GameSessionId" : "generated after the game client is executed",
"UserId" : "could be obtained from player's credential information",
"LoginSessionId" : "generated after the player has been logged in",
"LoginType" : "[USERNAME, LAUNCHER, STEAM, etc..]",
"GameVersion" : "our game release version",
"SDKVersion" : "version of AccelByte SDK in the game's project",
"DSTargetVersion" : "version of dedicated server image",
"Platform" : "[WINDOWS, LINUX, etc..]"
}
}

Logout:

{
"EventName" : "player_logged_out",
"EventNamespace" : "abshooter", // Game Namespace
"Payload": {
"GameSessionId" : "generated after the game client is executed",
"UserId" : "could be obtained from player's credential information",
"LoginSessionId" : "generated after the player has been logged in",
"LoginSessionDuration" : "time unit is in minutes"
}
}

If you want to track when matchmaking starts and ends, you can use the following reference for your request body.

Start:

{
"EventName" : "player_match_start",
"EventNamespace" : "abshooter", // Game Namespace
"Payload": {
"GameSessionId" : "generated after the game client is executed",
"UserId" : "could be obtained from player's credential information",
"MatchId" : "obtained from lobby matchmaking service",
"ConnectToLocal" : [true, false], // Is using local DS
"GameMode" : "chosen game mode for current match"
}
}

End:

{

"EventName" : "player_match_end",
"EventNamespace" : "abshooter", // Game Namespace
"Payload": {
"GameSessionId" : "generated after the game client is executed",
"UserId" : "could be obtained from player's credential information",
"MatchId" : "obtained from lobby matchmaking service",
"IsWinner" : [true, false], // Is the player win
"EndReason" : "cause of end match"
}
}

If you want to detect a player's active status on the server, you can use the following reference for your request body.

{
"EventName" : "player_heartbeat",
"EventNamespace" : "abshooter", // Game Namespace
"Payload": {
"GameSessionId" : "generated after the game client is executed",
"UserId" : "could be obtained from player's credential information",
"IsServer" : [true, false] // Is it in the server
}
}

The Event Timestamp will be generated automatically by the Game Telemetry in ISO 8601 format (e.g., 2021-01-05T05:04:08.775Z).

The Event ID will be generated automatically by the Game Telemetry. Upon a successful request, the event will be sent to the designated streaming pipeline for tracking.

Track events using the client SDKs

With our Game Telemetry service, you can track and log players' actions within the game by sending an event to be tracked to the game's streaming pipeline. To track those actions a player session is required, so you must enable your players to create an account in your game before you can use this feature.

Preparation

By default, telemetry events will be sent to a game's streaming pipeline as a batch after a set amount of time. This amount of time should be configured before telemetry events can be sent. Any events that should be sent immediately should also be added to the immediate event list. Here is an example of how to configure your telemetry events.

TArray<FString> EventName;
EventName.Add(FString("ITEM_SOURCE"));
EventName.Add(FString("SPECIALISED_ABILITY"));
FTimespan Interval = FTimespan::FromSeconds(30.0f);

// For Game Client
FRegistry::GameTelemetry.SetImmediateEventList(EventNames);
FRegistry::GameTelemetry.SetBatchFrequency(Interval);

// For Game Server
FRegistry::ServerGameTelemetry.SetImmediateEventList(EventNames);
FRegistry::GameTelemetry.SetBatchFrequency(Interval);

Send event

The following function signature can also be used to send an event. The returned data will be displayed in your data warehouse, where you'll be able to customize its visualization.

TSharedPtr<FJsonObject> Payload = MakeShareable(new FJsonObject);
Payload->SetStringField(FString("SomeString"), FString("SomeValue"));
Payload->SetNumberField(FString("SomeNumber"), 50);
Payload->SetBoolField(FString("SomeBool"), true);

FAccelByteModelsTelemetryBody TelemetryBody;
TelemetryBody.EventName = FString("SomeEventName");
TelemetryBody.EventNamespace = FString("SomeEventNamespace");
TelemetryBody.Payload = Payload;

FRegistry::GameTelemetry.Send(TelemetryBody, FVoidHandler::CreateLambda([]()
{
// Do something if Send Event has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if Send Event has an error
UE_LOG(LogTemp, Log, TEXT("Error Send, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));